@anaemia/cli 0.1.3 → 0.1.4
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/package.json +1 -2
- package/src/index.ts +31 -42
- package/src/logger.ts +28 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anaemia/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"anaemia": "./dist/index.js"
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"picocolors": "^1.1.1",
|
|
15
15
|
"prompts": "^2.4.2",
|
|
16
16
|
"sucrase": "^3.35.1",
|
|
17
|
-
"fs-extra": "^11.3.5",
|
|
18
17
|
"ws": "^8.21.0",
|
|
19
18
|
"@anaemia/bundler": "0.1.2",
|
|
20
19
|
"@anaemia/core": "0.1.2"
|
package/src/index.ts
CHANGED
|
@@ -9,40 +9,19 @@ 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 { ChildProcess } from "node:child_process";
|
|
12
|
+
import { ChildProcess, execSync } from "node:child_process";
|
|
13
13
|
import prompts from "prompts";
|
|
14
14
|
import { scaffoldFeature, generateSharedComponent, scaffoldPage, scaffoldHook } from "./scaffold.js";
|
|
15
|
-
import fsExtra from "fs-extra";
|
|
16
15
|
import { transform } from "sucrase";
|
|
17
16
|
import { WebSocketServer } from "ws";
|
|
18
17
|
import { WebSocket as NodeWS } from "ws";
|
|
18
|
+
import logger from "./logger.js";
|
|
19
19
|
import http from "node:http";
|
|
20
20
|
import { AnaemiaConfig } from "@anaemia/core/config";
|
|
21
21
|
|
|
22
22
|
const __filename = fileURLToPath(import.meta.url);
|
|
23
23
|
const __dirname = path.dirname(__filename);
|
|
24
24
|
|
|
25
|
-
const logger = {
|
|
26
|
-
prefix: pc.bold(pc.red("[anaemia]")),
|
|
27
|
-
|
|
28
|
-
info(msg: string) {
|
|
29
|
-
console.log(`${this.prefix} ${pc.cyan(msg)}`);
|
|
30
|
-
},
|
|
31
|
-
success(msg: string) {
|
|
32
|
-
console.log(`${this.prefix} ${pc.green(msg)}`);
|
|
33
|
-
},
|
|
34
|
-
warn(msg: string) {
|
|
35
|
-
console.log(`${this.prefix} ${pc.yellow(msg)}`);
|
|
36
|
-
},
|
|
37
|
-
error(msg: string, detail?: unknown) {
|
|
38
|
-
console.error(`${this.prefix} ${pc.red(msg)}`);
|
|
39
|
-
if (detail) console.error(detail);
|
|
40
|
-
},
|
|
41
|
-
compiler(msg: string) {
|
|
42
|
-
console.log(`${pc.bold(pc.magenta("[compiler]"))} ${msg}`);
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
25
|
const cli = cac("anaemia");
|
|
47
26
|
|
|
48
27
|
interface UserConfigModule {
|
|
@@ -257,7 +236,6 @@ cli
|
|
|
257
236
|
}
|
|
258
237
|
|
|
259
238
|
if (type === "hook") {
|
|
260
|
-
// supports both "hook:useAuth" and "hook:auth/usePermissions"
|
|
261
239
|
scaffoldHook(normalizedName, appRoot);
|
|
262
240
|
return;
|
|
263
241
|
}
|
|
@@ -311,32 +289,43 @@ cli
|
|
|
311
289
|
}
|
|
312
290
|
|
|
313
291
|
logger.warn(`purging existing files inside ${targetDir}...`);
|
|
314
|
-
|
|
292
|
+
fs.rmSync(targetPath, { recursive: true, force: true });
|
|
293
|
+
fs.mkdirSync(targetPath, { recursive: true });
|
|
315
294
|
}
|
|
316
295
|
} else {
|
|
317
296
|
fs.mkdirSync(targetPath, { recursive: true });
|
|
318
297
|
}
|
|
319
298
|
|
|
320
|
-
let templatePath = path.resolve(__dirname, "
|
|
321
|
-
|
|
299
|
+
let templatePath = path.resolve(__dirname, "../templates/template-base");
|
|
322
300
|
if (!fs.existsSync(templatePath)) {
|
|
323
301
|
templatePath = path.resolve(__dirname, "../templates/base-app");
|
|
324
302
|
}
|
|
325
|
-
|
|
326
|
-
if (!fs.existsSync(templatePath)) {
|
|
327
|
-
logger.error(`internal framework error: base-app template folder could not be found at: ${templatePath}`);
|
|
328
|
-
process.exit(1);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
logger.info(`scaffolding templates into ${pc.bold(targetPath)}...`);
|
|
332
303
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
304
|
+
if (fs.existsSync(templatePath)) {
|
|
305
|
+
logger.info("unpacking localized scaffolding architecture layout structures...");
|
|
306
|
+
fs.cpSync(templatePath, targetPath, {
|
|
307
|
+
recursive: true,
|
|
308
|
+
filter: (src) => !["node_modules", "dist", ".anaemia", ".rspack"].includes(path.basename(src)),
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
logger.warn("local templates missing. fetching remote registry packages over the network...");
|
|
312
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
313
|
+
let packageManager = "npm";
|
|
314
|
+
if (userAgent.includes("pnpm")) packageManager = "pnpm";
|
|
315
|
+
else if (userAgent.includes("yarn")) packageManager = "yarn";
|
|
339
316
|
|
|
317
|
+
try {
|
|
318
|
+
if (packageManager === "pnpm") {
|
|
319
|
+
execSync(`pnpm dlx dlx-unzip @anaemia/template-base "${targetPath}"`, { stdio: "ignore" });
|
|
320
|
+
} else {
|
|
321
|
+
execSync(`npx degit colourlabs/anaemia/templates/base-app "${targetPath}"`, { stdio: "ignore" });
|
|
322
|
+
}
|
|
323
|
+
} catch {
|
|
324
|
+
logger.error("Could not source template workspace assets locally or from network registry nodes.");
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
340
329
|
const removeGitKeepFiles = (dir: string) => {
|
|
341
330
|
const files = fs.readdirSync(dir);
|
|
342
331
|
for (const file of files) {
|
|
@@ -396,7 +385,7 @@ cli
|
|
|
396
385
|
const pkgJsonPath = path.join(targetPath, "package.json");
|
|
397
386
|
if (fs.existsSync(pkgJsonPath)) {
|
|
398
387
|
try {
|
|
399
|
-
const pkg =
|
|
388
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
400
389
|
pkg.name = path.basename(targetPath);
|
|
401
390
|
|
|
402
391
|
if (response.variant === "js") {
|
|
@@ -411,7 +400,7 @@ cli
|
|
|
411
400
|
}
|
|
412
401
|
}
|
|
413
402
|
|
|
414
|
-
|
|
403
|
+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2), "utf8");
|
|
415
404
|
} catch (err) {
|
|
416
405
|
logger.error("failed rewriting package.json manifest structures:", err);
|
|
417
406
|
}
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
|
|
3
|
+
const logger = {
|
|
4
|
+
prefix: pc.bold(pc.red("[anaemia]")),
|
|
5
|
+
|
|
6
|
+
info(msg: string) {
|
|
7
|
+
console.log(`${this.prefix} ${pc.cyan(msg)}`);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
success(msg: string) {
|
|
11
|
+
console.log(`${this.prefix} ${pc.green(msg)}`);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
warn(msg: string) {
|
|
15
|
+
console.log(`${this.prefix} ${pc.yellow(msg)}`);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
error(msg: string, detail?: unknown) {
|
|
19
|
+
console.error(`${this.prefix} ${pc.red(msg)}`);
|
|
20
|
+
if (detail) console.error(detail);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
compiler(msg: string) {
|
|
24
|
+
console.log(`${pc.bold(pc.magenta("[compiler]"))} ${msg}`);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default logger;
|