madrun 9.0.8 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog CHANGED
@@ -1,3 +1,15 @@
1
+ 2023.05.01, v9.2.0
2
+
3
+ feature:
4
+ - a702e01 madrun: use built-in madrun
5
+ - 77560c6 package: eslint-plugin-putout v17.5.1
6
+ - 928768c package: @putout/plugin-madrun v15.0.0
7
+
8
+ 2023.03.07, v9.1.0
9
+
10
+ feature:
11
+ - 0b32623 madrun: add ability to select script to run
12
+
1
13
  2023.03.06, v9.0.8
2
14
 
3
15
  feature:
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 🏎 Madrun [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
2
2
 
3
+ ![image](https://user-images.githubusercontent.com/1573141/223524904-4175548f-1e30-4745-bf2e-c2f4ea39fef5.png)
4
+
3
5
  [NPMURL]: https://npmjs.org/package/madrun "npm"
4
6
  [NPMIMGURL]: https://img.shields.io/npm/v/madrun.svg?style=flat
5
7
  [BuildStatusURL]: https://github.com/coderaiser/madrun/actions?query=workflow%3A%22Node+CI%22 "Build Status"
@@ -147,7 +149,10 @@ export default {
147
149
  'lint:env': () => ['putout .', {
148
150
  CI: 1,
149
151
  }],
150
- 'env:lint': () => [env, 'putout .'],
152
+ 'env:lint': () => [
153
+ env,
154
+ 'putout .',
155
+ ],
151
156
  'lint:no-env': async () => await cutEnv('lint:env'),
152
157
  };
153
158
  ```
package/bin/init.mjs CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  writeFile,
5
5
  access,
6
6
  } from 'fs/promises';
7
-
8
7
  import tryToCatch from 'try-to-catch';
9
8
  import montag from 'montag';
10
9
 
@@ -21,7 +20,7 @@ export const createMadrun = async (cwd, info) => {
21
20
  if (!name) {
22
21
  const {scripts = {}} = info;
23
22
 
24
- const madrun = montag `
23
+ const madrun = montag`
25
24
  'use strict';
26
25
 
27
26
  const {
@@ -82,4 +81,3 @@ async function findMadrun(cwd) {
82
81
 
83
82
  return '';
84
83
  }
85
-
@@ -10,4 +10,3 @@ const read = fs.createReadStream(filename);
10
10
  const write = process.stdout;
11
11
 
12
12
  read.pipe(write);
13
-
package/bin/madrun.mjs CHANGED
@@ -1,24 +1,25 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  import {createRequire} from 'module';
4
3
  import {
5
4
  dirname,
6
5
  basename,
7
6
  } from 'path';
8
-
9
7
  import findUp from 'find-up';
10
8
  import tryToCatch from 'try-to-catch';
11
9
  import yargsParser from 'yargs-parser';
12
-
13
10
  import {series} from '../lib/madrun.js';
14
11
  import check from '../lib/check.js';
12
+ import {choose} from '../lib/choose.mjs';
13
+
15
14
  const require = createRequire(import.meta.url);
16
15
 
17
16
  const {exit} = process;
17
+
18
18
  const {
19
19
  MADRUN_PWD,
20
20
  MADRUN_NAME,
21
21
  } = process.env;
22
+
22
23
  const cwd = process.cwd();
23
24
 
24
25
  const args = yargsParser(process.argv.slice(2), {
@@ -48,13 +49,13 @@ const {
48
49
  if (help) {
49
50
  const {help} = require('../lib/help.js');
50
51
  console.log(help());
51
- process.exit();
52
+ exit();
52
53
  }
53
54
 
54
55
  if (version) {
55
56
  const {version} = require('../package.json');
56
57
  console.log(`v${version}`);
57
- process.exit();
58
+ exit();
58
59
  }
59
60
 
60
61
  if (init) {
@@ -77,45 +78,52 @@ if (init) {
77
78
  console.error(error);
78
79
  }
79
80
 
80
- const names = args._;
81
+ let names = args._;
81
82
  const options = getOptions(args['--']);
82
- const [dir, script] = await getScript();
83
+ const [dir, scripts] = await getScript();
83
84
 
84
- const problems = check(script);
85
+ const problems = check(scripts);
85
86
 
86
87
  if (problems) {
87
- const result = await putoutMadrun(dir, {fix});
88
+ const result = await putoutMadrun(dir, {
89
+ fix,
90
+ });
88
91
 
89
92
  if (fix) {
90
- process.exit();
93
+ exit();
91
94
  } else {
92
95
  console.log(result);
93
- process.exit(1);
96
+ exit(1);
94
97
  }
95
98
  }
96
99
 
97
100
  if (init)
98
- process.exit();
101
+ exit();
99
102
 
100
103
  if (problems) {
101
104
  await execute(`echo '${problems}'`);
102
- process.exit(1);
105
+ exit(1);
103
106
  }
104
107
 
105
108
  if (!names.length) {
106
- console.log(Object.keys(script).join('\n'));
107
- exit();
109
+ names = await choose(scripts);
108
110
  }
109
111
 
112
+ if (!names.length)
113
+ exit();
114
+
110
115
  const env = {};
111
- const [e, cmd] = await tryToCatch(series, names, options, env, script);
116
+ const [e, cmd] = await tryToCatch(series, names, options, env, scripts);
112
117
 
113
118
  if (e) {
114
119
  console.error(e.message);
115
- process.exit(1);
120
+ exit(1);
116
121
  }
117
122
 
118
- console.log(getOutput({cmd, cwd}));
123
+ console.log(getOutput({
124
+ cmd,
125
+ cwd,
126
+ }));
119
127
  await execute(cmd);
120
128
 
121
129
  function getOutput({cmd, cwd}) {
@@ -172,17 +180,20 @@ async function getScript() {
172
180
  async function putoutMadrun(dir, {fix}) {
173
181
  const name = `${dir}/.madrun.js`;
174
182
  const {runPutout} = await import('../lib/fix.mjs');
183
+
175
184
  const {
176
185
  readFile,
177
186
  writeFile,
178
187
  } = await import('fs/promises');
179
188
 
180
189
  const data = await readFile(name, 'utf8');
181
- const {places, code} = await runPutout(data);
190
+ const {
191
+ places,
192
+ code,
193
+ } = await runPutout(data);
182
194
 
183
195
  if (fix)
184
196
  await writeFile(name, code);
185
197
 
186
198
  return places;
187
199
  }
188
-
package/lib/check.js CHANGED
@@ -25,4 +25,3 @@ function getNames(scripts) {
25
25
 
26
26
  return result;
27
27
  }
28
-
package/lib/choose.mjs ADDED
@@ -0,0 +1,37 @@
1
+ import enquirer from 'enquirer';
2
+ import actions from 'enquirer/lib/combos.js';
3
+ import tryToCatch from 'try-to-catch';
4
+
5
+ const {MultiSelect} = enquirer;
6
+
7
+ const custom = {
8
+ h: 'left',
9
+ j: 'down',
10
+ k: 'up',
11
+ l: 'right',
12
+ enter: 'i',
13
+ };
14
+
15
+ actions.keys = {
16
+ ...actions.keys,
17
+ ...custom,
18
+ };
19
+
20
+ export const choose = async (scripts) => {
21
+ const prompt = new MultiSelect({
22
+ message: 'Run:',
23
+ onSubmit() {
24
+ this.enable(this.focused);
25
+ },
26
+ choices: Object.keys(scripts),
27
+ });
28
+
29
+ const answer = await run(prompt);
30
+
31
+ return answer || [];
32
+ };
33
+
34
+ async function run(prompt) {
35
+ const [, answer] = await tryToCatch(prompt.run.bind(prompt));
36
+ return answer;
37
+ }
package/lib/fix.mjs CHANGED
@@ -1,18 +1,20 @@
1
1
  import putout, {
2
2
  initReport,
3
3
  } from 'putout';
4
-
5
4
  import dumpFormatter from '@putout/formatter-dump';
6
- import madrun from '@putout/plugin-madrun';
7
5
 
8
6
  const report = initReport();
9
7
 
10
8
  export const runPutout = async (data, options) => {
11
- const {code, places} = putout(data, {
9
+ const {
10
+ code,
11
+ places,
12
+ } = putout(data, {
13
+ printer: 'putout',
12
14
  ...options,
13
- plugins: [{
14
- madrun,
15
- }],
15
+ plugins: [
16
+ 'madrun',
17
+ ],
16
18
  });
17
19
 
18
20
  return {
package/lib/help.js CHANGED
@@ -16,4 +16,3 @@ module.exports.help = () => {
16
16
 
17
17
  return result.join('\n');
18
18
  };
19
-
package/lib/madrun.js CHANGED
@@ -8,7 +8,7 @@ const findUp = require('find-up');
8
8
  const wildcard = require('./wildcard');
9
9
  const check = require('./check');
10
10
  const supported = require('../supported');
11
-
11
+ const maybeArray = (a) => isArray(a) ? a : [a];
12
12
  const isStr = (a) => typeof a === 'string';
13
13
  const {isArray} = Array;
14
14
 
@@ -22,12 +22,11 @@ async function getScripts() {
22
22
  }
23
23
 
24
24
  module.exports.cutEnv = async (names, opts = '', env, scripts) => {
25
- if (isStr(names))
26
- names = [names];
27
-
25
+ names = maybeArray(names);
28
26
  scripts = scripts || await getScripts();
29
27
 
30
28
  const isParallel = false;
29
+
31
30
  const commands = await run(names, opts, scripts, {
32
31
  env,
33
32
  cutEnv: true,
@@ -53,12 +52,11 @@ module.exports.run = async (name, opts = '', env, scripts) => {
53
52
  module.exports.series = series;
54
53
 
55
54
  async function series(names, opts = '', env, scripts) {
56
- if (isStr(names))
57
- names = [names];
58
-
55
+ names = maybeArray(names);
59
56
  scripts = scripts || await getScripts();
60
57
 
61
58
  const isParallel = false;
59
+
62
60
  const commands = await run(names, opts, scripts, {
63
61
  env,
64
62
  isParallel,
@@ -71,12 +69,14 @@ async function series(names, opts = '', env, scripts) {
71
69
 
72
70
  module.exports.parallel = async (names, opts = '', env, scripts) => {
73
71
  scripts = scripts || await getScripts();
74
-
75
- if (isStr(names))
76
- names = [names];
72
+ names = maybeArray(names);
77
73
 
78
74
  const isParallel = true;
79
- const commands = await run(names, opts, scripts, {env, isParallel});
75
+
76
+ const commands = await run(names, opts, scripts, {
77
+ env,
78
+ isParallel,
79
+ });
80
80
 
81
81
  return joinByType(commands, {
82
82
  isParallel,
@@ -140,8 +140,13 @@ const parse = async (name, {scripts, opts, env, isParallel, cutEnv}) => {
140
140
 
141
141
  const fn = jessy(key, scripts);
142
142
 
143
- const {line, lineEnv} = await runScriptFn(fn);
143
+ const {
144
+ line,
145
+ lineEnv,
146
+ } = await runScriptFn(fn);
147
+
144
148
  const cmd = addOpts(line, opts);
149
+
145
150
  const cmdEnv = addEnv(cmd, {
146
151
  ...cutEnv ? {} : lineEnv,
147
152
  ...env,
@@ -195,4 +200,3 @@ async function addPrePost(cmd, key, scripts) {
195
200
 
196
201
  return cmd;
197
202
  }
198
-
package/lib/validate.js CHANGED
@@ -12,4 +12,3 @@ module.exports = (runners) => {
12
12
 
13
13
  return null;
14
14
  };
15
-
package/lib/wildcard.js CHANGED
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = (str) => {
4
- const wildcard = '^' + str/* search from start of line */
4
+ const wildcard = '^' + str
5
5
  .replace('.', '\\.')
6
6
  .replace('*', '.*')
7
- .replace('?', '.?') + '$'; /* search to end of line */
7
+ .replace('?', '.?') + '$';
8
8
 
9
9
  return RegExp(wildcard);
10
10
  };
11
-
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "madrun",
3
- "version": "9.0.8",
3
+ "version": "9.2.0",
4
4
  "description": "CLI tool to run multiple npm-scripts in a madly comfortable way",
5
5
  "main": "lib/madrun.js",
6
6
  "type": "commonjs",
7
- "commitType": "colon",
8
7
  "scripts": {
9
8
  "lint": "madrun lint",
10
9
  "fresh:lint": "madrun fresh:lint",
@@ -56,8 +55,8 @@
56
55
  },
57
56
  "dependencies": {
58
57
  "@putout/formatter-dump": "^4.0.0",
59
- "@putout/plugin-madrun": "^14.0.0",
60
58
  "all-object-keys": "^2.0.0",
59
+ "enquirer": "^2.3.6",
61
60
  "find-up": "^5.0.0",
62
61
  "jessy": "^3.0.0",
63
62
  "mapsome": "^1.0.0",
@@ -74,7 +73,7 @@
74
73
  "escover": "^2.0.1",
75
74
  "eslint": "^8.0.0",
76
75
  "eslint-plugin-n": "^15.2.4",
77
- "eslint-plugin-putout": "^16.0.0",
76
+ "eslint-plugin-putout": "^17.5.1",
78
77
  "mock-import": "^3.0.0",
79
78
  "mock-require": "^3.0.3",
80
79
  "nodemon": "^2.0.0",