@chrisluyi/daas-cli 1.0.0 → 1.1.0

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/daas-bin ADDED
Binary file
package/dist/index.js CHANGED
@@ -2358,12 +2358,28 @@ function buildShared(shared) {
2358
2358
 
2359
2359
  // ../rsbuild-config/dist/index.js
2360
2360
  function createConfig(manifest, remoteMeta, options) {
2361
- const { mode, port } = options;
2361
+ const { mode, port, target } = options;
2362
2362
  return mergeRsbuildConfig(getDefaults(mode), {
2363
2363
  server: port ? { port } : undefined,
2364
- plugins: [getReactPlugin(), getMF2Plugin(manifest, remoteMeta)]
2364
+ plugins: [getReactPlugin(), getMF2Plugin(manifest, remoteMeta)],
2365
+ source: target ? { alias: buildTargetAliases(target), define: buildTargetDefines(target) } : undefined
2365
2366
  });
2366
2367
  }
2368
+ function buildTargetAliases(target) {
2369
+ return {
2370
+ "@region-config": `./src/config/regions/${target.region}`,
2371
+ "@platform-config": `./src/config/platforms/${target.platform}`,
2372
+ "@product-config": `./src/config/products/${target.product}`
2373
+ };
2374
+ }
2375
+ function buildTargetDefines(target) {
2376
+ return {
2377
+ "process.env.DAAS_REGION": JSON.stringify(target.region),
2378
+ "process.env.DAAS_ENVIRONMENT": JSON.stringify(target.environment),
2379
+ "process.env.DAAS_PLATFORM": JSON.stringify(target.platform),
2380
+ "process.env.DAAS_PRODUCT": JSON.stringify(target.product)
2381
+ };
2382
+ }
2367
2383
 
2368
2384
  // src/daas-config.ts
2369
2385
  import { readFileSync, existsSync } from "fs";
@@ -2518,6 +2534,42 @@ function meetsMinVersion(current, min) {
2518
2534
  return cPatch >= mPatch;
2519
2535
  }
2520
2536
 
2537
+ // src/target.ts
2538
+ import { writeFileSync } from "fs";
2539
+ import { resolve as resolve3 } from "path";
2540
+
2541
+ class TargetParseError extends Error {
2542
+ constructor(message) {
2543
+ super(message);
2544
+ this.name = "TargetParseError";
2545
+ }
2546
+ }
2547
+ function parseTarget(str) {
2548
+ const parts = str.split("-");
2549
+ if (parts.length < 4) {
2550
+ throw new TargetParseError(`Invalid target "${str}". Expected format: {region}-{product}-{platform}-{environment} (e.g. sg-foo-mb-dev)`);
2551
+ }
2552
+ const region = parts[0];
2553
+ const environment = parts[parts.length - 1];
2554
+ const platform2 = parts[parts.length - 2];
2555
+ const product = parts.slice(1, parts.length - 2).join("-");
2556
+ return { region, product, platform: platform2, environment };
2557
+ }
2558
+ function generateTsconfigDaas(cwd, target) {
2559
+ const content = {
2560
+ extends: "./tsconfig.json",
2561
+ compilerOptions: {
2562
+ paths: {
2563
+ "@region-config": [`./src/config/regions/${target.region}`],
2564
+ "@platform-config": [`./src/config/platforms/${target.platform}`],
2565
+ "@product-config": [`./src/config/products/${target.product}`]
2566
+ }
2567
+ }
2568
+ };
2569
+ writeFileSync(resolve3(cwd, "tsconfig.daas.json"), JSON.stringify(content, null, 2) + `
2570
+ `);
2571
+ }
2572
+
2521
2573
  // src/output.ts
2522
2574
  function formatSuccess(command, data) {
2523
2575
  return { ok: true, command, cliVersion: getCliVersion(), ...data };
@@ -2552,6 +2604,7 @@ var EXIT_CODES = {
2552
2604
  var devCommand = defineCommand({
2553
2605
  meta: { name: "dev", description: "Start MFE dev server" },
2554
2606
  args: {
2607
+ target: { type: "positional", description: "Build target (e.g. sg-foo-mb-dev)", required: false },
2555
2608
  port: { type: "string", description: "Override dev server port" },
2556
2609
  json: { type: "boolean", default: false, description: "Machine-readable JSON output" }
2557
2610
  },
@@ -2566,7 +2619,12 @@ var devCommand = defineCommand({
2566
2619
  consola.warn("Config version mismatch \u2014 update daas-cli for full compatibility");
2567
2620
  }
2568
2621
  const port = args.port ? Number(args.port) : daasConfig.port;
2569
- const config = createConfig(manifest, remoteMeta, { mode: "development", port });
2622
+ const target = args.target ? parseTarget(args.target) : undefined;
2623
+ if (target) {
2624
+ generateTsconfigDaas(process.cwd(), target);
2625
+ consola.info(`Target: ${args.target} (region=${target.region}, product=${target.product}, platform=${target.platform}, env=${target.environment})`);
2626
+ }
2627
+ const config = createConfig(manifest, remoteMeta, { mode: "development", port, target });
2570
2628
  consola.start(`Starting ${manifest.name} dev server...`);
2571
2629
  const rsbuild = await createRsbuild({ rsbuildConfig: config });
2572
2630
  const server = await rsbuild.createDevServer();
@@ -2590,6 +2648,12 @@ function handleError(command, e2, json) {
2590
2648
  consola.warn(`Remote config unavailable \u2014 using fallback. ${e2.message}`);
2591
2649
  process.exit(EXIT_CODES.REMOTE_FETCH_FAILED);
2592
2650
  }
2651
+ if (e2 instanceof TargetParseError) {
2652
+ if (json)
2653
+ writeJsonError(command, EXIT_CODES.CONFIG_ERROR, e2.message, "Check target format: {region}-{product}-{platform}-{environment}");
2654
+ consola.fatal(e2.message);
2655
+ process.exit(EXIT_CODES.CONFIG_ERROR);
2656
+ }
2593
2657
  if (e2 instanceof ConfigError || e2 instanceof ManifestError) {
2594
2658
  if (json)
2595
2659
  writeJsonError(command, EXIT_CODES.CONFIG_ERROR, e2.message, "Run daas init first.");
@@ -2605,6 +2669,7 @@ import { createRsbuild as createRsbuild2 } from "@rsbuild/core";
2605
2669
  var buildCommand = defineCommand({
2606
2670
  meta: { name: "build", description: "Build MFE for production" },
2607
2671
  args: {
2672
+ target: { type: "positional", description: "Build target (e.g. sg-foo-mb-prod)", required: false },
2608
2673
  json: { type: "boolean", default: false, description: "Machine-readable JSON output" }
2609
2674
  },
2610
2675
  async run({ args }) {
@@ -2617,7 +2682,10 @@ var buildCommand = defineCommand({
2617
2682
  const remoteMeta = await fetchRemoteConfig(daasConfig.configUrl, true);
2618
2683
  checkCliVersion(remoteMeta);
2619
2684
  checkConfigVersion(remoteMeta, true);
2620
- const config = createConfig(manifest, remoteMeta, { mode: "production" });
2685
+ const target = args.target ? parseTarget(args.target) : undefined;
2686
+ if (target)
2687
+ generateTsconfigDaas(process.cwd(), target);
2688
+ const config = createConfig(manifest, remoteMeta, { mode: "production", target });
2621
2689
  const rsbuild = await createRsbuild2({ rsbuildConfig: config });
2622
2690
  await rsbuild.build();
2623
2691
  if (json)
@@ -2642,6 +2710,12 @@ var buildCommand = defineCommand({
2642
2710
  consola.fatal(e2.message);
2643
2711
  process.exit(EXIT_CODES.CONFIG_VERSION_MISMATCH);
2644
2712
  }
2713
+ if (e2 instanceof TargetParseError) {
2714
+ if (json)
2715
+ writeJsonError("build", EXIT_CODES.CONFIG_ERROR, e2.message, "Check target format: {region}-{product}-{platform}-{environment}");
2716
+ consola.fatal(e2.message);
2717
+ process.exit(EXIT_CODES.CONFIG_ERROR);
2718
+ }
2645
2719
  if (e2 instanceof ConfigError || e2 instanceof ManifestError) {
2646
2720
  if (json)
2647
2721
  writeJsonError("build", EXIT_CODES.CONFIG_ERROR, e2.message, "Run daas init first.");
@@ -2658,7 +2732,7 @@ var buildCommand = defineCommand({
2658
2732
  import { startVitest } from "vitest/node";
2659
2733
 
2660
2734
  // ../rsbuild-config/dist/vitest.js
2661
- import { resolve as resolve3, dirname } from "path";
2735
+ import { resolve as resolve4, dirname } from "path";
2662
2736
  import { fileURLToPath } from "url";
2663
2737
  var __dirname2 = dirname(fileURLToPath(import.meta.url));
2664
2738
  function createVitestConfig(manifest, options = {}) {
@@ -2666,7 +2740,7 @@ function createVitestConfig(manifest, options = {}) {
2666
2740
  test: {
2667
2741
  name: manifest.name,
2668
2742
  environment: "happy-dom",
2669
- setupFiles: [resolve3(__dirname2, "test-setup.js")],
2743
+ setupFiles: [resolve4(__dirname2, "test-setup.js")],
2670
2744
  coverage: {
2671
2745
  provider: "v8",
2672
2746
  reporter: ["text", "lcov"],
@@ -2708,7 +2782,7 @@ var testCommand = defineCommand({
2708
2782
 
2709
2783
  // src/init/monorepo.ts
2710
2784
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
2711
- import { resolve as resolve4, dirname as dirname2 } from "path";
2785
+ import { resolve as resolve5, dirname as dirname2 } from "path";
2712
2786
  function detectMonorepo(startDir) {
2713
2787
  let dir = startDir;
2714
2788
  for (let i2 = 0;i2 < 10; i2++) {
@@ -2716,9 +2790,9 @@ function detectMonorepo(startDir) {
2716
2790
  if (parent === dir)
2717
2791
  break;
2718
2792
  dir = parent;
2719
- if (existsSync3(resolve4(dir, "bun.lockb")))
2793
+ if (existsSync3(resolve5(dir, "bun.lockb")))
2720
2794
  return true;
2721
- const pkgPath = resolve4(dir, "package.json");
2795
+ const pkgPath = resolve5(dir, "package.json");
2722
2796
  if (existsSync3(pkgPath)) {
2723
2797
  try {
2724
2798
  const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
@@ -3263,8 +3337,8 @@ var de = () => {
3263
3337
  };
3264
3338
 
3265
3339
  // src/commands/init.ts
3266
- import { writeFileSync as writeFileSync2, existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
3267
- import { resolve as resolve6 } from "path";
3340
+ import { writeFileSync as writeFileSync3, existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
3341
+ import { resolve as resolve7 } from "path";
3268
3342
 
3269
3343
  // src/init/copy-template.ts
3270
3344
  import { existsSync as existsSync4, copyFileSync, mkdirSync, readdirSync } from "fs";
@@ -3297,10 +3371,10 @@ async function copyTemplate(destDir) {
3297
3371
  }
3298
3372
 
3299
3373
  // src/init/package-json.ts
3300
- import { readFileSync as readFileSync4, writeFileSync, existsSync as existsSync5 } from "fs";
3301
- import { resolve as resolve5 } from "path";
3374
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync2, existsSync as existsSync5 } from "fs";
3375
+ import { resolve as resolve6 } from "path";
3302
3376
  function updatePackageJson(cwd, opts) {
3303
- const pkgPath = resolve5(cwd, "package.json");
3377
+ const pkgPath = resolve6(cwd, "package.json");
3304
3378
  const pkg = existsSync5(pkgPath) ? JSON.parse(readFileSync4(pkgPath, "utf8")) : {};
3305
3379
  pkg.scripts = {
3306
3380
  ...pkg.scripts ?? {},
@@ -3315,7 +3389,7 @@ function updatePackageJson(cwd, opts) {
3315
3389
  };
3316
3390
  }
3317
3391
  pkg.daas = { configUrl: opts.configUrl, port: opts.port };
3318
- writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + `
3392
+ writeFileSync2(pkgPath, JSON.stringify(pkg, null, 2) + `
3319
3393
  `);
3320
3394
  }
3321
3395
 
@@ -3367,7 +3441,7 @@ var initCommand = defineCommand({
3367
3441
  s2.message("\u2713 Updated package.json");
3368
3442
  if (hasExtraExposes) {
3369
3443
  const manifest = { name: appName, exposes: { "./App": "./src/App" } };
3370
- writeFileSync2(resolve6(cwd, "mf.manifest.json"), JSON.stringify(manifest, null, 2) + `
3444
+ writeFileSync3(resolve7(cwd, "mf.manifest.json"), JSON.stringify(manifest, null, 2) + `
3371
3445
  `);
3372
3446
  s2.message("\u2713 Created mf.manifest.json (add extra exposes as needed)");
3373
3447
  }
@@ -3376,7 +3450,7 @@ var initCommand = defineCommand({
3376
3450
  }
3377
3451
  });
3378
3452
  function getPackageName(cwd) {
3379
- const pkgPath = resolve6(cwd, "package.json");
3453
+ const pkgPath = resolve7(cwd, "package.json");
3380
3454
  if (!existsSync6(pkgPath))
3381
3455
  return "mfe-app";
3382
3456
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisluyi/daas-cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "daas": "./dist/index.js"