@anaemia/cli 0.1.4 → 0.1.6
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.js +34 -36
- package/dist/logger.js +22 -0
- package/package.json +1 -1
- package/src/index.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -9,35 +9,16 @@ import path from "node:path";
|
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { createJiti } from "jiti";
|
|
11
11
|
import fs from "node:fs";
|
|
12
|
+
import { execSync } from "node:child_process";
|
|
12
13
|
import prompts from "prompts";
|
|
13
14
|
import { scaffoldFeature, generateSharedComponent, scaffoldPage, scaffoldHook } from "./scaffold.js";
|
|
14
|
-
import fsExtra from "fs-extra";
|
|
15
15
|
import { transform } from "sucrase";
|
|
16
16
|
import { WebSocketServer } from "ws";
|
|
17
17
|
import { WebSocket as NodeWS } from "ws";
|
|
18
|
+
import logger from "./logger.js";
|
|
18
19
|
import http from "node:http";
|
|
19
20
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
21
|
const __dirname = path.dirname(__filename);
|
|
21
|
-
const logger = {
|
|
22
|
-
prefix: pc.bold(pc.red("[anaemia]")),
|
|
23
|
-
info(msg) {
|
|
24
|
-
console.log(`${this.prefix} ${pc.cyan(msg)}`);
|
|
25
|
-
},
|
|
26
|
-
success(msg) {
|
|
27
|
-
console.log(`${this.prefix} ${pc.green(msg)}`);
|
|
28
|
-
},
|
|
29
|
-
warn(msg) {
|
|
30
|
-
console.log(`${this.prefix} ${pc.yellow(msg)}`);
|
|
31
|
-
},
|
|
32
|
-
error(msg, detail) {
|
|
33
|
-
console.error(`${this.prefix} ${pc.red(msg)}`);
|
|
34
|
-
if (detail)
|
|
35
|
-
console.error(detail);
|
|
36
|
-
},
|
|
37
|
-
compiler(msg) {
|
|
38
|
-
console.log(`${pc.bold(pc.magenta("[compiler]"))} ${msg}`);
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
22
|
const cli = cac("anaemia");
|
|
42
23
|
async function loadUserConfig(appRoot) {
|
|
43
24
|
const configPath = path.resolve(appRoot, "anaemia.config.ts");
|
|
@@ -211,7 +192,6 @@ cli
|
|
|
211
192
|
return;
|
|
212
193
|
}
|
|
213
194
|
if (type === "hook") {
|
|
214
|
-
// supports both "hook:useAuth" and "hook:auth/usePermissions"
|
|
215
195
|
scaffoldHook(normalizedName, appRoot);
|
|
216
196
|
return;
|
|
217
197
|
}
|
|
@@ -257,27 +237,45 @@ cli
|
|
|
257
237
|
process.exit(1);
|
|
258
238
|
}
|
|
259
239
|
logger.warn(`purging existing files inside ${targetDir}...`);
|
|
260
|
-
|
|
240
|
+
fs.rmSync(targetPath, { recursive: true, force: true });
|
|
241
|
+
fs.mkdirSync(targetPath, { recursive: true });
|
|
261
242
|
}
|
|
262
243
|
}
|
|
263
244
|
else {
|
|
264
245
|
fs.mkdirSync(targetPath, { recursive: true });
|
|
265
246
|
}
|
|
266
|
-
let templatePath = path.resolve(__dirname, "
|
|
247
|
+
let templatePath = path.resolve(__dirname, "../templates/template-base");
|
|
267
248
|
if (!fs.existsSync(templatePath)) {
|
|
268
249
|
templatePath = path.resolve(__dirname, "../templates/base-app");
|
|
269
250
|
}
|
|
270
|
-
if (
|
|
271
|
-
logger.
|
|
272
|
-
|
|
251
|
+
if (fs.existsSync(templatePath)) {
|
|
252
|
+
logger.info("unpacking localized scaffolding architecture layout structures...");
|
|
253
|
+
fs.cpSync(templatePath, targetPath, {
|
|
254
|
+
recursive: true,
|
|
255
|
+
filter: (src) => !["node_modules", "dist", ".anaemia", ".rspack"].includes(path.basename(src)),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
logger.warn("local templates missing. fetching remote registry packages over the network...");
|
|
260
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
261
|
+
let packageManager = "npm";
|
|
262
|
+
if (userAgent.includes("pnpm"))
|
|
263
|
+
packageManager = "pnpm";
|
|
264
|
+
else if (userAgent.includes("yarn"))
|
|
265
|
+
packageManager = "yarn";
|
|
266
|
+
try {
|
|
267
|
+
if (packageManager === "pnpm") {
|
|
268
|
+
execSync(`pnpm dlx dlx-unzip @anaemia/template-base "${targetPath}"`, { stdio: "ignore" });
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
execSync(`npx degit colourlabs/anaemia/templates/base-app "${targetPath}"`, { stdio: "ignore" });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
logger.error("could not source template workspace assets locally or from network registry nodes. " + err);
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
273
278
|
}
|
|
274
|
-
logger.info(`scaffolding templates into ${pc.bold(targetPath)}...`);
|
|
275
|
-
fsExtra.copySync(templatePath, targetPath, {
|
|
276
|
-
filter: (src) => {
|
|
277
|
-
const base = path.basename(src);
|
|
278
|
-
return !["node_modules", "dist", ".anaemia", ".rspack"].includes(base);
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
279
|
const removeGitKeepFiles = (dir) => {
|
|
282
280
|
const files = fs.readdirSync(dir);
|
|
283
281
|
for (const file of files) {
|
|
@@ -330,7 +328,7 @@ cli
|
|
|
330
328
|
const pkgJsonPath = path.join(targetPath, "package.json");
|
|
331
329
|
if (fs.existsSync(pkgJsonPath)) {
|
|
332
330
|
try {
|
|
333
|
-
const pkg =
|
|
331
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
334
332
|
pkg.name = path.basename(targetPath);
|
|
335
333
|
if (response.variant === "js") {
|
|
336
334
|
if (pkg.devDependencies) {
|
|
@@ -343,7 +341,7 @@ cli
|
|
|
343
341
|
delete pkg.scripts.typecheck;
|
|
344
342
|
}
|
|
345
343
|
}
|
|
346
|
-
|
|
344
|
+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2), "utf8");
|
|
347
345
|
}
|
|
348
346
|
catch (err) {
|
|
349
347
|
logger.error("failed rewriting package.json manifest structures:", err);
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
const logger = {
|
|
3
|
+
prefix: pc.bold(pc.red("[anaemia]")),
|
|
4
|
+
info(msg) {
|
|
5
|
+
console.log(`${this.prefix} ${pc.cyan(msg)}`);
|
|
6
|
+
},
|
|
7
|
+
success(msg) {
|
|
8
|
+
console.log(`${this.prefix} ${pc.green(msg)}`);
|
|
9
|
+
},
|
|
10
|
+
warn(msg) {
|
|
11
|
+
console.log(`${this.prefix} ${pc.yellow(msg)}`);
|
|
12
|
+
},
|
|
13
|
+
error(msg, detail) {
|
|
14
|
+
console.error(`${this.prefix} ${pc.red(msg)}`);
|
|
15
|
+
if (detail)
|
|
16
|
+
console.error(detail);
|
|
17
|
+
},
|
|
18
|
+
compiler(msg) {
|
|
19
|
+
console.log(`${pc.bold(pc.magenta("[compiler]"))} ${msg}`);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export default logger;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -320,8 +320,8 @@ cli
|
|
|
320
320
|
} else {
|
|
321
321
|
execSync(`npx degit colourlabs/anaemia/templates/base-app "${targetPath}"`, { stdio: "ignore" });
|
|
322
322
|
}
|
|
323
|
-
} catch {
|
|
324
|
-
logger.error("
|
|
323
|
+
} catch (err) {
|
|
324
|
+
logger.error("could not source template workspace assets locally or from network registry nodes. " + err);
|
|
325
325
|
process.exit(1);
|
|
326
326
|
}
|
|
327
327
|
}
|