@anaemia/cli 0.1.3 → 0.1.5

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 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
- fsExtra.emptyDirSync(targetPath);
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, "../../../templates/base-app");
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 (!fs.existsSync(templatePath)) {
271
- logger.error(`internal framework error: base-app template folder could not be found at: ${templatePath}`);
272
- process.exit(1);
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 {
275
+ logger.error("Could not source template workspace assets locally or from network registry nodes.");
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 = fsExtra.readJsonSync(pkgJsonPath);
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
- fsExtra.writeJsonSync(pkgJsonPath, pkg, { spaces: 2 });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaemia/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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
- fsExtra.emptyDirSync(targetPath);
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, "../../../templates/base-app");
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
- fsExtra.copySync(templatePath, targetPath, {
334
- filter: (src) => {
335
- const base = path.basename(src);
336
- return !["node_modules", "dist", ".anaemia", ".rspack"].includes(base);
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 = fsExtra.readJsonSync(pkgJsonPath);
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
- fsExtra.writeJsonSync(pkgJsonPath, pkg, { spaces: 2 });
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;