Skip to content

Commit d14d90e

Browse files
authored
feat: Merge run and command command (#196)
1 parent 1df7b6f commit d14d90e

File tree

14 files changed

+158
-115
lines changed

14 files changed

+158
-115
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
3434
* Add command to generate recipe (#192)
3535
* Add option to init from `Eldev`-file (#193)
3636
* Add command `commnad` for custom commands (#195)
37+
* Merge the two commands `run` and `command` (#196)
3738

3839
## 0.8.x
3940
> Released Mar 08, 2023

cmds/core/run.js

Lines changed: 16 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,91 +19,22 @@
1919

2020
"use strict";
2121

22-
const fs = require('fs');
23-
const child_process = require("child_process");
24-
25-
exports.command = ['run [names..]', 'run-script [names..]'];
26-
exports.desc = 'Run script nameds [names..]';
27-
exports.builder = yargs => yargs
28-
.positional(
29-
'[names..]', {
30-
description: 'specify scripts to run',
31-
type: 'array',
32-
});
33-
34-
exports.handler = async (argv) => {
35-
await UTIL.e_call(argv, 'core/run', argv.names);
36-
37-
if (!fs.existsSync(EASK_HOMEDIR)) {
38-
return;
39-
}
40-
41-
let run = EASK_HOMEDIR + 'run';
42-
43-
if (!fs.existsSync(run)) {
44-
return;
45-
}
46-
47-
// this contain the full command!
48-
let instruction = fs.readFileSync(run, 'utf8');
49-
let commands = instruction.split('\n').filter(element => element);
50-
51-
let count = 0;
52-
startCommand(commands, count);
53-
};
54-
55-
/**
56-
* Recursive to execute commands in order.
57-
*
58-
* @param { array } commands - An array of commands to execute.
59-
* @param { integer } count - The current executing command's index.
60-
*/
61-
function startCommand(commands, count) {
62-
if (commands.length <= count)
63-
return;
64-
65-
let command = commands[count];
66-
67-
console.log('[RUN]: ' + command);
68-
69-
let proc = spawn(command, { stdio: 'inherit', shell: true });
70-
71-
proc.on('close', function (code) {
72-
if (code == 0) {
73-
startCommand(commands, ++count); // start next command!
74-
return;
75-
}
76-
process.exit(code);
77-
});
78-
}
79-
80-
/**
81-
* Spawn process to avoid `MODULE_NOT_FOUND` not found error,
82-
* see https://github.com/vercel/pkg/issues/1356.
83-
*
84-
* @param { String } command - Command string.
85-
* @param { JSON } options - Process options.
86-
* @return Process object.
87-
*/
88-
function spawn(command, options) {
89-
if (IS_PKG && command.includes('eask ')) {
90-
let cmds = command.split(' ');
91-
cmds = replaceEaskExec(cmds);
92-
return child_process.spawn(process.execPath, cmds, options);
22+
exports.command = ['run <type>'];
23+
exports.desc = 'Run custom tasks';
24+
exports.builder = function (yargs) {
25+
yargs.usage(`${exports.desc}
26+
27+
Usage: eask run <type> [options..]`)
28+
.commandDir('../run/')
29+
.demandCommand();
30+
31+
/* XXX: Configure only in the menu. */
32+
if (UTIL.cmd_count() == 1) {
33+
yargs.positional(
34+
'<type>', {
35+
description: 'type of the execution',
36+
});
9337
}
94-
return child_process.spawn(command, options);
9538
}
9639

97-
/**
98-
* Replace all possible eask/cli executable to snapshot executable.
99-
* @param { Array } cmds - Command array.
100-
* @return Return updated command array.
101-
*/
102-
function replaceEaskExec(cmds) {
103-
for (let index = 0; index < cmds.length; ++index) {
104-
if (cmds[index] == "eask") {
105-
cmds[index] = process.argv[1]; // XXX: This is `/snapshot/cli/eask`
106-
}
107-
}
108-
return cmds;
109-
}
40+
exports.handler = async (argv) => { };
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ exports.builder = yargs => yargs
2929
});
3030

3131
exports.handler = async (argv) => {
32-
await UTIL.e_call(argv, 'core/command'
32+
await UTIL.e_call(argv, 'run/command'
3333
, argv.names);
3434
};

cmds/run/script.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* Copyright (C) 2022-2023 Jen-Chieh Shen
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3, or (at your option)
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with GNU Emacs; see the file COPYING. If not, write to the
16+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301, USA.
18+
*/
19+
20+
"use strict";
21+
22+
const fs = require('fs');
23+
const child_process = require("child_process");
24+
25+
exports.command = ['script [names..]'];
26+
exports.desc = 'Run script nameds [names..]';
27+
exports.builder = yargs => yargs
28+
.positional(
29+
'[names..]', {
30+
description: 'specify scripts to run',
31+
type: 'array',
32+
});
33+
34+
exports.handler = async (argv) => {
35+
await UTIL.e_call(argv, 'run/script', argv.names);
36+
37+
if (!fs.existsSync(EASK_HOMEDIR)) {
38+
return;
39+
}
40+
41+
let run = EASK_HOMEDIR + 'run';
42+
43+
if (!fs.existsSync(run)) {
44+
return;
45+
}
46+
47+
// this contain the full command!
48+
let instruction = fs.readFileSync(run, 'utf8');
49+
let commands = instruction.split('\n').filter(element => element);
50+
51+
let count = 0;
52+
startCommand(commands, count);
53+
};
54+
55+
/**
56+
* Recursive to execute commands in order.
57+
*
58+
* @param { array } commands - An array of commands to execute.
59+
* @param { integer } count - The current executing command's index.
60+
*/
61+
function startCommand(commands, count) {
62+
if (commands.length <= count)
63+
return;
64+
65+
let command = commands[count];
66+
67+
console.log('[RUN]: ' + command);
68+
69+
let proc = spawn(command, { stdio: 'inherit', shell: true });
70+
71+
proc.on('close', function (code) {
72+
if (code == 0) {
73+
startCommand(commands, ++count); // start next command!
74+
return;
75+
}
76+
process.exit(code);
77+
});
78+
}
79+
80+
/**
81+
* Spawn process to avoid `MODULE_NOT_FOUND` not found error,
82+
* see https://github.com/vercel/pkg/issues/1356.
83+
*
84+
* @param { String } command - Command string.
85+
* @param { JSON } options - Process options.
86+
* @return Process object.
87+
*/
88+
function spawn(command, options) {
89+
if (IS_PKG && command.includes('eask ')) {
90+
let cmds = command.split(' ');
91+
cmds = replaceEaskExec(cmds);
92+
return child_process.spawn(process.execPath, cmds, options);
93+
}
94+
return child_process.spawn(command, options);
95+
}
96+
97+
/**
98+
* Replace all possible eask/cli executable to snapshot executable.
99+
* @param { Array } cmds - Command array.
100+
* @return Return updated command array.
101+
*/
102+
function replaceEaskExec(cmds) {
103+
for (let index = 0; index < cmds.length; ++index) {
104+
if (cmds[index] == "eask") {
105+
cmds[index] = process.argv[1]; // XXX: This is `/snapshot/cli/eask`
106+
}
107+
}
108+
return cmds;
109+
}

docs/content/en/Getting-Started/Basic-Usage/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Usage: eask <command> [options..]
3434
Commands:
3535
archives List out all package archives [aliases: sources]
3636
clean <type> Delete various files produced during building
37-
command [names..] Run elisp commands named [names..] [aliases: cmd]
3837
compile [names..] Byte compile all Emacs Lisp files in the package
3938
create <type> Create a new elisp project
4039
docker <version> [args..] Launch specified Emacs version in a Docker container
@@ -60,7 +59,7 @@ Commands:
6059
recipe Suggest a recipe format
6160
refresh Download package archives
6261
reinstall [names..] Reinstall packages
63-
run [names..] Run script nameds [names..] [aliases: run-script]
62+
run <type> Run custom tasks
6463
search [queries..] Search packages
6564
status Display the state of the workspace
6665
test <type> Run test
@@ -146,6 +145,7 @@ Here is a list of known nested subcommands:
146145
- eask generate workflow
147146
- eask link
148147
- eask lint
148+
- eask run
149149
- eask test
150150
151151
## 📌 Knowing your `elpa` directory

docs/content/en/Getting-Started/Commands-and-options.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,22 +316,20 @@ Evaluate `FORM` as a lisp form.
316316
$ eask [GLOBAL-OPTIONS] eval [FORM]
317317
```
318318

319-
## 🔍 eask run
319+
## 🔍 eask run script
320320

321321
Run the script.
322322

323323
```sh
324-
$ eask [GLOBAL-OPTIONS] run [NAMES..]
324+
$ eask [GLOBAL-OPTIONS] run script [NAMES..]
325325
```
326326

327-
Alias: `run-script`
328-
329-
## 🔍 eask command
327+
## 🔍 eask run command
330328

331329
Run the command.
332330

333331
```sh
334-
$ eask [GLOBAL-OPTIONS] command [NAMES..]
332+
$ eask [GLOBAL-OPTIONS] run command [NAMES..]
335333
```
336334

337335
Alias: `cmd`

docs/content/zh-TW/Getting-Started/Basic-Usage/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Usage: eask <command> [options..]
3131
Commands:
3232
archives List out all package archives [aliases: sources]
3333
clean <type> Delete various files produced during building
34-
command [names..] Run elisp commands named [names..] [aliases: cmd]
3534
compile [names..] Byte compile all Emacs Lisp files in the package
3635
create <type> Create a new elisp project
3736
docker <version> [args..] Launch specified Emacs version in a Docker container
@@ -57,7 +56,7 @@ Commands:
5756
recipe Suggest a recipe format
5857
refresh Download package archives
5958
reinstall [names..] Reinstall packages
60-
run [names..] Run script nameds [names..] [aliases: run-script]
59+
run <type> Run custom tasks
6160
search [queries..] Search packages
6261
status Display the state of the workspace
6362
test <type> Run test
@@ -141,6 +140,7 @@ Positionals:
141140
- eask generate workflow
142141
- eask link
143142
- eask lint
143+
- eask run
144144
- eask test
145145
146146
## 📌 了解你的 `elpa` 目錄

docs/content/zh-TW/Getting-Started/Commands-and-options.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,20 @@ $ eask [GLOBAL-OPTIONS] emacs [ARGUMENTS ...]
312312
$ eask [GLOBAL-OPTIONS] eval [FORM]
313313
```
314314

315-
## 🔍 eask run
315+
## 🔍 eask run script
316316

317317
運行腳本。
318318

319319
```sh
320-
$ eask [GLOBAL-OPTIONS] run [NAMES..]
320+
$ eask [GLOBAL-OPTIONS] run script [NAMES..]
321321
```
322322

323-
別名: `run-script`
324-
325-
## 🔍 eask command
323+
## 🔍 eask run command
326324

327325
運行指令。
328326

329327
```sh
330-
$ eask [GLOBAL-OPTIONS] command [NAMES..]
328+
$ eask [GLOBAL-OPTIONS] run command [NAMES..]
331329
```
332330

333331
別名: `cmd`
File renamed without changes.

0 commit comments

Comments
 (0)