@acidgreen-au/ag-cicd-cli 0.0.6 → 0.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.
Files changed (2) hide show
  1. package/dist/cli.mjs +72 -25
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -506,14 +506,15 @@ Details:
506
506
  With a name argument: Adds a new named environment, copying path and
507
507
  ignore settings from the default environment.
508
508
 
509
- Prompts for:
509
+ Prompts for (unless provided via options):
510
510
  - Store name (required): Your myshopify.com store URL
511
511
  - Theme ID (optional): Target theme ID for deployment
512
512
 
513
513
  Examples:
514
- $ ag config:shopify # Create/update default environment
515
- $ ag config:shopify production # Add production environment
516
- $ ag config:shopify staging --force # Overwrite staging environment`;
514
+ $ ag config:shopify # Create/update default environment
515
+ $ ag config:shopify production # Add production environment
516
+ $ ag config:shopify staging --force # Overwrite staging environment
517
+ $ ag config:shopify --store my-store.myshopify.com --theme 123456789`;
517
518
  const DEFAULT_IGNORES = [
518
519
  "templates/*.json",
519
520
  "locales/*.json",
@@ -523,7 +524,7 @@ const DEFAULT_IGNORES = [
523
524
  ];
524
525
  const DEFAULT_PATH = "theme";
525
526
  function register$7(program$1) {
526
- program$1.command("config:shopify").description("Create or update shopify.theme.toml configuration").addHelpText("after", helpText$7).argument("[name]", "Environment name (default: 'default')").option("-f, --force", "Overwrite existing environment").action(configShopify);
527
+ program$1.command("config:shopify").description("Create or update shopify.theme.toml configuration").addHelpText("after", helpText$7).argument("[name]", "Environment name (default: 'default')").option("-f, --force", "Overwrite existing environment").option("-s, --store <store>", "Store name (e.g., my-store.myshopify.com)").option("-t, --theme <themeId>", "Theme ID for deployment").action(configShopify);
527
528
  }
528
529
  function loadConfig(configPath) {
529
530
  if (!existsSync(configPath)) return { environments: {} };
@@ -532,41 +533,87 @@ function loadConfig(configPath) {
532
533
  function saveConfig(configPath, config) {
533
534
  writeFileSync(configPath, stringify(config));
534
535
  }
536
+ function validateConfig(config, envName, options) {
537
+ if (config.environments[envName] && !options.force) return {
538
+ success: false,
539
+ message: `Environment '${envName}' already exists. Use --force to overwrite.`,
540
+ envName,
541
+ errorCode: "ENV_EXISTS"
542
+ };
543
+ if (envName !== "default" && !config.environments.default) return {
544
+ success: false,
545
+ message: "Default environment does not exist.",
546
+ envName,
547
+ errorCode: "DEFAULT_MISSING"
548
+ };
549
+ return null;
550
+ }
551
+ function buildEnvConfig(config, response) {
552
+ const defaultEnv = config.environments.default;
553
+ const path = defaultEnv?.path ?? DEFAULT_PATH;
554
+ const ignore = defaultEnv?.ignore ?? DEFAULT_IGNORES;
555
+ const envConfig = {
556
+ store: response.store,
557
+ path,
558
+ ignore
559
+ };
560
+ if (response.themeId) envConfig.theme = response.themeId;
561
+ return envConfig;
562
+ }
535
563
  async function configShopify(name, options) {
536
564
  const configPath = "shopify.theme.toml";
537
- const envName = name ?? "default";
565
+ let envName = name ?? "default";
538
566
  const config = loadConfig(configPath);
539
567
  if (!config.environments) config.environments = {};
540
- if (config.environments[envName] && !options.force) {
541
- console.error(`Error: Environment '${envName}' already exists. Use --force to overwrite.`);
542
- process.exit(1);
543
- }
544
- if (envName !== "default" && !config.environments.default) {
545
- console.error("Error: Default environment must be created first. Run 'ag config:shopify' without arguments.");
568
+ const validationError = validateConfig(config, envName, options);
569
+ if (validationError) if (validationError.errorCode === "DEFAULT_MISSING") {
570
+ const { createDefault } = await prompts({
571
+ type: "confirm",
572
+ name: "createDefault",
573
+ message: `Default environment does not exist. Create 'default' instead of '${envName}'?`,
574
+ initial: true
575
+ }, { onCancel: () => {
576
+ console.log("\nCancelled.");
577
+ process.exit(0);
578
+ } });
579
+ if (createDefault) envName = "default";
580
+ else {
581
+ console.log("\nCancelled.");
582
+ process.exit(0);
583
+ }
584
+ } else {
585
+ console.error(`Error: ${validationError.message}`);
546
586
  process.exit(1);
547
587
  }
548
- const response = await prompts([{
588
+ const defaultEnv = config.environments.default;
589
+ let store = options.store;
590
+ let themeId = options.theme;
591
+ if (!store) store = (await prompts({
549
592
  type: "text",
550
593
  name: "store",
551
594
  message: "Store name (e.g., my-store.myshopify.com)",
595
+ initial: defaultEnv?.store,
552
596
  validate: (value) => value.length > 0 || "Store name is required"
553
- }, {
597
+ }, { onCancel: () => {
598
+ console.log("\nCancelled.");
599
+ process.exit(0);
600
+ } })).store;
601
+ if (themeId === void 0) themeId = (await prompts({
554
602
  type: "text",
555
603
  name: "themeId",
556
604
  message: "Theme ID (optional, press Enter to skip)"
557
- }], { onCancel: () => {
605
+ }, { onCancel: () => {
558
606
  console.log("\nCancelled.");
559
607
  process.exit(0);
560
- } });
561
- const defaultEnv = config.environments.default;
562
- const path = defaultEnv?.path ?? DEFAULT_PATH;
563
- const ignore = defaultEnv?.ignore ?? DEFAULT_IGNORES;
564
- const envConfig = {
565
- store: response.store,
566
- path,
567
- ignore
568
- };
569
- if (response.themeId) envConfig.theme = response.themeId;
608
+ } })).themeId;
609
+ if (!store) {
610
+ console.error("Error: Store name is required.");
611
+ process.exit(1);
612
+ }
613
+ const envConfig = buildEnvConfig(config, {
614
+ store,
615
+ themeId
616
+ });
570
617
  config.environments[envName] = envConfig;
571
618
  saveConfig(configPath, config);
572
619
  console.log(`\n${existsSync(configPath) ? "Updated" : "Created"} ${configPath} with '${envName}' environment`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acidgreen-au/ag-cicd-cli",
3
- "version": "0.0.6",
3
+ "version": "0.1.0",
4
4
  "description": "Acidgreen CI/CD CLI tools",
5
5
  "type": "module",
6
6
  "bin": {