@digigov/cli-lab 2.0.0 → 2.0.2-0138f8bd
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/.rush/temp/shrinkwrap-deps.json +354 -264
- package/CHANGELOG.json +12 -0
- package/CHANGELOG.md +8 -1
- package/index.mjs +15 -13
- package/lib/changed-packages/index.mjs +39 -18
- package/lib/extra/index.mjs +101 -67
- package/package.json +14 -12
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/cli-lab",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "2.0.1",
|
|
6
|
+
"tag": "@digigov/cli-lab_v2.0.1",
|
|
7
|
+
"date": "Tue, 19 Dec 2023 15:00:14 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Upgrade rush and fs-extra"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "2.0.0",
|
|
6
18
|
"tag": "@digigov/cli-lab_v2.0.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log - @digigov/cli-lab
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 19 Dec 2023 15:00:14 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 2.0.1
|
|
6
|
+
Tue, 19 Dec 2023 15:00:14 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Upgrade rush and fs-extra
|
|
4
11
|
|
|
5
12
|
## 2.0.0
|
|
6
13
|
Fri, 15 Dec 2023 15:23:56 GMT
|
package/index.mjs
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env zx
|
|
2
2
|
import "zx-extra";
|
|
3
3
|
import "./lib/extra/index.mjs";
|
|
4
|
-
|
|
5
|
-
const scriptLocation = path.join(__dirname, 'scripts', script+'.mjs')
|
|
6
|
-
await spawn(`zx`, [scriptLocation], {stdio: 'inherit'})
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
7
5
|
|
|
6
|
+
async function runScript(script) {
|
|
7
|
+
const scriptLocation = path.join(__dirname, "scripts", script + ".mjs");
|
|
8
|
+
spawnSync(`zx`, [scriptLocation], { stdio: "inherit" });
|
|
8
9
|
}
|
|
9
|
-
if(argv.script) {
|
|
10
|
-
await runScript(argv.script)
|
|
11
|
-
}else {
|
|
12
|
-
const scripts = (await find(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
await
|
|
10
|
+
if (argv.script) {
|
|
11
|
+
await runScript(argv.script);
|
|
12
|
+
} else {
|
|
13
|
+
const scripts = (await find(path.join(__dirname, "scripts", "*.mjs"))).map(
|
|
14
|
+
(filePath) =>
|
|
15
|
+
filePath
|
|
16
|
+
.replace(path.join(__dirname, "scripts/"), "")
|
|
17
|
+
.replace(".mjs", ""),
|
|
18
|
+
);
|
|
19
|
+
const script = await select("Select script", scripts);
|
|
20
|
+
await runScript(script);
|
|
19
21
|
}
|
|
@@ -1,24 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env zx
|
|
2
2
|
import "zx-extra";
|
|
3
3
|
import "../extra/index.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
|
|
6
|
+
export default async function getChangedPackages(targetBranch) {
|
|
7
|
+
const rushJSON = await readJSON(await findUp("rush.json"));
|
|
8
|
+
return await diffAllPackages(targetBranch, rushJSON.projects);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
function
|
|
11
|
-
let targetBranch =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
async function diffAllPackages(customTargetBranch, projects) {
|
|
12
|
+
let targetBranch =
|
|
13
|
+
customTargetBranch || process.env.CI_DEFAULT_BRANCH || "origin/main";
|
|
14
|
+
targetBranch = targetBranch.replace(/^origin\//, "");
|
|
15
|
+
|
|
16
|
+
const allPackages = await Promise.all(
|
|
17
|
+
projects.map((project) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const { projectFolder } = project;
|
|
20
|
+
const diffProcess = spawn("git", [
|
|
21
|
+
"diff",
|
|
22
|
+
"--merge-base",
|
|
23
|
+
targetBranch,
|
|
24
|
+
"--",
|
|
25
|
+
projectFolder,
|
|
26
|
+
]);
|
|
27
|
+
let output = "";
|
|
28
|
+
diffProcess.stdout.on("data", (data) => {
|
|
29
|
+
output += data.toString();
|
|
30
|
+
});
|
|
31
|
+
diffProcess.stderr.on("data", (data) => {
|
|
32
|
+
reject(data.toString());
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
diffProcess.on("close", (code) => {
|
|
36
|
+
if (code !== 0) return reject(`git diff exited with code ${code}`);
|
|
37
|
+
if (output.trim()) return resolve(projectFolder);
|
|
38
|
+
else return resolve(null);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return allPackages.filter(Boolean);
|
|
24
45
|
}
|
package/lib/extra/index.mjs
CHANGED
|
@@ -1,80 +1,115 @@
|
|
|
1
|
-
import { $ } from
|
|
2
|
-
import inquirer from
|
|
3
|
-
import glob from
|
|
4
|
-
import path from
|
|
5
|
-
import { spawnSync } from
|
|
6
|
-
import fs from
|
|
1
|
+
import { $ } from "zx";
|
|
2
|
+
import * as inquirer from "@inquirer/prompts";
|
|
3
|
+
import glob from "globby";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { spawnSync } from "child_process";
|
|
6
|
+
import fs from "fs-extra";
|
|
7
|
+
|
|
7
8
|
const errorOffset = 1000;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create a CLI command
|
|
12
|
+
*
|
|
13
|
+
* This creates a proxy object that allows you to call CLI commands
|
|
14
|
+
* as if they were functions. Under the hood, it uses `spawnSync` to
|
|
15
|
+
* run the command and return the result
|
|
16
|
+
*
|
|
17
|
+
* @param {string} commandName
|
|
18
|
+
* @returns {Proxy} a proxy object for the CLI command
|
|
19
|
+
*/
|
|
8
20
|
function createCli(commandName) {
|
|
9
|
-
return new Proxy(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const result = spawnSync(commandName, [command, ...args], { shell: true, stdio: options?.json || options?.stdout ? 'pipe' : ['inherit', 'inherit', 'pipe'], env: options?.env || process.env });
|
|
18
|
-
if (result.status !== 0 && result.stderr) {
|
|
19
|
-
const errMsg = result.stderr.toString();
|
|
20
|
-
if (errMsg.includes('Error: ')) {
|
|
21
|
-
const idx = errMsg.substring(errMsg.indexOf('Error: '));
|
|
22
|
-
throw new Error(errMsg.substring(idx, idx + errorOffset))
|
|
21
|
+
return new Proxy(
|
|
22
|
+
{},
|
|
23
|
+
{
|
|
24
|
+
get: (_, command) => {
|
|
25
|
+
return async function (args, options) {
|
|
26
|
+
if (args) {
|
|
27
|
+
args = args.split(" ");
|
|
23
28
|
} else {
|
|
24
|
-
|
|
29
|
+
args = [];
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const result = spawnSync(commandName, [command, ...args], {
|
|
32
|
+
shell: true,
|
|
33
|
+
stdio:
|
|
34
|
+
options?.json || options?.stdout
|
|
35
|
+
? "pipe"
|
|
36
|
+
: ["inherit", "inherit", "pipe"],
|
|
37
|
+
env: options?.env || process.env,
|
|
38
|
+
});
|
|
39
|
+
if (result.status !== 0 && result.stderr) {
|
|
40
|
+
const errMsg = result.stderr.toString();
|
|
41
|
+
if (errMsg.includes("Error: ")) {
|
|
42
|
+
const idx = errMsg.substring(errMsg.indexOf("Error: "));
|
|
43
|
+
throw new Error(errMsg.substring(idx, idx + errorOffset));
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error(result.stderr.toString());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (options?.json) {
|
|
49
|
+
return JSON.parse(result.stdout);
|
|
50
|
+
}
|
|
51
|
+
if (options?.stdout) {
|
|
52
|
+
return result.stdout.toString();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
);
|
|
37
58
|
}
|
|
38
|
-
console.clear();
|
|
39
59
|
global.find = async (patterns, options) => {
|
|
40
60
|
return glob.sync(patterns, options);
|
|
41
61
|
};
|
|
42
62
|
global.mkdir = async (dir) => {
|
|
43
|
-
fs.mkdirSync(dir)
|
|
44
|
-
}
|
|
63
|
+
fs.mkdirSync(dir);
|
|
64
|
+
};
|
|
45
65
|
global.rm = async (fileOrDir) => {
|
|
46
|
-
console.log(
|
|
47
|
-
return fs.
|
|
48
|
-
recursive: true
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
global.confirm =
|
|
52
|
-
global.question =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
console.log("removing " + fileOrDir);
|
|
67
|
+
return fs.rm(fileOrDir, {
|
|
68
|
+
recursive: true,
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
global.confirm = (question) => inquirer.confirm({ message: question });
|
|
72
|
+
global.question = (question, value) =>
|
|
73
|
+
inquirer.input({
|
|
74
|
+
message: question,
|
|
75
|
+
default: value,
|
|
76
|
+
});
|
|
77
|
+
global.password = (question) => inquirer.password({ message: question });
|
|
56
78
|
|
|
57
|
-
global.select =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
global.select = (question, choices, values) =>
|
|
80
|
+
inquirer.select({
|
|
81
|
+
message: question,
|
|
82
|
+
choices,
|
|
83
|
+
default: values,
|
|
84
|
+
});
|
|
85
|
+
global.checkbox = (question, choices) =>
|
|
86
|
+
inquirer.checkbox({
|
|
87
|
+
message: question,
|
|
88
|
+
choices,
|
|
89
|
+
});
|
|
66
90
|
|
|
67
|
-
global.cli = new Proxy(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
91
|
+
global.cli = new Proxy(
|
|
92
|
+
{},
|
|
93
|
+
{
|
|
94
|
+
get: (_, commandName) => {
|
|
95
|
+
return createCli(commandName);
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
);
|
|
72
99
|
global.pwd = async () => (await $`pwd`).stdout;
|
|
73
100
|
global.path = path;
|
|
74
|
-
global.cd = (p) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
global.
|
|
101
|
+
global.cd = (p) => {
|
|
102
|
+
process.chdir(p);
|
|
103
|
+
};
|
|
104
|
+
global.readJSON = async (file) => {
|
|
105
|
+
return fs.readJSONSync(file);
|
|
106
|
+
};
|
|
107
|
+
global.readFile = async (file) => {
|
|
108
|
+
return fs.readFileSync(file).toString();
|
|
109
|
+
};
|
|
110
|
+
global.writeFile = async (file, content) => {
|
|
111
|
+
return fs.outputFileSync(file, content);
|
|
112
|
+
};
|
|
78
113
|
global.findUp = function findFileInParentDirectories(fileName, rootDir) {
|
|
79
114
|
let currentDir = rootDir || process.cwd();
|
|
80
115
|
while (currentDir) {
|
|
@@ -101,10 +136,9 @@ global.requireEnv = async (key, required, options) => {
|
|
|
101
136
|
return val;
|
|
102
137
|
};
|
|
103
138
|
|
|
104
|
-
global.spawn = spawnSync
|
|
139
|
+
global.spawn = spawnSync;
|
|
105
140
|
|
|
106
|
-
process.on(
|
|
141
|
+
process.on("SIGINT", function () {
|
|
107
142
|
console.log("Caught interrupt signal");
|
|
108
143
|
process.exit();
|
|
109
|
-
|
|
110
|
-
});
|
|
144
|
+
});
|
package/package.json
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/cli-lab",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-0138f8bd",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"directories": {
|
|
8
8
|
"lib": "lib"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"publint": "publint",
|
|
12
|
-
"lab": "zx index.mjs"
|
|
13
|
-
},
|
|
14
10
|
"author": "",
|
|
15
11
|
"license": "BSD-2-Clause",
|
|
16
12
|
"dependencies": {
|
|
17
|
-
"@microsoft/rush-lib": "5.
|
|
18
|
-
"zx": "2.
|
|
19
|
-
"zx-extra": "
|
|
20
|
-
"inquirer": "
|
|
21
|
-
"
|
|
22
|
-
"fs-extra": "
|
|
13
|
+
"@microsoft/rush-lib": "5.151.0",
|
|
14
|
+
"zx": "7.2.3",
|
|
15
|
+
"zx-extra": "3.0.23",
|
|
16
|
+
"@inquirer/prompts": "7.0.1",
|
|
17
|
+
"globby": "11.0.0",
|
|
18
|
+
"fs-extra": "11.2.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
23
21
|
"publint": "0.1.8"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"publint": "publint",
|
|
25
|
+
"lab": "zx index.mjs"
|
|
24
26
|
}
|
|
25
|
-
}
|
|
27
|
+
}
|