@cocreate/cli 1.49.0 → 1.50.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.md +22 -0
- package/CoCreate.config.js +498 -413
- package/docs/index.html +250 -250
- package/package.json +5 -5
- package/prettier.config.js +2 -0
- package/src/addMeta.js +74 -67
- package/src/coc.js +129 -114
- package/src/commands/acme.js +19 -22
- package/src/commands/bump.js +149 -87
- package/src/commands/clone.js +26 -22
- package/src/commands/fs/automated.js +1 -1
- package/src/commands/fs/config.js +1 -1
- package/src/commands/fs/gitignore.js +13 -22
- package/src/commands/fs/manual.js +17 -27
- package/src/commands/fs/prettier.config.js +1 -1
- package/src/commands/fs/remove.js +7 -12
- package/src/commands/fs/replace.js +23 -31
- package/src/commands/fs/webpack.js +143 -149
- package/src/commands/install.js +18 -22
- package/src/commands/link.js +73 -60
- package/src/commands/nginx.js +19 -22
- package/src/commands/symlink.js +132 -115
- package/src/execute.js +63 -50
- package/src/index.js +3 -0
- package/src/spinner.js +85 -0
package/src/addMeta.js
CHANGED
|
@@ -1,75 +1,82 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const util = require(
|
|
4
|
-
const exec = util.promisify(require(
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const util = require("node:util");
|
|
4
|
+
const exec = util.promisify(require("node:child_process").exec);
|
|
5
5
|
|
|
6
6
|
module.exports = async function addMeta(repos, failed, directory) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
let packageManager;
|
|
8
|
+
for (let i = 0; i < repos.length; i++) {
|
|
9
|
+
repos[i].name = path.basename(repos[i].path);
|
|
10
|
+
repos[i].plainName = repos[i].name.substring(9);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
if (directory) {
|
|
13
|
+
repos[i].absolutePath = path.resolve(directory, repos[i].path);
|
|
14
|
+
const parsedPath = path.parse(repos[i].absolutePath);
|
|
15
|
+
repos[i].directory = parsedPath.dir;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
let packagejson = path.resolve(repos[i].absolutePath, "package.json");
|
|
19
|
+
if (!fs.existsSync(packagejson)) {
|
|
20
|
+
console.error("package json not found for", repos[i].name);
|
|
21
|
+
failed.push({
|
|
22
|
+
name: repos[i].name,
|
|
23
|
+
error: "package json not found"
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
let packageObj;
|
|
27
|
+
try {
|
|
28
|
+
packageObj = require(packagejson);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error("packageObj", err.message);
|
|
31
|
+
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
packageObj = require(packagejson);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
console.error('packageObj', err.message)
|
|
33
|
-
}
|
|
33
|
+
repos[i].packageName = packageObj.name;
|
|
34
34
|
|
|
35
|
+
repos[i].deps = Object.keys(
|
|
36
|
+
packageObj["dependencies"] || {}
|
|
37
|
+
).filter((packageName) => packageName.startsWith("@cocreate/"));
|
|
38
|
+
repos[i].devDeps = Object.keys(
|
|
39
|
+
packageObj["devDependencies"] || {}
|
|
40
|
+
).filter((packageName) => packageName.startsWith("@cocreate/"));
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
if (!repos[i].packageManager) {
|
|
43
|
+
if (packageManager) repos[i].packageManager = packageManager;
|
|
44
|
+
else {
|
|
45
|
+
repos[i].packageManager = "npm";
|
|
46
|
+
let lockFile = path.resolve(
|
|
47
|
+
repos[i].absolutePath,
|
|
48
|
+
"package-lock.json"
|
|
49
|
+
);
|
|
50
|
+
if (!fs.existsSync(lockFile)) {
|
|
51
|
+
lockFile = path.resolve(
|
|
52
|
+
repos[i].absolutePath,
|
|
53
|
+
"pnpm-lock.yaml"
|
|
54
|
+
);
|
|
55
|
+
if (fs.existsSync(lockFile))
|
|
56
|
+
repos[i].packageManager = "pnpm";
|
|
57
|
+
else {
|
|
58
|
+
lockFile = path.resolve(
|
|
59
|
+
repos[i].absolutePath,
|
|
60
|
+
"yarn.lock"
|
|
61
|
+
);
|
|
62
|
+
if (fs.existsSync(lockFile))
|
|
63
|
+
repos[i].packageManager = "yarn";
|
|
64
|
+
else {
|
|
65
|
+
try {
|
|
66
|
+
const { error } = await exec(
|
|
67
|
+
"yarn --version"
|
|
68
|
+
);
|
|
69
|
+
if (!error)
|
|
70
|
+
repos[i].packageManager = "yarn";
|
|
71
|
+
} catch (e) {}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
packageManager = repos[i].packageManager;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
37
80
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
repos[i].devDeps = Object.keys(packageObj['devDependencies'] || {})
|
|
41
|
-
.filter(packageName => packageName.startsWith('@cocreate/'));
|
|
42
|
-
|
|
43
|
-
if (!repos[i].packageManager) {
|
|
44
|
-
if (packageManager)
|
|
45
|
-
repos[i].packageManager = packageManager
|
|
46
|
-
else {
|
|
47
|
-
repos[i].packageManager = 'npm'
|
|
48
|
-
let lockFile = path.resolve(repos[i].absolutePath, 'package-lock.json');
|
|
49
|
-
if (!fs.existsSync(lockFile)) {
|
|
50
|
-
lockFile = path.resolve(repos[i].absolutePath, 'pnpm-lock.yaml');
|
|
51
|
-
if (fs.existsSync(lockFile))
|
|
52
|
-
repos[i].packageManager = 'pnpm'
|
|
53
|
-
else {
|
|
54
|
-
lockFile = path.resolve(repos[i].absolutePath, 'yarn.lock');
|
|
55
|
-
if (fs.existsSync(lockFile))
|
|
56
|
-
repos[i].packageManager = 'yarn'
|
|
57
|
-
else {
|
|
58
|
-
try {
|
|
59
|
-
const { error } = await exec('yarn --version');
|
|
60
|
-
if (!error)
|
|
61
|
-
repos[i].packageManager = 'yarn'
|
|
62
|
-
} catch(e) {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
packageManager = repos[i].packageManager
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return repos
|
|
75
|
-
}
|
|
81
|
+
return repos;
|
|
82
|
+
};
|
package/src/coc.js
CHANGED
|
@@ -1,115 +1,130 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const addMeta = require(
|
|
7
|
-
const { color } = require(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const readline = require("readline");
|
|
5
|
+
const execute = require("./execute");
|
|
6
|
+
const addMeta = require("./addMeta");
|
|
7
|
+
const { color } = require("./fonts");
|
|
8
|
+
|
|
9
|
+
let config = {};
|
|
10
|
+
|
|
11
|
+
const argv = process.argv.slice(2);
|
|
12
|
+
const options = ["-self"];
|
|
13
|
+
for (let option of options) {
|
|
14
|
+
if (argv.includes(option)) {
|
|
15
|
+
config[option.replace(/^--/, "")] = true;
|
|
16
|
+
const index = argv.indexOf(option);
|
|
17
|
+
delete argv[index];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
command = argv
|
|
22
|
+
.map((part) =>
|
|
23
|
+
part.match(/ |'|"/) ? `'${part.replace(/'/, "\\'")}'` : part
|
|
24
|
+
)
|
|
25
|
+
.join(" ");
|
|
26
|
+
|
|
27
|
+
function getRepositories(path) {
|
|
28
|
+
try {
|
|
29
|
+
const config = require(path);
|
|
30
|
+
return config.repositories;
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(
|
|
33
|
+
color.red + "cannot read repository file in" + color.reset,
|
|
34
|
+
path,
|
|
35
|
+
color.red + "error:" + color.reset,
|
|
36
|
+
err.message
|
|
37
|
+
);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function main(config = {}, repos = null, directory = null) {
|
|
43
|
+
if (!repos) {
|
|
44
|
+
// Existing logic to determine repositories and configuration
|
|
45
|
+
const currentRepoPath = path.resolve(
|
|
46
|
+
process.cwd(),
|
|
47
|
+
"CoCreate.config.js"
|
|
48
|
+
);
|
|
49
|
+
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
50
|
+
|
|
51
|
+
if (config["c"] && fs.existsSync(config["c"])) {
|
|
52
|
+
repos = getRepositories(config["c"]);
|
|
53
|
+
directory = path.dirname(config["c"]);
|
|
54
|
+
console.warn(
|
|
55
|
+
`${color.yellow}using ${config["c"]} configuration${color.reset}`
|
|
56
|
+
);
|
|
57
|
+
} else if (!config["self"] && fs.existsSync(currentRepoPath)) {
|
|
58
|
+
repos = getRepositories(currentRepoPath);
|
|
59
|
+
directory = path.dirname(currentRepoPath);
|
|
60
|
+
console.warn(
|
|
61
|
+
`${color.yellow}using ${currentRepoPath} configuration${color.reset}`
|
|
62
|
+
);
|
|
63
|
+
} else if (fs.existsSync(packageJsonPath)) {
|
|
64
|
+
const repoPath = path.resolve(process.cwd());
|
|
65
|
+
const packageObj = require(packageJsonPath);
|
|
66
|
+
const repoUrl =
|
|
67
|
+
packageObj.repository &&
|
|
68
|
+
packageObj.repository.url.substring(12);
|
|
69
|
+
const repoEntry = packageObj.main;
|
|
70
|
+
repos = [
|
|
71
|
+
{
|
|
72
|
+
path: repoPath,
|
|
73
|
+
repo: repoUrl,
|
|
74
|
+
entry: repoEntry
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
directory = path.dirname(packageJsonPath);
|
|
78
|
+
console.warn(
|
|
79
|
+
`${color.yellow}using ${packageJsonPath} configuration${color.reset}`
|
|
80
|
+
);
|
|
81
|
+
} else {
|
|
82
|
+
console.error(
|
|
83
|
+
`${color.red}a configuration file cannot be found${color.reset}`
|
|
84
|
+
);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
config = { hideMessage: false, ...config };
|
|
90
|
+
|
|
91
|
+
if (repos && repos.length) repos = await addMeta(repos, [], directory);
|
|
92
|
+
|
|
93
|
+
const failed = await execute(command, repos, config);
|
|
94
|
+
|
|
95
|
+
if (failed && failed.length > 0) {
|
|
96
|
+
console.log(
|
|
97
|
+
color.red +
|
|
98
|
+
" **************** failures **************** " +
|
|
99
|
+
color.reset
|
|
100
|
+
);
|
|
101
|
+
for (const failure of failed) {
|
|
102
|
+
console.log(
|
|
103
|
+
color.red + `${failure.name}: ${failure.error}` + color.reset
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
await promptRetry(failed, config, directory);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function promptRetry(failed, config, directory) {
|
|
112
|
+
const rl = readline.createInterface({
|
|
113
|
+
input: process.stdin,
|
|
114
|
+
output: process.stdout
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
rl.question(
|
|
118
|
+
"Do you want to retry the failed commands? (yes/no): ",
|
|
119
|
+
async (answer) => {
|
|
120
|
+
rl.close();
|
|
121
|
+
if (answer.toLowerCase() === "yes") {
|
|
122
|
+
await main(config, failed, directory);
|
|
123
|
+
} else {
|
|
124
|
+
process.exit(0);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
main(config);
|
package/src/commands/acme.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
const { requestCertificate } = require(
|
|
1
|
+
const { requestCertificate } = require("@cocreate/acme");
|
|
2
2
|
|
|
3
3
|
module.exports = async function nginx(repos, args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
if (args.length) {
|
|
8
|
-
if (args[0] === 'create') {
|
|
9
|
-
args.shift()
|
|
10
|
-
await createServer(args);
|
|
11
|
-
} else if (args[0] === 'delete') {
|
|
12
|
-
args.shift()
|
|
13
|
-
await deleteServer(args);
|
|
14
|
-
} else
|
|
15
|
-
await createServer(args);
|
|
16
|
-
}
|
|
17
|
-
} catch (err) {
|
|
18
|
-
failed.push({ name: 'GENERAL', des: err.message });
|
|
19
|
-
console.error(err.red);
|
|
20
|
-
} finally {
|
|
21
|
-
return failed;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
4
|
+
let failed = [];
|
|
25
5
|
|
|
6
|
+
try {
|
|
7
|
+
if (args.length) {
|
|
8
|
+
if (args[0] === "create") {
|
|
9
|
+
args.shift();
|
|
10
|
+
await createServer(args);
|
|
11
|
+
} else if (args[0] === "delete") {
|
|
12
|
+
args.shift();
|
|
13
|
+
await deleteServer(args);
|
|
14
|
+
} else await createServer(args);
|
|
15
|
+
}
|
|
16
|
+
} catch (err) {
|
|
17
|
+
failed.push({ name: "GENERAL", error: err.message });
|
|
18
|
+
console.error(err.red);
|
|
19
|
+
} finally {
|
|
20
|
+
return failed;
|
|
21
|
+
}
|
|
22
|
+
};
|