@acidgreen-au/ag-cicd-cli 0.4.0 → 0.6.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 +50 -3
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -125,6 +125,17 @@ function pushToRemote(remote, branch) {
125
125
 
126
126
  //#endregion
127
127
  //#region src/commands/check-tag.ts
128
+ const THEME_SETTINGS_SCHEMA_PATH = "theme/config/settings_schema.json";
129
+ var ThemeVersionMismatchError = class extends Error {
130
+ packageVersion;
131
+ themeVersion;
132
+ constructor(packageVersion, themeVersion) {
133
+ super(`Version mismatch: package.json has version "${packageVersion}" but theme/config/settings_schema.json has theme_version "${themeVersion}"`);
134
+ this.name = "ThemeVersionMismatchError";
135
+ this.packageVersion = packageVersion;
136
+ this.themeVersion = themeVersion;
137
+ }
138
+ };
128
139
  const helpText$10 = `
129
140
  Details:
130
141
  Reads the version from package.json and checks if a corresponding git tag
@@ -161,12 +172,22 @@ function getVersionFromPackage(packagePath) {
161
172
  const content = readFileSync(packagePath, "utf-8");
162
173
  return JSON.parse(content).version;
163
174
  }
175
+ function getThemeVersion(settingsSchemaPath) {
176
+ if (!existsSync(settingsSchemaPath)) return;
177
+ const content = readFileSync(settingsSchemaPath, "utf-8");
178
+ return JSON.parse(content).find((block) => block.name === "theme_info")?.theme_version;
179
+ }
180
+ function validateThemeVersion(packageVersion) {
181
+ const themeVersion = getThemeVersion(THEME_SETTINGS_SCHEMA_PATH);
182
+ if (themeVersion !== void 0 && themeVersion !== packageVersion) throw new ThemeVersionMismatchError(packageVersion, themeVersion);
183
+ }
164
184
  function checkTag(options) {
165
185
  const packagePath = options.packagePath ?? "package.json";
166
186
  const prefix = options.prefix ?? "v";
167
187
  const remote = options.remote ?? "origin";
168
188
  if (options.remote) syncTagsFromRemote(remote);
169
189
  const version$1 = getVersionFromPackage(packagePath);
190
+ validateThemeVersion(version$1);
170
191
  const tag = `${prefix}${version$1}`;
171
192
  if (tagExists(tag)) return {
172
193
  version: version$1,
@@ -756,12 +777,32 @@ function pushTheme(path, themeId, ignorePatterns = [], allowLive = false) {
756
777
  function deleteTheme(themeId) {
757
778
  execSync(`shopify theme delete --theme "${themeId}" --force`, { encoding: "utf-8" });
758
779
  }
780
+ function renameTheme(themeId, name) {
781
+ execSync(`shopify theme rename --theme "${themeId}" --name "${name}"`, { encoding: "utf-8" });
782
+ }
759
783
  function writeDeployEnv(previewUrl, editorUrl, themeId, extras = {}) {
760
784
  let content = `PREVIEW_URL=${previewUrl}\nEDITOR_URL=${editorUrl}\nTHEME_ID=${themeId}\n`;
761
785
  for (const [key, value] of Object.entries(extras)) content += `${key}=${value}\n`;
762
786
  writeFileSync("deploy.env", content);
763
787
  }
764
788
  const previewBranchName = (branch) => `AG Preview: ${branch}`.substring(0, 49);
789
+ function formatDeployThemeName(env, branch) {
790
+ const now = /* @__PURE__ */ new Date();
791
+ const parts = new Intl.DateTimeFormat("en-AU", {
792
+ timeZone: "Australia/Sydney",
793
+ year: "numeric",
794
+ month: "2-digit",
795
+ day: "2-digit",
796
+ hour: "2-digit",
797
+ minute: "2-digit",
798
+ hour12: false
799
+ }).formatToParts(now);
800
+ const get = (type) => parts.find((p) => p.type === type)?.value;
801
+ return `AG ${env} from ${branch} at ${`${get("year")}-${get("month")}-${get("day")}`} ${`${get("hour")}:${get("minute")}`}${(new Intl.DateTimeFormat("en-AU", {
802
+ timeZone: "Australia/Sydney",
803
+ timeZoneName: "shortOffset"
804
+ }).formatToParts(now).find((p) => p.type === "timeZoneName")?.value ?? "GMT+11").replace("GMT", "")}`.substring(0, 50);
805
+ }
765
806
  const defaultIgnores = [
766
807
  "templates/**/*.json",
767
808
  "locales/**/*.json",
@@ -789,17 +830,23 @@ Environment:
789
830
  Examples:
790
831
  $ ag deploy --theme-id 123456789
791
832
  $ ag deploy -t 123456789 --path ./theme
792
- $ ag deploy -t 123456789 --allow-live`;
833
+ $ ag deploy -t 123456789 --allow-live
834
+ $ ag deploy -t 123456789 --env staging --branch feature/auth`;
793
835
  function register$6(program$1) {
794
- program$1.command("deploy").description("Deploy theme to an existing Shopify theme by ID").addHelpText("after", helpText$6).requiredOption("-t, --theme-id <id>", "Target Shopify theme ID").option("-p, --path <path>", "Theme directory path", "theme").option("--allow-live", "Allow pushing to a live (published) theme", false).action(deploy);
836
+ program$1.command("deploy").description("Deploy theme to an existing Shopify theme by ID").addHelpText("after", helpText$6).requiredOption("-t, --theme-id <id>", "Target Shopify theme ID").option("-p, --path <path>", "Theme directory path", "theme").option("--allow-live", "Allow pushing to a live (published) theme", false).option("-e, --env <env>", "Environment name for theme rename").option("-b, --branch <branch>", "Branch name for theme rename").action(deploy);
795
837
  }
796
838
  function deploy(options) {
797
- const { themeId, path, allowLive } = options;
839
+ const { themeId, path, allowLive, env, branch } = options;
798
840
  const themeIdNum = parseInt(themeId, 10);
799
841
  const { preview_url, editor_url } = pushTheme(path, themeIdNum, defaultIgnores, allowLive).theme;
800
842
  console.log("Release deployed successfully!");
801
843
  console.log(`Preview URL: ${preview_url}`);
802
844
  console.log(`Editor URL: ${editor_url}`);
845
+ if (env && branch) {
846
+ const themeName = formatDeployThemeName(env, branch);
847
+ renameTheme(themeIdNum, themeName);
848
+ console.log(`Theme renamed to: ${themeName}`);
849
+ }
803
850
  writeDeployEnv(preview_url, editor_url, themeIdNum);
804
851
  }
805
852
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acidgreen-au/ag-cicd-cli",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Acidgreen CI/CD CLI tools",
5
5
  "type": "module",
6
6
  "bin": {