@cocreate/cli 1.48.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/.github/workflows/automated.yml +0 -1
- package/CHANGELOG.md +40 -0
- package/CoCreate.config.js +499 -420
- package/docs/index.html +250 -250
- package/package.json +5 -7
- package/prettier.config.js +18 -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 +81 -31
- package/src/commands/fs/config.js +94 -38
- package/src/commands/fs/gitignore.js +13 -22
- package/src/commands/fs/manual.js +17 -27
- package/src/commands/fs/prettier.config.js +99 -0
- 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/commands/link.js
CHANGED
|
@@ -1,69 +1,82 @@
|
|
|
1
|
-
const spawn = require(
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const fs = require(
|
|
4
|
-
const { color } = require(
|
|
1
|
+
const spawn = require("../spawn");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const { color } = require("../fonts");
|
|
5
5
|
|
|
6
6
|
module.exports = async (repos, args) => {
|
|
7
|
-
|
|
7
|
+
const failed = [],
|
|
8
|
+
isLinked = {};
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
continue
|
|
10
|
+
try {
|
|
11
|
+
for (let repo of repos) {
|
|
12
|
+
if (!repo) continue;
|
|
13
|
+
if (repo.exclude && repo.exclude.includes("link")) continue;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
continue
|
|
15
|
+
if (process.cwd() === repo.absolutePath) continue;
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
if (repo.packageManager === "npm") {
|
|
18
|
+
let dir = path.resolve(process.cwd(), "node_modules");
|
|
19
|
+
let dest = path.resolve(
|
|
20
|
+
path.resolve(repo.absolutePath),
|
|
21
|
+
"node_modules"
|
|
22
|
+
);
|
|
23
|
+
if (dir && dest) {
|
|
24
|
+
if (fs.existsSync(dest))
|
|
25
|
+
await fs.promises.rm(dest, {
|
|
26
|
+
recursive: true,
|
|
27
|
+
force: true
|
|
28
|
+
});
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
await fs.promises.symlink(dir, dest, "dir");
|
|
31
|
+
console.log(repo.packageManager, "link", repo.packageName);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
let exitCode = await spawn(repo.packageManager, ["link"], {
|
|
35
|
+
cwd: repo.absolutePath,
|
|
36
|
+
shell: true,
|
|
37
|
+
stdio: "inherit"
|
|
38
|
+
});
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
if (exitCode !== 0) {
|
|
41
|
+
failed.push({
|
|
42
|
+
name: repo.name,
|
|
43
|
+
error: `${repo.packageManager} link failed`
|
|
44
|
+
});
|
|
45
|
+
console.error(
|
|
46
|
+
color.red +
|
|
47
|
+
`${repo.name}: ${repo.packageManager} link failed` +
|
|
48
|
+
color.reset
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
console.log(repo.packageManager, "link", repo.packageName);
|
|
35
52
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
let exitCode = await spawn(
|
|
54
|
+
repo.packageManager,
|
|
55
|
+
["link", repo.packageName],
|
|
56
|
+
{
|
|
57
|
+
cwd: process.cwd(),
|
|
58
|
+
shell: true,
|
|
59
|
+
stdio: "inherit"
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
if (exitCode !== 0) {
|
|
63
|
+
failed.push({
|
|
64
|
+
name: repo.name,
|
|
65
|
+
error: `${repo.packageManager} link ${repo.packageName} failed`
|
|
66
|
+
});
|
|
67
|
+
console.error(
|
|
68
|
+
color.red +
|
|
69
|
+
`${repo.name}: ${repo.packageManager} link ${repo.packageName} failed` +
|
|
70
|
+
color.reset
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
failed.push({ name: "GENERAL", error: err.message });
|
|
78
|
+
console.error(color.red + `${err}` + color.reset);
|
|
79
|
+
}
|
|
44
80
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
shell: true,
|
|
48
|
-
stdio: 'inherit'
|
|
49
|
-
})
|
|
50
|
-
if (exitCode !== 0) {
|
|
51
|
-
failed.push({
|
|
52
|
-
name: repo.name,
|
|
53
|
-
des: `${repo.packageManager} link ${repo.packageName} failed`
|
|
54
|
-
});
|
|
55
|
-
console.error(color.red + `${repo.name}: ${repo.packageManager} link ${repo.packageName} failed` + color.reset)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
failed.push({ name: 'GENERAL', des: err.message })
|
|
65
|
-
console.error(color.red + `${err}` + color.reset)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return failed;
|
|
69
|
-
}
|
|
81
|
+
return failed;
|
|
82
|
+
};
|
package/src/commands/nginx.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
const { createServer, deleteServer } = require(
|
|
1
|
+
const { createServer, deleteServer } = require("@cocreate/nginx");
|
|
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
|
+
};
|
package/src/commands/symlink.js
CHANGED
|
@@ -1,136 +1,153 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const spawn = require(
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const spawn = require("../spawn");
|
|
4
4
|
|
|
5
5
|
const cwdPath = path.resolve(process.cwd());
|
|
6
|
-
let cwdNodeModulesPath = path.resolve(cwdPath,
|
|
6
|
+
let cwdNodeModulesPath = path.resolve(cwdPath, "node_modules");
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let reposLength,
|
|
9
|
+
failed = [];
|
|
10
10
|
|
|
11
11
|
module.exports = async function (repos, args) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
12
|
+
reposLength = repos.length;
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < repos.length; i++) {
|
|
15
|
+
if (
|
|
16
|
+
cwdPath === repos[i].absolutePath &&
|
|
17
|
+
!fs.existsSync(cwdNodeModulesPath)
|
|
18
|
+
) {
|
|
19
|
+
await install(repos[i], repos);
|
|
20
|
+
reposLength -= 1;
|
|
21
|
+
} else if (repos[i].install == true) {
|
|
22
|
+
reposLength -= 1;
|
|
23
|
+
await install(repos[i], repos);
|
|
24
|
+
} else if (cwdPath !== repos[i].absolutePath) {
|
|
25
|
+
await createSymlink(repos[i]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log("symlink complete");
|
|
30
|
+
return failed;
|
|
31
|
+
};
|
|
33
32
|
|
|
34
33
|
async function createSymlink(repo) {
|
|
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
|
-
|
|
34
|
+
let dpath = path.resolve(repo.absolutePath);
|
|
35
|
+
if (!fs.existsSync(dpath)) {
|
|
36
|
+
failed.push({
|
|
37
|
+
name: "createSymlink",
|
|
38
|
+
error: "path doesn't exist:" + dpath
|
|
39
|
+
});
|
|
40
|
+
return console.error(dpath, "not exist");
|
|
41
|
+
}
|
|
42
|
+
let response = "";
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
let dest = path.resolve(dpath, "node_modules");
|
|
46
|
+
if (dest) {
|
|
47
|
+
if (fs.existsSync(dest)) {
|
|
48
|
+
if (!cwdNodeModulesPath.includes("/CoCreateJS")) {
|
|
49
|
+
let isSymlink = await isSymlinkDirectory(dest);
|
|
50
|
+
if (isSymlink) {
|
|
51
|
+
const targetPath = await getSymlinkTargetPath(dest);
|
|
52
|
+
if (targetPath.includes("/CoCreateJS")) {
|
|
53
|
+
console.warn(
|
|
54
|
+
"symlink already exists with CoCreateJS"
|
|
55
|
+
);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await symlink(repo.name, dest);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
failed.push({
|
|
66
|
+
name: "symlink",
|
|
67
|
+
error: "with response:" + response + err
|
|
68
|
+
});
|
|
69
|
+
console.error(
|
|
70
|
+
repo.name,
|
|
71
|
+
"failed to aquire symlink",
|
|
72
|
+
"with response:",
|
|
73
|
+
response,
|
|
74
|
+
err
|
|
75
|
+
);
|
|
76
|
+
}
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
async function symlink(name, dest) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
try {
|
|
81
|
+
if (fs.existsSync(dest))
|
|
82
|
+
await fs.promises.rm(dest, { recursive: true, force: true });
|
|
83
|
+
|
|
84
|
+
await fs.promises.symlink(cwdNodeModulesPath, dest, "dir");
|
|
85
|
+
console.log(name, "node_modules symlink added");
|
|
86
|
+
} catch (err) {
|
|
87
|
+
failed.push({
|
|
88
|
+
name: "symlink",
|
|
89
|
+
error: "with response: " + response,
|
|
90
|
+
err
|
|
91
|
+
});
|
|
92
|
+
console.error(
|
|
93
|
+
repo.name,
|
|
94
|
+
"failed to acquire symlink",
|
|
95
|
+
"with response:",
|
|
96
|
+
response,
|
|
97
|
+
err
|
|
98
|
+
);
|
|
99
|
+
}
|
|
82
100
|
}
|
|
83
101
|
|
|
84
|
-
|
|
85
102
|
async function install(repo, repos) {
|
|
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
|
-
|
|
103
|
+
let dpath = repo.absolutePath;
|
|
104
|
+
if (!fs.existsSync(dpath)) {
|
|
105
|
+
failed.push({ name: "install", error: "path doesn't exist:" + dpath });
|
|
106
|
+
return console.error(dpath, "not exist");
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
console.log("installing", repo.name);
|
|
110
|
+
let exitCode = await spawn(repo.packageManager, ["install"], {
|
|
111
|
+
cwd: repo.absolutePath,
|
|
112
|
+
shell: true,
|
|
113
|
+
stdio: "inherit"
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (exitCode !== 0) {
|
|
117
|
+
failed.push({
|
|
118
|
+
name: repo.name,
|
|
119
|
+
error: `${repo.packageManager} install failed`
|
|
120
|
+
});
|
|
121
|
+
console.error(
|
|
122
|
+
`${repo.name}: ${repo.packageManager} install failed`.red
|
|
123
|
+
);
|
|
124
|
+
} else {
|
|
125
|
+
console.log(
|
|
126
|
+
`${repo.name}: ${repo.packageManager} install succesful`.green
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
console.error(repo.name, "did not install", err);
|
|
131
|
+
}
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
async function isSymlinkDirectory(path) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
try {
|
|
136
|
+
const stats = await fs.promises.lstat(path);
|
|
137
|
+
return stats.isSymbolicLink();
|
|
138
|
+
} catch (err) {
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
async function getSymlinkTargetPath(symlinkPath) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
try {
|
|
145
|
+
const target = await fs.promises.readlink(symlinkPath);
|
|
146
|
+
const targetPath = fs.realpathSync(target);
|
|
147
|
+
return targetPath;
|
|
148
|
+
} catch (err) {
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
134
151
|
}
|
|
135
152
|
|
|
136
|
-
// module.exports = { symlink }
|
|
153
|
+
// module.exports = { symlink }
|
package/src/execute.js
CHANGED
|
@@ -1,65 +1,78 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const fs = require("fs");
|
|
3
|
-
const spawn = require(
|
|
4
|
-
const util = require(
|
|
5
|
-
const exec = util.promisify(require(
|
|
6
|
-
const { color } = require(
|
|
3
|
+
const spawn = require("./spawn");
|
|
4
|
+
const util = require("node:util");
|
|
5
|
+
const exec = util.promisify(require("node:child_process").exec);
|
|
6
|
+
const { color } = require("./fonts");
|
|
7
7
|
|
|
8
8
|
module.exports = async function execute(command, repos = [], config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let type = args[0]
|
|
12
|
-
args.shift()
|
|
9
|
+
let failed = [];
|
|
10
|
+
let [filename, ...args] = command.replaceAll("'", '"').trim().split(" ");
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
let type;
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (filename.endsWith(".js")) {
|
|
15
|
+
type = filename.slice(0, -3);
|
|
16
|
+
} else {
|
|
17
|
+
type = filename;
|
|
18
|
+
filename += ".js";
|
|
19
|
+
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.log(color.blue + 'running on all repos' + color.reset)
|
|
21
|
+
let predefined = path.resolve(__dirname, "commands", filename);
|
|
22
|
+
let isPredefined = fs.existsSync(predefined);
|
|
23
|
+
let repositories = [];
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
for (let repo of repos) {
|
|
26
|
+
try {
|
|
27
|
+
if (
|
|
28
|
+
repo.exclude &&
|
|
29
|
+
(repo.exclude.includes(type) || repo.exclude.includes(filename))
|
|
30
|
+
) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
const packageJsonPath = path.resolve(repo.path, "package.json");
|
|
35
|
+
const packageObj = require(packageJsonPath);
|
|
36
|
+
repo.entry = packageObj.main;
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.log(color.green + `${repo.name}: ` + color.reset, command)
|
|
33
|
-
let exitCode;
|
|
34
|
-
if (config.hideMessage) {
|
|
35
|
-
const { error } = await exec(command, {
|
|
36
|
-
cwd: repo.absolutePath,
|
|
37
|
-
});
|
|
38
|
+
if (isPredefined) {
|
|
39
|
+
repositories.push(repo);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
stdio: 'inherit'
|
|
46
|
-
})
|
|
47
|
-
}
|
|
43
|
+
console.log(color.green + `${repo.name}: ` + color.reset, command);
|
|
44
|
+
let exitCode;
|
|
45
|
+
if (config.hideMessage) {
|
|
46
|
+
const { error } = await exec(command, {
|
|
47
|
+
cwd: repo.absolutePath
|
|
48
|
+
});
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
if (error) exitCode = 1;
|
|
51
|
+
} else {
|
|
52
|
+
exitCode = await spawn(type, args, {
|
|
53
|
+
cwd: repo.absolutePath,
|
|
54
|
+
shell: true,
|
|
55
|
+
stdio: "inherit"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
54
58
|
|
|
59
|
+
if (exitCode !== 0) {
|
|
60
|
+
repo.error = "command failed: " + command;
|
|
61
|
+
failed.push(repo);
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error(
|
|
65
|
+
color.red +
|
|
66
|
+
`an error occured executing command in ${repo.name} repository` +
|
|
67
|
+
color.reset,
|
|
68
|
+
err.message
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
55
72
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
73
|
+
if (isPredefined) {
|
|
74
|
+
failed = require(predefined)(repositories, args);
|
|
75
|
+
}
|
|
62
76
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
77
|
+
return failed;
|
|
78
|
+
};
|
package/src/index.js
ADDED