create-icebreaker 0.1.0 → 0.1.2
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/dist/index.mjs +9 -57
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,54 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import process from "node:process";
|
|
3
|
-
import { Command, checkbox, input,
|
|
3
|
+
import { Command, checkbox, input, scaffoldWorkspace, templateChoices } from "@icebreakers/monorepo-templates";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
|
|
6
6
|
//#region src/constants.ts
|
|
7
7
|
const DEFAULT_TARGET = "icebreaker-monorepo";
|
|
8
8
|
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/fs-utils.ts
|
|
11
|
-
async function isEmptyDir(dir) {
|
|
12
|
-
try {
|
|
13
|
-
return (await fs.readdir(dir)).length === 0;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
if (error && error.code === "ENOENT") return true;
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async function prepareTarget(dir, force) {
|
|
20
|
-
if (await isEmptyDir(dir)) {
|
|
21
|
-
await fs.mkdir(dir, { recursive: true });
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (!force) throw new Error(`Target directory ${dir} is not empty. Pass --force to overwrite.`);
|
|
25
|
-
await fs.rm(dir, {
|
|
26
|
-
recursive: true,
|
|
27
|
-
force: true
|
|
28
|
-
});
|
|
29
|
-
await fs.mkdir(dir, { recursive: true });
|
|
30
|
-
}
|
|
31
|
-
async function copyDirContents(sourceDir, targetDir, rootDir = sourceDir) {
|
|
32
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
33
|
-
const entries = await fs.readdir(sourceDir, { withFileTypes: true });
|
|
34
|
-
for (const entry of entries) {
|
|
35
|
-
const from = path.join(sourceDir, entry.name);
|
|
36
|
-
if (shouldSkipTemplatePath(rootDir, from)) continue;
|
|
37
|
-
const targetName = toWorkspaceGitignorePath(entry.name);
|
|
38
|
-
const to = path.join(targetDir, targetName);
|
|
39
|
-
if (entry.isDirectory()) {
|
|
40
|
-
await copyDirContents(from, to, rootDir);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (entry.isSymbolicLink()) {
|
|
44
|
-
const link = await fs.readlink(from);
|
|
45
|
-
await fs.symlink(link, to);
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
await fs.cp(from, to);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
9
|
//#endregion
|
|
53
10
|
//#region src/package-json.ts
|
|
54
11
|
async function updateRootPackageJson(targetDir, projectName) {
|
|
@@ -125,17 +82,13 @@ async function promptTemplates() {
|
|
|
125
82
|
|
|
126
83
|
//#endregion
|
|
127
84
|
//#region src/source-npm.ts
|
|
128
|
-
async function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async function scaffoldFromNpm(targetDir, selectedTemplates) {
|
|
137
|
-
await copyDirContents(skeletonDir, targetDir);
|
|
138
|
-
await copySelectedTemplates(targetDir, selectedTemplates);
|
|
85
|
+
async function scaffoldFromNpm(targetDir, selectedTemplates, force = false) {
|
|
86
|
+
await scaffoldWorkspace({
|
|
87
|
+
targetDir,
|
|
88
|
+
templateKeys: selectedTemplates,
|
|
89
|
+
targetMode: "prepare",
|
|
90
|
+
force
|
|
91
|
+
});
|
|
139
92
|
}
|
|
140
93
|
|
|
141
94
|
//#endregion
|
|
@@ -163,8 +116,7 @@ async function runCreate(targetDirInput, options) {
|
|
|
163
116
|
} else if (isInteractive) selectedTemplates = await promptTemplates();
|
|
164
117
|
const targetDir = path.resolve(process.cwd(), targetInput);
|
|
165
118
|
const projectName = path.basename(targetDir) || targetInput;
|
|
166
|
-
await
|
|
167
|
-
await scaffoldFromNpm(targetDir, selectedTemplates);
|
|
119
|
+
await scaffoldFromNpm(targetDir, selectedTemplates, Boolean(options.force));
|
|
168
120
|
await updateRootPackageJson(targetDir, projectName);
|
|
169
121
|
printNextSteps(targetDir);
|
|
170
122
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-icebreaker",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Bootstrap the icebreaker monorepo template via npm create/pnpm create with optional cleanup",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"node": ">=18.0.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@icebreakers/monorepo-templates": "0.1.
|
|
34
|
+
"@icebreakers/monorepo-templates": "0.1.2"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|