@atomicsmash/cli 11.0.0-beta.2 → 11.0.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/README.md CHANGED
@@ -10,18 +10,18 @@ smash-cli --help
10
10
 
11
11
  ## Development
12
12
 
13
- To develop this npm package, you will need to do the following after cloning the repo:
13
+ To work on this package, navigate to the root of the project and run:
14
14
 
15
- 1. `nvm use`
15
+ 1. `nvm use` - This will set the correct node environment (this is important for permissions for the following step)
16
+ 2. `npm install`
17
+ 3. `npm run dev` - To start tracking file changes and will transpile all `.ts` files down into usable `.js` files in dist.
16
18
 
17
- - This will set the correct node environment (this is important for permissions for the following step)
18
-
19
- 2. `npm link`
19
+ Once these commands are done, you're ready to start working on this project. Check the "CHECKLISTS" file for a checklist of tasks for any development work.
20
20
 
21
- - This will create a symlink in your npm global config, effectively pretending that you've installed the package globally.
21
+ ## Run the package locally
22
22
 
23
- 3. `npm run dev`
23
+ Navigate to the project/site you would like to work on, then run your selected command using:
24
24
 
25
- - This will transpile all `.ts` files down into usable `.js` files in dist.
25
+ `npx <Absolute path to project>/packages/packages/cli <command>`
26
26
 
27
- Once these commands are done, you're ready to start working on this project. Check the "CHECKLISTS" file for a checklist of tasks for any development work.
27
+ Instead of a package name from the npm registry, this points directly to a local directory on disk; npx will look inside that folder's package.json for the bin entry and execute it.
@@ -126,7 +126,7 @@ export async function handler() {
126
126
  ]);
127
127
  const failedCleanups = cleanupResults.filter((result) => result.status === "rejected");
128
128
  if (failedCleanups.length > 0) {
129
- console.warn(`Warning: Failed to delete ${failedCleanups.length} temporary file(s). You may need to clean them up manually.`);
129
+ console.warn(`Warning: Failed to delete ${failedCleanups.length.toString()} temporary file(s). You may need to clean them up manually.`);
130
130
  }
131
131
  process.exitCode = 1;
132
132
  });
