Skip to content

Commit

Permalink
add common command
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Aug 12, 2018
1 parent 87bea87 commit 73638fe
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 30 deletions.
2 changes: 1 addition & 1 deletion public/js/terminal.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion resources/assets/ts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'core-js/modules/es6.object.assign';
import 'core-js/modules/es6.regexp.flags';
import './unix_formatting';
import { HttpClient } from './httpclient';
import { Artisan, Composer, MySQL, Tinker, Vim, Help } from './commands';
import { Artisan, Common, Composer, MySQL, Tinker, Vim, Help } from './commands';
import { OutputFormatter } from './output-formatter';
import { Command } from './command';
import { Spinner } from './spinners';
Expand Down Expand Up @@ -36,6 +36,7 @@ export class Terminal {
new MySQL(client, this.outputFormatter, this.options),
new Tinker(client, this.outputFormatter, this.options),
new Vim(client, this.outputFormatter, this.options),
new Common(client, this.outputFormatter, this.options),
];

this.fit();
Expand Down
3 changes: 1 addition & 2 deletions resources/assets/ts/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ export abstract class Command implements Interpreterable, Comfirmable {

async run(command: string): Promise<any> {
const cmd: any = this.parseSentence(command);
console.log(cmd);

return await this.client.jsonrpc(cmd.method, [`--command="${cmd.params.join(' ')}"`]);
return await this.client.jsonrpc(cmd.method, cmd.params);
}

interpreterable(command: string): boolean {
Expand Down
4 changes: 3 additions & 1 deletion resources/assets/ts/commands/artisan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export class Artisan extends Command {
}

async run(command: string): Promise<any> {
return super.run(this.removePHP(command));
const cmd: any = this.parseSentence(this.removePHP(command));

return await this.client.jsonrpc(cmd.method, [`--command="${cmd.params.join(' ')}"`]);
}

comfirmable(command: string): boolean {
Expand Down
7 changes: 7 additions & 0 deletions resources/assets/ts/commands/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Command } from '../command';

export class Common extends Command {
is(command: string): boolean {
return true;
}
}
6 changes: 6 additions & 0 deletions resources/assets/ts/commands/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ export class Composer extends Command {
is(command: string): boolean {
return /^(\.\/)?composer/.test(command);
}

async run(command: string): Promise<any> {
const cmd: any = this.parseSentence(command);

return await this.client.jsonrpc(cmd.method, [`--command="${cmd.params.join(' ')}"`]);
}
}
1 change: 1 addition & 0 deletions resources/assets/ts/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './artisan';
export * from './common';
export * from './composer';
export * from './help';
export * from './mysql';
Expand Down
6 changes: 6 additions & 0 deletions resources/assets/ts/commands/tinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export class Tinker extends Command implements Interpreterable {
return /^(\.\/)?tinker/.test(command);
}

async run(command: string): Promise<any> {
const cmd: any = this.parseSentence(command);

return await this.client.jsonrpc(cmd.method, [`--command="${cmd.params.join(' ')}"`]);
}

interpreterable(command: string): boolean {
return ['artisan tinker', 'tinker'].indexOf(command.trim()) !== -1;
}
Expand Down
18 changes: 9 additions & 9 deletions resources/assets/ts/commands/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,6 @@ export class Vim extends Command {
return /^(\.\/)?vi(m)?/.test(command);
}

private async write(): Promise<void> {
try {
const text = JSON.stringify(this.editor.getText().replace(/\n$/, ''));
await this.client.jsonrpc('vi', [this.file, `--text=${text}`]);
} catch (error) {
this.reject(error);
}
}

async run(command: string): Promise<any> {
return new Promise(async (resolve, reject) => {
this.resolve = resolve;
Expand All @@ -198,4 +189,13 @@ export class Vim extends Command {
}
});
}

private async write(): Promise<void> {
try {
const text = JSON.stringify(this.editor.getText().replace(/\n$/, ''));
await this.client.jsonrpc('vi', [this.file, `--text=${text}`]);
} catch (error) {
this.reject(error);
}
}
}
37 changes: 21 additions & 16 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@ const publicPath = path.resolve(__dirname, '../../../../vendor/terminal');
|
*/

mix
.options({
autoload: {
jquery: ['$', 'window.jQuery', 'jQuery', 'CodeMirror'],
},
processCssUrls: false,
publicPath: './',
})
.browserSync({
files: [`${publicPath}/js/app.js`, `${publicPath}/css/app.css`],
});
mix.options({
autoload: {
jquery: ['$', 'window.jQuery', 'jQuery', 'CodeMirror'],
},
processCssUrls: false,
publicPath: './',
}).browserSync({
files: [`${publicPath}/js/app.js`, `${publicPath}/css/app.css`],
});

mix
.ts('resources/assets/ts/app.ts', 'public/js/terminal.js')
.sass('resources/assets/sass/app.scss', 'public/css/terminal.css');
mix.ts('resources/assets/ts/app.ts', 'public/js/terminal.js').sass(
'resources/assets/sass/app.scss',
'public/css/terminal.css'
);

mix.then(() => {
try {
fse.copyFileSync(path.resolve(__dirname, 'public/css/terminal.css'), path.resolve(publicPath, 'css/terminal.css'));
fse.copyFileSync(
path.resolve(__dirname, 'public/css/terminal.css'),
path.resolve(publicPath, 'css/terminal.css')
);
fse.copyFileSync(path.resolve(__dirname, 'public/js/terminal.js'), path.resolve(publicPath, 'js/terminal.js'));
fse.copyFileSync(path.resolve(__dirname, 'resources/views/index.blade.php'), path.resolve(publicPath, '../../laravel/resources/views/vendor/terminal/index.blade.php'));
fse.copyFileSync(
path.resolve(__dirname, 'resources/views/index.blade.php'),
path.resolve(publicPath, '../../laravel/resources/views/vendor/terminal/index.blade.php')
);
} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit 73638fe

Please sign in to comment.