@addmo/create-addmo-app 0.1.1-beta.1
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/LICENSE +21 -0
- package/README.md +14 -0
- package/dist/cli.js +461 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 addmo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @addmo/create-addmo-app
|
|
2
|
+
|
|
3
|
+
[中文](README-zh_CN.md) | English
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Interactive scaffolder: generates a addmo-based extension project from options (template, package manager, entries, skills).
|
|
8
|
+
|
|
9
|
+
- Commands: `create-addmo-app` or `pnpm create addmo-app` (and npm/yarn/bun equivalents)
|
|
10
|
+
- Flow: (1) select framework (vanilla / vue / react / preact / svelte / solid), (2) language (TypeScript / JavaScript), (3) package manager (pnpm / npm / yarn / bun), (4) entries to include (multi-select), (5) whether to install addmo skills (yes/no). Output to cwd or a given directory. Generated project uses **addmo.config.ts** or **addmo.config.js** with minimal manifest (entry discovery; no built-in entry paths in manifest).
|
|
11
|
+
|
|
12
|
+
## Templates
|
|
13
|
+
|
|
14
|
+
Scaffold templates live at **repo root** in **`templates/`** (e.g. `template-vanilla-ts`, `template-react-ts`). The CLI downloads the chosen template from the GitHub repo tarball, so the repo must have `templates/` at root and committed. The npm package does not bundle templates; it fetches from GitHub at scaffold time.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
import prompts from "prompts";
|
|
8
|
+
import { blue, cyan, dim, gray, green, lightBlue, red, trueColor, yellow } from "kolorist";
|
|
9
|
+
import minimist from "minimist";
|
|
10
|
+
import { gunzipSync } from "node:zlib";
|
|
11
|
+
import { detectPackageManager, getExecCommand, getInstallCommand, getRunCommand } from "@addmo/pkg-manager";
|
|
12
|
+
const GITHUB_REPO = "gxy5202/addmo";
|
|
13
|
+
const TEMPLATE_BASE = "templates";
|
|
14
|
+
function getRepoRoot() {
|
|
15
|
+
const fromDist = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
16
|
+
return fromDist;
|
|
17
|
+
}
|
|
18
|
+
function tryLocalTemplates(templateName, destDir) {
|
|
19
|
+
const repoRoot = getRepoRoot();
|
|
20
|
+
const templatePath = join(repoRoot, TEMPLATE_BASE, templateName);
|
|
21
|
+
if (!existsSync(templatePath)) return false;
|
|
22
|
+
mkdirSync(destDir, {
|
|
23
|
+
recursive: true
|
|
24
|
+
});
|
|
25
|
+
cpSync(templatePath, destDir, {
|
|
26
|
+
recursive: true
|
|
27
|
+
});
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function parseTarHeader(buf) {
|
|
31
|
+
if (buf.every((b)=>0 === b)) return null;
|
|
32
|
+
const rawName = buf.subarray(0, 100).toString("utf8").replace(/\0+$/, "");
|
|
33
|
+
const sizeStr = buf.subarray(124, 136).toString("utf8").replace(/\0+$/, "").trim();
|
|
34
|
+
const type = String.fromCharCode(buf[156]);
|
|
35
|
+
const prefix = buf.subarray(345, 500).toString("utf8").replace(/\0+$/, "");
|
|
36
|
+
return {
|
|
37
|
+
name: prefix ? `${prefix}/${rawName}` : rawName,
|
|
38
|
+
size: parseInt(sizeStr, 8) || 0,
|
|
39
|
+
type
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function extractMatchingFiles(tarBuffer, templatePrefix, destDir) {
|
|
43
|
+
let offset = 0;
|
|
44
|
+
while(offset + 512 <= tarBuffer.length){
|
|
45
|
+
const header = parseTarHeader(tarBuffer.subarray(offset, offset + 512));
|
|
46
|
+
offset += 512;
|
|
47
|
+
if (!header) break;
|
|
48
|
+
const dataBlocks = 512 * Math.ceil(header.size / 512);
|
|
49
|
+
const idx = header.name.indexOf(templatePrefix);
|
|
50
|
+
if (-1 !== idx) {
|
|
51
|
+
const relativePath = header.name.substring(idx + templatePrefix.length).replace(/^\//, "");
|
|
52
|
+
if (relativePath) {
|
|
53
|
+
const destPath = join(destDir, relativePath);
|
|
54
|
+
const isDir = "5" === header.type || relativePath.endsWith("/");
|
|
55
|
+
if (isDir) mkdirSync(destPath, {
|
|
56
|
+
recursive: true
|
|
57
|
+
});
|
|
58
|
+
else if ("0" === header.type || "\0" === header.type) {
|
|
59
|
+
mkdirSync(dirname(destPath), {
|
|
60
|
+
recursive: true
|
|
61
|
+
});
|
|
62
|
+
writeFileSync(destPath, tarBuffer.subarray(offset, offset + header.size));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
offset += dataBlocks;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function downloadTemplate(templateName, destDir, branch = "main") {
|
|
70
|
+
const url = `https://codeload.github.com/${GITHUB_REPO}/tar.gz/${branch}`;
|
|
71
|
+
const templatePrefix = `${TEMPLATE_BASE}/${templateName}/`;
|
|
72
|
+
const response = await fetch(url);
|
|
73
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
74
|
+
const compressed = Buffer.from(await response.arrayBuffer());
|
|
75
|
+
const tarBuffer = gunzipSync(compressed);
|
|
76
|
+
mkdirSync(destDir, {
|
|
77
|
+
recursive: true
|
|
78
|
+
});
|
|
79
|
+
extractMatchingFiles(tarBuffer, templatePrefix, destDir);
|
|
80
|
+
}
|
|
81
|
+
const FRAMEWORKS = [
|
|
82
|
+
{
|
|
83
|
+
title: "Vanilla",
|
|
84
|
+
value: "vanilla"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
title: "Vue",
|
|
88
|
+
value: "vue"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
title: "React",
|
|
92
|
+
value: "react"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
title: "Preact",
|
|
96
|
+
value: "preact"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
title: "Svelte",
|
|
100
|
+
value: "svelte"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
title: "Solid",
|
|
104
|
+
value: "solid"
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
function getTemplateName(framework, language) {
|
|
108
|
+
return `template-${framework}-${language}`;
|
|
109
|
+
}
|
|
110
|
+
const PACKAGE_MANAGER_CHOICES = [
|
|
111
|
+
{
|
|
112
|
+
title: "pnpm",
|
|
113
|
+
value: "pnpm"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
title: "npm",
|
|
117
|
+
value: "npm"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
title: "yarn",
|
|
121
|
+
value: "yarn"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
title: "bun",
|
|
125
|
+
value: "bun"
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
const ENTRY_NAMES = [
|
|
129
|
+
"popup",
|
|
130
|
+
"options",
|
|
131
|
+
"background",
|
|
132
|
+
"content",
|
|
133
|
+
"devtools",
|
|
134
|
+
"sidepanel",
|
|
135
|
+
"sandbox",
|
|
136
|
+
"newtab",
|
|
137
|
+
"bookmarks",
|
|
138
|
+
"history",
|
|
139
|
+
"offscreen"
|
|
140
|
+
];
|
|
141
|
+
const ENTRY_APP_DIRS = ENTRY_NAMES;
|
|
142
|
+
const ENTRY_CHOICES = [
|
|
143
|
+
{
|
|
144
|
+
title: "All (popup, options, background, content, …)",
|
|
145
|
+
value: "__all__"
|
|
146
|
+
},
|
|
147
|
+
...ENTRY_NAMES.map((name)=>({
|
|
148
|
+
title: name,
|
|
149
|
+
value: name
|
|
150
|
+
}))
|
|
151
|
+
];
|
|
152
|
+
const APP_DIR = "app";
|
|
153
|
+
function filterAppEntries(destDir, selectedEntries) {
|
|
154
|
+
const useAll = selectedEntries.includes("__all__");
|
|
155
|
+
if (useAll) return;
|
|
156
|
+
const keepSet = new Set(selectedEntries);
|
|
157
|
+
const appPath = join(destDir, APP_DIR);
|
|
158
|
+
if (!existsSync(appPath)) return;
|
|
159
|
+
const dirs = readdirSync(appPath, {
|
|
160
|
+
withFileTypes: true
|
|
161
|
+
}).filter((d)=>d.isDirectory()).map((d)=>d.name);
|
|
162
|
+
for (const dir of dirs){
|
|
163
|
+
const isEntryDir = ENTRY_APP_DIRS.includes(dir);
|
|
164
|
+
if (isEntryDir && !keepSet.has(dir)) rmSync(join(appPath, dir), {
|
|
165
|
+
recursive: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function getExistingAppEntryDirs(destDir) {
|
|
170
|
+
const appPath = join(destDir, APP_DIR);
|
|
171
|
+
if (!existsSync(appPath)) return [];
|
|
172
|
+
return readdirSync(appPath, {
|
|
173
|
+
withFileTypes: true
|
|
174
|
+
}).filter((d)=>d.isDirectory()).map((d)=>d.name).filter((name)=>ENTRY_APP_DIRS.includes(name));
|
|
175
|
+
}
|
|
176
|
+
function getPluginBlock(framework) {
|
|
177
|
+
switch(framework){
|
|
178
|
+
case "react":
|
|
179
|
+
return {
|
|
180
|
+
import: "import { pluginReact } from \"@rsbuild/plugin-react\";",
|
|
181
|
+
usage: "plugins: [pluginReact()],"
|
|
182
|
+
};
|
|
183
|
+
case "preact":
|
|
184
|
+
return {
|
|
185
|
+
import: "import { pluginPreact } from \"@rsbuild/plugin-preact\";",
|
|
186
|
+
usage: "plugins: [pluginPreact()],"
|
|
187
|
+
};
|
|
188
|
+
case "vue":
|
|
189
|
+
return {
|
|
190
|
+
import: "import { pluginVue } from \"@rsbuild/plugin-vue\";",
|
|
191
|
+
usage: "plugins: [pluginVue()],"
|
|
192
|
+
};
|
|
193
|
+
case "svelte":
|
|
194
|
+
return {
|
|
195
|
+
import: "import { pluginSvelte } from \"@rsbuild/plugin-svelte\";",
|
|
196
|
+
usage: "plugins: [pluginSvelte()],"
|
|
197
|
+
};
|
|
198
|
+
case "solid":
|
|
199
|
+
return {
|
|
200
|
+
import: "import { pluginSolid } from \"@rsbuild/plugin-solid\";",
|
|
201
|
+
usage: "plugins: [pluginSolid()],"
|
|
202
|
+
};
|
|
203
|
+
default:
|
|
204
|
+
return {
|
|
205
|
+
import: "",
|
|
206
|
+
usage: ""
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const MINIMAL_MANIFEST = ' name: "My Extension",\n version: "1.0.0",\n manifest_version: 3,\n description: "Browser extension built with addmo",\n permissions: ["storage", "activeTab"],';
|
|
211
|
+
function generateAddmoConfig(framework, _language) {
|
|
212
|
+
const { import: pluginImport, usage: pluginUsage } = getPluginBlock(framework);
|
|
213
|
+
const parts = [
|
|
214
|
+
"import { defineConfig } from \"addmo\";",
|
|
215
|
+
pluginImport ? `\n${pluginImport}\n` : "",
|
|
216
|
+
"const manifest = {",
|
|
217
|
+
MINIMAL_MANIFEST,
|
|
218
|
+
"};",
|
|
219
|
+
"",
|
|
220
|
+
"export default defineConfig({",
|
|
221
|
+
" manifest: { chromium: manifest, firefox: { ...manifest } },",
|
|
222
|
+
...pluginUsage ? [
|
|
223
|
+
` ${pluginUsage}`
|
|
224
|
+
] : [],
|
|
225
|
+
"});"
|
|
226
|
+
];
|
|
227
|
+
return parts.filter(Boolean).join("\n");
|
|
228
|
+
}
|
|
229
|
+
const DASH_H = " - - - - - - - - - - - - - - - - - - - - - - - - - ";
|
|
230
|
+
const INNER_W = DASH_H.length;
|
|
231
|
+
function printAddmoLogo(colorFn) {
|
|
232
|
+
const c = colorFn;
|
|
233
|
+
const top = " " + c("┌" + DASH_H + "┐");
|
|
234
|
+
const empty = " " + c("│") + " ".repeat(INNER_W) + c("│");
|
|
235
|
+
const text = "Addmo";
|
|
236
|
+
const pad = Math.max(0, Math.floor((INNER_W - text.length) / 2));
|
|
237
|
+
const textLine = " " + c("│") + " ".repeat(pad) + c(text) + " ".repeat(INNER_W - pad - text.length) + c("│");
|
|
238
|
+
const bottom = " " + c("└" + DASH_H + "┘");
|
|
239
|
+
const art = [
|
|
240
|
+
"",
|
|
241
|
+
top,
|
|
242
|
+
empty,
|
|
243
|
+
textLine,
|
|
244
|
+
empty,
|
|
245
|
+
bottom,
|
|
246
|
+
""
|
|
247
|
+
].join("\n");
|
|
248
|
+
console.log(art);
|
|
249
|
+
}
|
|
250
|
+
const cli_require = createRequire(import.meta.url);
|
|
251
|
+
try {
|
|
252
|
+
const figures = cli_require("prompts/lib/util/figures");
|
|
253
|
+
figures.radioOn = "\u25CF";
|
|
254
|
+
figures.radioOff = "\u25CB";
|
|
255
|
+
} catch {}
|
|
256
|
+
const SKILLS_REPO = "addmo-dev/skills";
|
|
257
|
+
const orange = trueColor(230, 138, 46);
|
|
258
|
+
function getFrameworkChoicesColored() {
|
|
259
|
+
const colors = {
|
|
260
|
+
vanilla: gray,
|
|
261
|
+
vue: green,
|
|
262
|
+
react: cyan,
|
|
263
|
+
preact: yellow,
|
|
264
|
+
svelte: red,
|
|
265
|
+
solid: lightBlue
|
|
266
|
+
};
|
|
267
|
+
return FRAMEWORKS.map((f)=>({
|
|
268
|
+
...f,
|
|
269
|
+
title: colors[f.value](f.title)
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
function getLanguageChoicesColored() {
|
|
273
|
+
return [
|
|
274
|
+
{
|
|
275
|
+
title: cyan("TypeScript"),
|
|
276
|
+
value: "ts"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
title: yellow("JavaScript"),
|
|
280
|
+
value: "js"
|
|
281
|
+
}
|
|
282
|
+
];
|
|
283
|
+
}
|
|
284
|
+
function getPackageManagerChoicesColored() {
|
|
285
|
+
const colors = {
|
|
286
|
+
pnpm: orange,
|
|
287
|
+
npm: red,
|
|
288
|
+
yarn: blue,
|
|
289
|
+
bun: green
|
|
290
|
+
};
|
|
291
|
+
return PACKAGE_MANAGER_CHOICES.map((c)=>({
|
|
292
|
+
...c,
|
|
293
|
+
title: colors[c.value](c.title)
|
|
294
|
+
}));
|
|
295
|
+
}
|
|
296
|
+
function getVersion() {
|
|
297
|
+
try {
|
|
298
|
+
const pkgPath = resolve(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
299
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
300
|
+
return pkg.version ?? "0.0.0";
|
|
301
|
+
} catch {
|
|
302
|
+
return "0.0.0";
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function printHelp() {
|
|
306
|
+
const version = getVersion();
|
|
307
|
+
console.log(`
|
|
308
|
+
create-addmo-app v${version}
|
|
309
|
+
|
|
310
|
+
Create a new addmo extension project
|
|
311
|
+
|
|
312
|
+
Usage:
|
|
313
|
+
create-addmo-app [project-name] [options]
|
|
314
|
+
|
|
315
|
+
Options:
|
|
316
|
+
--framework <name> Skip prompt: vanilla | vue | react | preact | svelte | solid
|
|
317
|
+
--language <lang> Skip prompt: js | ts
|
|
318
|
+
--help Show this help message
|
|
319
|
+
--version Show version number
|
|
320
|
+
|
|
321
|
+
Steps: 1) framework 2) language 3) package manager (pnpm|npm|yarn|bun) 4) entries 5) install skills
|
|
322
|
+
`);
|
|
323
|
+
}
|
|
324
|
+
async function confirmOverwrite(dir) {
|
|
325
|
+
const { overwrite } = await prompts({
|
|
326
|
+
type: "confirm",
|
|
327
|
+
name: "overwrite",
|
|
328
|
+
message: `Directory "${dir}" already exists. Overwrite?`,
|
|
329
|
+
initial: false
|
|
330
|
+
});
|
|
331
|
+
return !!overwrite;
|
|
332
|
+
}
|
|
333
|
+
async function promptOptions() {
|
|
334
|
+
const res = await prompts([
|
|
335
|
+
{
|
|
336
|
+
type: "select",
|
|
337
|
+
name: "framework",
|
|
338
|
+
message: "Select a framework",
|
|
339
|
+
choices: getFrameworkChoicesColored()
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
type: "select",
|
|
343
|
+
name: "language",
|
|
344
|
+
message: "Select a language",
|
|
345
|
+
choices: getLanguageChoicesColored()
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
type: "select",
|
|
349
|
+
name: "packageManager",
|
|
350
|
+
message: "Select package manager",
|
|
351
|
+
choices: getPackageManagerChoicesColored()
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
type: "multiselect",
|
|
355
|
+
name: "entries",
|
|
356
|
+
message: "Select extension entries",
|
|
357
|
+
choices: ENTRY_CHOICES,
|
|
358
|
+
min: 1,
|
|
359
|
+
initial: 0,
|
|
360
|
+
hint: "Space to toggle, Enter to confirm (○ unselected, ● selected)"
|
|
361
|
+
}
|
|
362
|
+
]);
|
|
363
|
+
if (!res.framework || !res.language || !res.packageManager || !res.entries?.length) return null;
|
|
364
|
+
return {
|
|
365
|
+
framework: res.framework,
|
|
366
|
+
language: res.language,
|
|
367
|
+
packageManager: res.packageManager,
|
|
368
|
+
entries: res.entries
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function updatePackageName(destDir, projectName) {
|
|
372
|
+
const pkgPath = resolve(destDir, "package.json");
|
|
373
|
+
if (!existsSync(pkgPath)) return;
|
|
374
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
375
|
+
pkg.name = projectName.replace(/\s+/g, "-").toLowerCase();
|
|
376
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
377
|
+
}
|
|
378
|
+
async function main() {
|
|
379
|
+
const argv = minimist(process.argv.slice(2));
|
|
380
|
+
if (argv.help || argv.h) return void printHelp();
|
|
381
|
+
if (argv.version || argv.v) return void console.log(getVersion());
|
|
382
|
+
const targetDir = argv._[0] ?? "my-extension";
|
|
383
|
+
const cliFramework = argv.framework;
|
|
384
|
+
const cliLanguage = argv.language;
|
|
385
|
+
printAddmoLogo(orange);
|
|
386
|
+
console.log(blue("\n Create Addmo App\n"));
|
|
387
|
+
const root = resolve(process.cwd(), targetDir);
|
|
388
|
+
if (existsSync(root)) {
|
|
389
|
+
const confirmed = await confirmOverwrite(targetDir);
|
|
390
|
+
if (!confirmed) process.exit(0);
|
|
391
|
+
}
|
|
392
|
+
const options = cliFramework && cliLanguage ? {
|
|
393
|
+
framework: cliFramework,
|
|
394
|
+
language: cliLanguage,
|
|
395
|
+
packageManager: detectPackageManager(),
|
|
396
|
+
entries: [
|
|
397
|
+
"__all__"
|
|
398
|
+
]
|
|
399
|
+
} : await promptOptions();
|
|
400
|
+
if (!options) process.exit(0);
|
|
401
|
+
const pm = options.packageManager;
|
|
402
|
+
const templateName = getTemplateName(options.framework, options.language);
|
|
403
|
+
console.log(yellow("\n Downloading template...\n"));
|
|
404
|
+
try {
|
|
405
|
+
tryLocalTemplates(templateName, root) || await downloadTemplate(templateName, root);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
console.error(red(`\n Failed to download template: ${err.message}\n`));
|
|
408
|
+
process.exit(1);
|
|
409
|
+
}
|
|
410
|
+
const useAllEntries = options.entries.includes("__all__");
|
|
411
|
+
const existingDirs = getExistingAppEntryDirs(root);
|
|
412
|
+
const effectiveEntries = useAllEntries ? [
|
|
413
|
+
"__all__"
|
|
414
|
+
] : options.entries.filter((e)=>"__all__" !== e && existingDirs.includes(e));
|
|
415
|
+
if (!useAllEntries && effectiveEntries.length > 0) filterAppEntries(root, effectiveEntries);
|
|
416
|
+
const configExt = "ts" === options.language ? "ts" : "js";
|
|
417
|
+
const configPath = resolve(root, `addmo.config.${configExt}`);
|
|
418
|
+
const configContent = generateAddmoConfig(options.framework, options.language);
|
|
419
|
+
writeFileSync(configPath, configContent, "utf-8");
|
|
420
|
+
updatePackageName(root, targetDir);
|
|
421
|
+
const installCmd = getInstallCommand(pm);
|
|
422
|
+
const devCmd = getRunCommand(pm, "dev");
|
|
423
|
+
const { installSkills } = await prompts({
|
|
424
|
+
type: "select",
|
|
425
|
+
name: "installSkills",
|
|
426
|
+
message: "Install addmo skills?",
|
|
427
|
+
choices: [
|
|
428
|
+
{
|
|
429
|
+
title: "Yes",
|
|
430
|
+
value: true
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
title: "No",
|
|
434
|
+
value: false
|
|
435
|
+
}
|
|
436
|
+
],
|
|
437
|
+
initial: 0
|
|
438
|
+
});
|
|
439
|
+
if (true === installSkills) {
|
|
440
|
+
const execCmd = getExecCommand(pm);
|
|
441
|
+
const fullCmd = `${execCmd} skills add ${SKILLS_REPO}`;
|
|
442
|
+
console.log(yellow("\n Running: " + fullCmd + "\n"));
|
|
443
|
+
try {
|
|
444
|
+
execSync(fullCmd, {
|
|
445
|
+
cwd: root,
|
|
446
|
+
stdio: "inherit"
|
|
447
|
+
});
|
|
448
|
+
} catch {
|
|
449
|
+
console.log(dim(" (Skills install skipped or failed; you can run it later.)\n"));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
console.log(green("\n ✓ Project created successfully\n"));
|
|
453
|
+
console.log(dim(" Next steps:\n"));
|
|
454
|
+
console.log(` cd ${targetDir}`);
|
|
455
|
+
console.log(` ${installCmd}`);
|
|
456
|
+
console.log(` ${devCmd}\n`);
|
|
457
|
+
}
|
|
458
|
+
main().catch((e)=>{
|
|
459
|
+
console.error(e);
|
|
460
|
+
process.exit(1);
|
|
461
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@addmo/create-addmo-app",
|
|
3
|
+
"version": "0.1.1-beta.1",
|
|
4
|
+
"description": "Interactive scaffolder for addmo extension projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-addmo-app": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"chalk": "^5.3.0",
|
|
14
|
+
"prompts": "^2.4.2",
|
|
15
|
+
"kolorist": "^1.8.0",
|
|
16
|
+
"minimist": "^1.2.8",
|
|
17
|
+
"@addmo/pkg-manager": "0.1.1-beta.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@rslib/core": "^0.20.0",
|
|
21
|
+
"@rstest/core": "^0.9.2",
|
|
22
|
+
"@rstest/coverage-istanbul": "^0.3.0",
|
|
23
|
+
"@types/node": "^20.0.0",
|
|
24
|
+
"typescript": "^5.0.0"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rslib build",
|
|
28
|
+
"start": "node dist/cli.js",
|
|
29
|
+
"test": "rstest run",
|
|
30
|
+
"test:coverage": "rstest run --coverage"
|
|
31
|
+
}
|
|
32
|
+
}
|