@@ -1 +1 @@
1
- {"version":3,"file":"pull-media.d.ts","sourceRoot":"","sources":["../../src/commands/pull-media.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,QAAQ,gDAAgD,CAAC;AACtE,wBAAsB,OAAO,kBA6E5B"}
1
+ {"version":3,"file":"pull-media.d.ts","sourceRoot":"","sources":["../../src/commands/pull-media.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,QAAQ,gDAAgD,CAAC;AACtE,wBAAsB,OAAO,kBA+E5B"}
@@ -66,21 +66,21 @@ export async function handler() {
66
66
  await downloadFiles(mediaPath, localPath, ssh);
67
67
  }
68
68
  else {
69
- console.log(`Downloading media for the last ${mediaMonths} months...`);
69
+ console.log(`Downloading media for the last ${mediaMonths.toString()} months...`);
70
70
  // Download media for each month
71
71
  for (let i = 0; i < mediaMonths; i++) {
72
72
  const date = new Date();
73
73
  date.setMonth(date.getMonth() - i);
74
74
  const year = date.getFullYear();
75
75
  const month = String(date.getMonth() + 1).padStart(2, "0");
76
- const remotePath = `${mediaPath}/${year}/${month}`;
77
- const localPath = `${mediaLocalPath}/${year}`;
76
+ const remotePath = `${mediaPath}/${year.toString()}/${month}`;
77
+ const localPath = `${mediaLocalPath}/${year.toString()}`;
78
78
  console.log(`Attempting to download: ${remotePath} -> ${localPath}`);
79
79
  try {
80
80
  await downloadFiles(remotePath, localPath, ssh);
81
81
  }
82
82
  catch {
83
- console.log(`Skipping uploads/${year}/${month} - directory does not exist on remote server`);
83
+ console.log(`Skipping uploads/${year.toString()}/${month} - directory does not exist on remote server`);
84
84
  return; // Skip to next iteration
85
85
  }
86
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,CAAC;AA+EvB,eAAO,MAAM,OAAO,mBAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,mEAC4C,CAAC;AAClE,wBAAsB,OAAO,kBAiH5B"}
1
+ {"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,CAAC;AA+EvB,eAAO,MAAM,OAAO,mBAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,mEAC4C,CAAC;AAClE,wBAAsB,OAAO,kBA6H5B"}
@@ -56,7 +56,7 @@ async function activatePluginsWithRetry(execute, pluginsToActivate, excludedPlug
56
56
  retryCount++;
57
57
  }
58
58
  if (remainingPlugins.length > 0) {
59
- console.warn(`⚠ Warning: Could not activate all plugins after ${maxRetries} attempts. Remaining: ${remainingPlugins.join(", ")}`);
59
+ console.warn(`⚠ Warning: Could not activate all plugins after ${maxRetries.toString()} attempts. Remaining: ${remainingPlugins.join(", ")}`);
60
60
  }
61
61
  }
62
62
  export const command = "setup-database";
@@ -65,9 +65,15 @@ export async function handler() {
65
65
  const execute = promisify(exec);
66
66
  const smashConfig = await getSmashConfig();
67
67
  // These must remain env vars because they differ for each dev.
68
- const addCustomUser = process.env.WORDPRESS_USER &&
68
+ const newUserToAdd = process.env.WORDPRESS_USER &&
69
69
  process.env.WORDPRESS_USER_EMAIL &&
70
- process.env.WORDPRESS_PASSWORD;
70
+ process.env.WORDPRESS_PASSWORD
71
+ ? {
72
+ user: process.env.WORDPRESS_USER,
73
+ email: process.env.WORDPRESS_USER_EMAIL,
74
+ password: process.env.WORDPRESS_PASSWORD,
75
+ }
76
+ : null;
71
77
  if (!smashConfig) {
72
78
  throw new Error("Unable to determine project setup information. Please add a smash.config.ts file with the required info.");
73
79
  }
@@ -82,14 +88,14 @@ export async function handler() {
82
88
  .then(() => {
83
89
  performance.mark("wordpress-tables");
84
90
  console.log(`Wordpress database tables installed. (${convertMeasureToPrettyString(performance.measure("wordpress-tables", "Start"))})`);
85
- if (addCustomUser) {
86
- return execute(`wp user create ${process.env.WORDPRESS_USER} ${process.env.WORDPRESS_USER_EMAIL} --user_pass=${process.env.WORDPRESS_PASSWORD} --role=administrator`);
91
+ if (newUserToAdd) {
92
+ return execute(`wp user create ${newUserToAdd.user} ${newUserToAdd.email} --user_pass=${newUserToAdd.password} --role=administrator`);
87
93
  }
88
94
  })
89
95
  .then(async () => {
90
- if (addCustomUser) {
96
+ if (newUserToAdd) {
91
97
  performance.mark("add-custom-user");
92
- console.log(`Custom user ${process.env.WORDPRESS_USER} added. (${convertMeasureToPrettyString(performance.measure("add-custom-user", "wordpress-tables"))})`);
98
+ console.log(`Custom user ${newUserToAdd.user} added. (${convertMeasureToPrettyString(performance.measure("add-custom-user", "wordpress-tables"))})`);
93
99
  }
94
100
  const excludedPlugins = [
95
101
  "stream",
@@ -109,18 +115,22 @@ export async function handler() {
109
115
  })
110
116
  .then(() => {
111
117
  performance.mark("plugins");
112
- console.log(`Plugins activated. (${convertMeasureToPrettyString(performance.measure("plugins", addCustomUser ? "add-custom-user" : "wordpress-tables"))})`);
118
+ console.log(`Plugins activated. (${convertMeasureToPrettyString(performance.measure("plugins", newUserToAdd ? "add-custom-user" : "wordpress-tables"))})`);
113
119
  return execute(`wp theme activate ${themeFolderName}`);
114
120
  })
115
121
  .then(async () => {
116
122
  performance.mark("theme");
117
123
  console.log(`Theme activated. (${convertMeasureToPrettyString(performance.measure("theme", "plugins"))})`);
118
124
  await stopRunningMessage();
119
- console.log(`Database set up${addCustomUser ? ` and ${process.env.WORDPRESS_USER} user added` : !process.env.CI ? ". To set up a user, run the `wp user create` command." : ""}. (${convertMeasureToPrettyString(performance.measure("everything", "Start"))})`);
125
+ console.log(`Database set up${newUserToAdd ? ` and ${newUserToAdd.user} user added` : !process.env.CI ? ". To set up a user, run the `wp user create` command." : ""}. (${convertMeasureToPrettyString(performance.measure("everything", "Start"))})`);
120
126
  })
121
127
  .catch(async (error) => {
122
128
  await stopRunningMessage();
123
- if (error.stderr?.startsWith("ERROR 1007")) {
129
+ if (typeof error === "object" &&
130
+ error &&
131
+ "stderr" in error &&
132
+ typeof error.stderr === "string" &&
133
+ error.stderr.startsWith("ERROR 1007")) {
124
134
  console.error("Database already exists with the name in the wp-config. Please delete that database first with `wp db drop --yes`");
125
135
  }
126
136
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,QAAQ,kDAAkD,CAAC;AACxE,wBAAsB,OAAO,kBA8Q5B"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,QAAQ,kDAAkD,CAAC;AACxE,wBAAsB,OAAO,kBAoQ5B"}
@@ -72,25 +72,16 @@ export async function handler() {
72
72
  !existsSync(resolve(process.cwd(), "herd.yml"))) {
73
73
  throw new Error("Herd is present on your machine, but the project is missing a herd.yaml file. Please do the initial setup by running herd init.");
74
74
  }
75
- await execute(`herd init`)
76
- .then(() => {
77
- performance.mark("herd init done");
78
- console.log(`Herd is configured. (${convertMeasureToPrettyString(performance.measure("herd-or-valet", "Start"))})`);
79
- })
80
- .catch((error) => {
81
- console.error(error);
82
- throw new Error("Failed to configure the site using Herd.");
83
- });
84
75
  await execute(`herd link ${projectName} --secure`)
85
76
  .then(() => {
86
77
  performance.mark("herd link done");
87
- console.log(`Herd is linked and secured. (${convertMeasureToPrettyString(performance.measure("herd link", "herd init done"))})`);
78
+ console.log(`Herd is linked and secured. (${convertMeasureToPrettyString(performance.measure("herd link", "Start"))})`);
88
79
  })
89
80
  .catch((error) => {
90
81
  console.error(error);
91
82
  throw new Error("Failed to link the site using Herd.");
92
83
  });
93
- await execute(`herd isolate`)
84
+ await execute(`herd isolate --site=${projectName}`)
94
85
  .then(() => {
95
86
  console.log(`Herd is isolated. (${convertMeasureToPrettyString(performance.measure("herd isolate", "herd link done"))})`);
96
87
  clearTimeout(timeout);
@@ -126,16 +117,16 @@ export async function handler() {
126
117
  console.error(error);
127
118
  throw new Error("Failed to run composer install in the root directory.");
128
119
  }),
129
- ...(composerInstallPaths?.map((path, index) => {
120
+ ...composerInstallPaths.map((path, index) => {
130
121
  return execute(`cd "${resolve(process.cwd(), path)}"; composer install${isCI ? " --no-dev --classmap-authoritative" : ""}`)
131
122
  .then(() => {
132
- console.log(`Additional composer install ${index + 1} done. (${convertMeasureToPrettyString(performance.measure(`additional composer install ${index + 1}`, "Start"))})`);
123
+ console.log(`Additional composer install ${(index + 1).toString()} done. (${convertMeasureToPrettyString(performance.measure(`additional composer install ${(index + 1).toString()}`, "Start"))})`);
133
124
  })
134
125
  .catch((error) => {
135
126
  console.error(error);
136
- throw new Error(`Failed to run additional composer install ${index + 1}.`);
127
+ throw new Error(`Failed to run additional composer install ${(index + 1).toString()}.`);
137
128
  });
138
- }) ?? []),
129
+ }),
139
130
  (async () => {
140
131
  await execute(`npm ${isCI ? "ci" : "install"}`)
141
132
  .then(() => {
@@ -155,18 +146,21 @@ export async function handler() {
155
146
  throw new Error("Failed to run a build after installing.");
156
147
  });
157
148
  })().catch((reason) => {
158
- throw new Error(reason);
149
+ if (typeof reason === "string") {
150
+ throw new Error(reason);
151
+ }
152
+ throw reason;
159
153
  }),
160
- ...(npmInstallPaths?.map((path, index) => {
154
+ ...npmInstallPaths.map((path, index) => {
161
155
  return execute(`cd "${resolve(process.cwd(), path)}"; npm ${isCI ? "ci --omit=dev" : "install"}`)
162
156
  .then(() => {
163
- console.log(`Additional npm install ${index + 1} done. (${convertMeasureToPrettyString(performance.measure(`additional npm install ${index + 1}`, "Start"))})`);
157
+ console.log(`Additional npm install ${(index + 1).toString()} done. (${convertMeasureToPrettyString(performance.measure(`additional npm install ${(index + 1).toString()}`, "Start"))})`);
164
158
  })
165
159
  .catch((error) => {
166
160
  console.error(error);
167
- throw new Error(`Failed to run additional npm install ${index + 1}.`);
161
+ throw new Error(`Failed to run additional npm install ${(index + 1).toString()}.`);
168
162
  });
169
- }) ?? []),
163
+ }),
170
164
  ])
171
165
  .then(async (results) => {
172
166
  await stopRunningMessage();
@@ -176,7 +170,7 @@ export async function handler() {
176
170
  console.error(results
177
171
  .filter((result) => result.status === "rejected")
178
172
  .map((result) => {
179
- return `- ${result.reason}`;
173
+ return `- ${typeof result.reason === "string" ? result.reason : "Unknown reason."}`;
180
174
  })
181
175
  .join(`\n`));
182
176
  }
package/dist/index.js CHANGED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7C,eAAO,MAAM,WAAW,EAAiC,WAAW,CAAC;AAIrE,eAAO,MAAM,WAAW,QAA6D,CAAC;AAItF,eAAO,MAAM,cAAc,QAAsB,CAAC;AAElD,wBAAsB,OAAO,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAqB;WAGtC,aAAa,GAAG,IAAI;YACnB,MAAM;YACN,MAAM;GAaf;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAQvC;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,UAevE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,uBAiClD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7C,eAAO,MAAM,WAAW,EAAiC,WAAW,CAAC;AAIrE,eAAO,MAAM,WAAW,QAA6D,CAAC;AAItF,eAAO,MAAM,cAAc,QAAsB,CAAC;AAElD,wBAAsB,OAAO,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAqB;WAGtC,aAAa,GAAG,IAAI;YACnB,MAAM;YACN,MAAM;GAaf;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAQvC;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,UAevE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,uBA+BlD"}
package/dist/utils.js CHANGED
@@ -33,20 +33,20 @@ export function toCamelCase(text) {
33
33
  });
34
34
  }
35
35
  export function convertMeasureToPrettyString(measure) {
36
- const duration = Number(measure.duration);
36
+ const duration = measure.duration;
37
37
  if (duration < 1) {
38
- return `${duration * 1000}µs`;
38
+ return `${(duration * 1000).toString()}µs`;
39
39
  }
40
40
  if (duration < 999) {
41
- return `${Math.round(duration)}ms`;
41
+ return `${Math.round(duration).toString()}ms`;
42
42
  }
43
43
  const timeInSeconds = Number((duration / 1000).toFixed(2));
44
44
  if (timeInSeconds < 60) {
45
- return `${timeInSeconds}s`;
45
+ return `${timeInSeconds.toString()}s`;
46
46
  }
47
47
  const minutes = Math.floor(timeInSeconds / 60);
48
48
  const seconds = Math.ceil(timeInSeconds % 60);
49
- return `${minutes}m ${seconds}s`;
49
+ return `${minutes.toString()}m ${seconds.toString()}s`;
50
50
  }
51
51
  export function startRunningMessage(message) {
52
52
  let $i = 3;
@@ -63,19 +63,17 @@ export function startRunningMessage(message) {
63
63
  process.stdout.write(`${message}${".".repeat($i)}\r`);
64
64
  }, 200);
65
65
  return async () => {
66
- if (interval) {
67
- clearInterval(interval);
68
- await new Promise((resolve) => {
69
- process.stdout.clearLine(0, () => {
70
- resolve();
71
- });
66
+ clearInterval(interval);
67
+ await new Promise((resolve) => {
68
+ process.stdout.clearLine(0, () => {
69
+ resolve();
72
70
  });
73
- await new Promise((resolve) => {
74
- process.stdout.cursorTo(0, () => {
75
- resolve();
76
- });
71
+ });
72
+ await new Promise((resolve) => {
73
+ process.stdout.cursorTo(0, () => {
74
+ resolve();
77
75
  });
78
- }
76
+ });
79
77
  };
80
78
  }
81
79
  return async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomicsmash/cli",
3
- "version": "11.0.0-beta.2",
3
+ "version": "11.0.0",
4
4
  "description": "A collection of CLI tools by Atomic Smash.",
5
5
  "keywords": [],
6
6
  "homepage": "https://www.atomicsmash.co.uk/",
@@ -40,8 +40,8 @@
40
40
  "lint:types": "tsc -b"
41
41
  },
42
42
  "dependencies": {
43
- "@atomicsmash/date-php": "^2.2.0-beta.0",
44
- "@atomicsmash/smash-config": "^1.0.2-beta.0",
43
+ "@atomicsmash/date-php": "^2.2.0",
44
+ "@atomicsmash/smash-config": "^1.0.2",
45
45
  "@types/vinyl": "^2.0.12",
46
46
  "glob-promise": "^6.0.7",
47
47
  "svg-sprite": "^2.0.4",
@@ -49,8 +49,9 @@
49
49
  "yargs": "^18.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@atomicsmash/blocks-helpers": "^7.2.2-beta.0",
53
- "@types/svg-sprite": "^0.0.39"
52
+ "@atomicsmash/blocks-helpers": "^7.2.2",
53
+ "@types/svg-sprite": "^0.0.39",
54
+ "type-fest": "^5.6.0"
54
55
  },
55
56
  "peerDependencies": {
56
57
  "dotenv": "^17.3.1",