@cocreate/cli 1.49.0 → 1.51.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 +29 -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 +166 -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,167 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
function
|
|
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
|
+
|
|
3
|
+
// Import necessary modules for path operations, file system operations, and more
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const readline = require("readline");
|
|
7
|
+
const execute = require("./execute");
|
|
8
|
+
const addMeta = require("./addMeta");
|
|
9
|
+
const { color } = require("./fonts");
|
|
10
|
+
|
|
11
|
+
// Configuration object for storing options
|
|
12
|
+
let config = {};
|
|
13
|
+
|
|
14
|
+
// Extract arguments from the command line input
|
|
15
|
+
const argv = process.argv.slice(2);
|
|
16
|
+
|
|
17
|
+
// Define available command-line options
|
|
18
|
+
const options = ["-self"];
|
|
19
|
+
|
|
20
|
+
// Iterate over available options and set configurations if specified in argv
|
|
21
|
+
for (let option of options) {
|
|
22
|
+
if (argv.includes(option)) {
|
|
23
|
+
config[option.replace(/^--/, "")] = true;
|
|
24
|
+
const index = argv.indexOf(option);
|
|
25
|
+
delete argv[index];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Format command from argv, handling spaces and quotes
|
|
30
|
+
command = argv
|
|
31
|
+
.map((part) => (part.match(/ |'|"/) ? `'${part.replace(/'/, "'")}'` : part))
|
|
32
|
+
.join(" ");
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Load repository configuration from the given path.
|
|
36
|
+
* @param {string} path - The file path to load repository config from.
|
|
37
|
+
* @returns {Array} - List of repositories.
|
|
38
|
+
*/
|
|
39
|
+
function getRepositories(path) {
|
|
40
|
+
try {
|
|
41
|
+
const config = require(path);
|
|
42
|
+
return config.repositories;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error(
|
|
45
|
+
color.red + "cannot read repository file in" + color.reset,
|
|
46
|
+
path,
|
|
47
|
+
color.red + "error:" + color.reset,
|
|
48
|
+
err.message
|
|
49
|
+
);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Main function to execute commands across repositories.
|
|
56
|
+
* @param {Object} config - The configuration object.
|
|
57
|
+
* @param {Array} [repos=null] - List of repositories to process.
|
|
58
|
+
* @param {string} [directory=null] - The directory path of the configuration.
|
|
59
|
+
*/
|
|
60
|
+
async function main(config = {}, repos = null, directory = null) {
|
|
61
|
+
if (!repos) {
|
|
62
|
+
// Determine repositories and configuration file paths
|
|
63
|
+
const currentRepoPath = path.resolve(
|
|
64
|
+
process.cwd(),
|
|
65
|
+
"CoCreate.config.js"
|
|
66
|
+
);
|
|
67
|
+
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
68
|
+
|
|
69
|
+
// Load repositories from specified config file
|
|
70
|
+
if (config["c"] && fs.existsSync(config["c"])) {
|
|
71
|
+
repos = getRepositories(config["c"]);
|
|
72
|
+
directory = path.dirname(config["c"]);
|
|
73
|
+
console.warn(
|
|
74
|
+
`${color.yellow}using ${config["c"]} configuration${color.reset}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
// Load repositories from default CoCreate.config.js if exists
|
|
78
|
+
else if (!config["self"] && fs.existsSync(currentRepoPath)) {
|
|
79
|
+
repos = getRepositories(currentRepoPath);
|
|
80
|
+
directory = path.dirname(currentRepoPath);
|
|
81
|
+
console.warn(
|
|
82
|
+
`${color.yellow}using ${currentRepoPath} configuration${color.reset}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
// If package.json exists, load repository details from it
|
|
86
|
+
else if (fs.existsSync(packageJsonPath)) {
|
|
87
|
+
const repoPath = path.resolve(process.cwd());
|
|
88
|
+
const packageObj = require(packageJsonPath);
|
|
89
|
+
const repoUrl =
|
|
90
|
+
packageObj.repository &&
|
|
91
|
+
packageObj.repository.url.substring(12);
|
|
92
|
+
const repoEntry = packageObj.main;
|
|
93
|
+
repos = [
|
|
94
|
+
{
|
|
95
|
+
path: repoPath,
|
|
96
|
+
repo: repoUrl,
|
|
97
|
+
entry: repoEntry
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
directory = path.dirname(packageJsonPath);
|
|
101
|
+
console.warn(
|
|
102
|
+
`${color.yellow}using ${packageJsonPath} configuration${color.reset}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
// Error if no configuration can be found
|
|
106
|
+
else {
|
|
107
|
+
console.error(
|
|
108
|
+
`${color.red}a configuration file cannot be found${color.reset}`
|
|
109
|
+
);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Set default config values
|
|
115
|
+
config = { hideMessage: false, ...config };
|
|
116
|
+
|
|
117
|
+
// Add metadata to repos if any are present
|
|
118
|
+
if (repos && repos.length) repos = await addMeta(repos, [], directory);
|
|
119
|
+
|
|
120
|
+
// Execute the command across repositories
|
|
121
|
+
const failed = await execute(command, repos, config);
|
|
122
|
+
|
|
123
|
+
// Handle any failed command executions
|
|
124
|
+
if (failed && failed.length > 0) {
|
|
125
|
+
console.log(
|
|
126
|
+
color.red +
|
|
127
|
+
" **************** failures **************** " +
|
|
128
|
+
color.reset
|
|
129
|
+
);
|
|
130
|
+
for (const failure of failed) {
|
|
131
|
+
console.log(
|
|
132
|
+
color.red + `${failure.name}: ${failure.error}` + color.reset
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Prompt user to retry failed commands
|
|
137
|
+
await promptRetry(failed, config, directory);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Prompt the user to retry failed commands.
|
|
143
|
+
* @param {Array} failed - List of failed commands.
|
|
144
|
+
* @param {Object} config - Configuration object.
|
|
145
|
+
* @param {string} directory - Path of the configuration directory.
|
|
146
|
+
*/
|
|
147
|
+
async function promptRetry(failed, config, directory) {
|
|
148
|
+
const rl = readline.createInterface({
|
|
149
|
+
input: process.stdin,
|
|
150
|
+
output: process.stdout
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
rl.question(
|
|
154
|
+
"Do you want to retry the failed commands? (yes/no): ",
|
|
155
|
+
async (answer) => {
|
|
156
|
+
rl.close();
|
|
157
|
+
if (answer.toLowerCase() === "yes") {
|
|
158
|
+
await main(config, failed, directory);
|
|
159
|
+
} else {
|
|
160
|
+
process.exit(0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Call the main function with initial configuration
|
|
167
|
+
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
|
+
};
|