@by-association-only/cli 2.3.2 → 3.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/dist/index.mjs ADDED
@@ -0,0 +1,436 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/index.ts
22
+ import { program } from "commander";
23
+
24
+ // package.json
25
+ var package_default = {
26
+ name: "@by-association-only/cli",
27
+ version: "3.0.0",
28
+ description: "By Association Only CLI",
29
+ private: false,
30
+ author: "BAO Agency",
31
+ license: "MIT",
32
+ main: "./dist/index.js",
33
+ module: "./dist/index.mjs",
34
+ types: "./dist/index.d.ts",
35
+ files: [
36
+ "dist"
37
+ ],
38
+ exports: {
39
+ ".": {
40
+ require: "./dist/index.js",
41
+ import: "./dist/index.mjs",
42
+ types: "./dist/index.d.ts"
43
+ }
44
+ },
45
+ scripts: {
46
+ dev: "npm run build -- --watch",
47
+ build: "tsup src/index.ts --dts --format cjs,esm",
48
+ watch: "tsup src/index.ts --dts --format cjs,esm --watch",
49
+ lint: "eslint **/*.{t,j}s --fix",
50
+ test: "vitest run"
51
+ },
52
+ peerDependencies: {
53
+ vite: "^4.0.4"
54
+ },
55
+ devDependencies: {
56
+ "@types/inquirer": "^9.0.3",
57
+ tsconfig: "workspace:*",
58
+ "type-fest": "^3.5.1",
59
+ vitest: "^0.25.7"
60
+ },
61
+ dependencies: {
62
+ "@octokit/rest": "^19.0.7",
63
+ "@sindresorhus/slugify": "^2.1.1",
64
+ commander: "^9.5.0",
65
+ inquirer: "^9.1.4",
66
+ kleur: "^4.1.5"
67
+ }
68
+ };
69
+
70
+ // src/commands/create/index.ts
71
+ import inquirer from "inquirer";
72
+ import kleur4 from "kleur";
73
+
74
+ // src/commands/config.ts
75
+ import * as os from "os";
76
+ import * as fs from "fs";
77
+ var config = {
78
+ get localProjectDirectory() {
79
+ if (process.env.BAO_CODE_DIRECTORY) {
80
+ if (fs.existsSync(process.env.BAO_CODE_DIRECTORY)) {
81
+ return process.env.BAO_CODE_DIRECTORY;
82
+ }
83
+ }
84
+ return `${os.homedir()}/Code`;
85
+ },
86
+ get githubToken() {
87
+ return process.env.GITHUB_AUTH_TOKEN;
88
+ },
89
+ get githubOrganizationName() {
90
+ return "baoagency";
91
+ },
92
+ get starterThemeGitUrl() {
93
+ return "git@github.com:baoagency/do-not-look.git";
94
+ }
95
+ };
96
+
97
+ // src/commands/create/local.ts
98
+ import * as process2 from "process";
99
+ import * as fs2 from "fs";
100
+ import kleur2 from "kleur";
101
+
102
+ // src/commands/utils.ts
103
+ import { execSync, spawn } from "child_process";
104
+ import kleur from "kleur";
105
+ function executableIsAvailable(name) {
106
+ const shell = (command) => execSync(command, { encoding: "utf8" });
107
+ try {
108
+ shell(`which ${name}`);
109
+ return true;
110
+ } catch (e) {
111
+ return false;
112
+ }
113
+ }
114
+ function renderStepTitle(title) {
115
+ console.info(`
116
+ ${kleur.magenta().bold().underline(title)}`);
117
+ }
118
+ function renderStepSuccess(text) {
119
+ console.info(`
120
+ ${kleur.green().bold(`\u2714 ${text}`)}`);
121
+ }
122
+ function renderStepError(text, error) {
123
+ console.info(`
124
+ ${kleur.bgRed().underline(`\u2716 ${text}`)}`);
125
+ throw new Error(error || text);
126
+ }
127
+ function spawnPromise(command, ...args) {
128
+ return new Promise((resolve, reject) => {
129
+ const child = spawn(command, ...args);
130
+ child.on("close", (code) => resolve(code));
131
+ child.on("error", (err) => reject(err));
132
+ });
133
+ }
134
+
135
+ // src/commands/create/local.ts
136
+ async function checkLocalDependencies() {
137
+ renderStepTitle("Checking dependencies");
138
+ const hasGithubToken = process2.env.GITHUB_AUTH_TOKEN !== void 0;
139
+ const gitExists = await executableIsAvailable("git");
140
+ const pnpmExists = await executableIsAvailable("pnpm");
141
+ const codeDirectoryExists = fs2.existsSync(config.localProjectDirectory);
142
+ const passed = hasGithubToken && gitExists && pnpmExists && codeDirectoryExists;
143
+ const renderIcon = (exists) => exists ? kleur2.green("\u2714") : kleur2.red("\u2716");
144
+ console.info(
145
+ `
146
+ ${renderIcon(hasGithubToken)} GITHUB_AUTH_TOKEN
147
+ ${renderIcon(gitExists)} git
148
+ ${renderIcon(pnpmExists)} pnpm
149
+ ${renderIcon(codeDirectoryExists)} ~/Code exists`
150
+ );
151
+ if (!hasGithubToken) {
152
+ console.info(`
153
+ You're missing an environment variable for ${kleur2.red().bold("GITHUB_AUTH_TOKEN")}. This is needed so we can create the repository on GitHub. Please go here: https://github.com/settings/tokens/new and create a new personal access token. Set the expiration to none, unless you want to keep remaking it, which is fine. You'll need the "repo" scope ticked as well.
154
+
155
+ Once that's been generated you will need to add it to your .bash_profile or .zshrc. Once that's been added you can run source ~/.bash_profile or source ~/.zshrc, depending on which shell you use, and run the script again.
156
+ `);
157
+ }
158
+ passed ? renderStepSuccess("yay dependencies") : renderStepError("Dependencies failed");
159
+ return passed;
160
+ }
161
+
162
+ // src/commands/create/starter-theme/index.ts
163
+ import * as fs3 from "fs";
164
+ import { readdir, writeFile } from "fs/promises";
165
+ async function setupStarterTheme(config2, answers) {
166
+ await cloneStarterThemeRepository(config2);
167
+ await moveStarterThemeToProjectLocation(config2);
168
+ await rewriteWorkspacePackageVersions(config2);
169
+ await addHuskyPrepareLine(config2);
170
+ await gitInit(config2);
171
+ await pnpmInstall(config2);
172
+ await doInitialCommits(config2);
173
+ await changeShopifyStoreName(config2, answers);
174
+ await removeTemporaryClone(config2);
175
+ }
176
+ async function cloneStarterThemeRepository(config2) {
177
+ renderStepTitle("Cloning starter theme repository");
178
+ try {
179
+ await spawnPromise(
180
+ "git",
181
+ [
182
+ "clone",
183
+ config2.starterThemeGitUrl,
184
+ config2.temporaryCloneLocation
185
+ ],
186
+ { stdio: "inherit" }
187
+ );
188
+ renderStepSuccess("yay, starter theme");
189
+ } catch (e) {
190
+ renderStepError("Git clone failed", e);
191
+ }
192
+ }
193
+ async function moveStarterThemeToProjectLocation(config2) {
194
+ renderStepTitle("Extracting starter theme");
195
+ const themeLocation = `${config2.temporaryCloneLocation}/themes/starter-theme`;
196
+ try {
197
+ await spawnPromise(
198
+ "mv",
199
+ [themeLocation, config2.localProjectLocation]
200
+ );
201
+ renderStepSuccess(`Moved theme to ${config2.localProjectLocation}`);
202
+ } catch (e) {
203
+ renderStepError("Git clone failed", e);
204
+ }
205
+ }
206
+ async function rewriteWorkspacePackageVersions(config2) {
207
+ renderStepTitle("Fixing package.json versions");
208
+ const packageJson = loadPackageJson(config2.localProjectLocation);
209
+ const rewrittenPackageJson = await rewritePackages(packageJson);
210
+ try {
211
+ await writeFile(
212
+ `${config2.localProjectLocation}/package.json`,
213
+ JSON.stringify(rewrittenPackageJson, null, 2)
214
+ );
215
+ renderStepSuccess("Updated package.json dependency versions");
216
+ } catch (e) {
217
+ renderStepError("Rewriting package.json versions failed", e);
218
+ }
219
+ async function findVersionForPackage(packageName) {
220
+ const packagesLocation = `${config2.temporaryCloneLocation}/packages`;
221
+ const folders = (await readdir(packagesLocation, { withFileTypes: true })).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
222
+ const foundPackage = folders.map((folder) => loadPackageJson(`${packagesLocation}/${folder}`)).find((packageJSON) => packageJSON.name === packageName);
223
+ if (!foundPackage)
224
+ return null;
225
+ return `^${foundPackage.version}`;
226
+ }
227
+ async function rewritePackages(packageJson2) {
228
+ await rewriteListOfPackages("dependencies");
229
+ await rewriteListOfPackages("devDependencies");
230
+ await rewriteListOfPackages("peerDependencies");
231
+ return packageJson2;
232
+ async function rewriteListOfPackages(key) {
233
+ const dependencies = packageJson2[key];
234
+ if (typeof dependencies === "undefined")
235
+ return;
236
+ for (const [packageName, version] of Object.entries(dependencies)) {
237
+ if (version !== "workspace:*")
238
+ continue;
239
+ const packageVersion = await findVersionForPackage(packageName);
240
+ if (!packageVersion)
241
+ continue;
242
+ dependencies[packageName] = packageVersion;
243
+ }
244
+ return packageJson2;
245
+ }
246
+ }
247
+ }
248
+ async function addHuskyPrepareLine(config2) {
249
+ renderStepTitle("Setting up Husky");
250
+ const packageJson = loadPackageJson(config2.localProjectLocation);
251
+ packageJson.scripts.prepare = "husky install";
252
+ try {
253
+ await writeFile(
254
+ `${config2.localProjectLocation}/package.json`,
255
+ JSON.stringify(packageJson, null, 2)
256
+ );
257
+ renderStepSuccess("Added Husky prepare script");
258
+ } catch (e) {
259
+ renderStepError("Setting up Husky failed", e);
260
+ }
261
+ }
262
+ async function gitInit(config2) {
263
+ renderStepTitle("Git in here");
264
+ try {
265
+ await spawnPromise(
266
+ "git",
267
+ [
268
+ "init"
269
+ ],
270
+ { stdio: "inherit", cwd: config2.localProjectLocation }
271
+ );
272
+ renderStepSuccess("Git is in here");
273
+ } catch (e) {
274
+ renderStepError("Git isn't here", e);
275
+ }
276
+ }
277
+ async function pnpmInstall(config2) {
278
+ renderStepTitle("Installing dependencies");
279
+ try {
280
+ await spawnPromise(
281
+ "pnpm",
282
+ [
283
+ "install"
284
+ ],
285
+ { stdio: "inherit", cwd: config2.localProjectLocation }
286
+ );
287
+ renderStepSuccess("Dependencies installed");
288
+ } catch (e) {
289
+ renderStepError("Installing dependencies failed", e);
290
+ }
291
+ }
292
+ async function doInitialCommits(config2) {
293
+ renderStepTitle("Performing initial commits");
294
+ try {
295
+ await spawnPromise(
296
+ "git",
297
+ ["add", "."],
298
+ { cwd: config2.localProjectLocation }
299
+ );
300
+ await spawnPromise(
301
+ "git",
302
+ ["commit", "-m", "Initial commit"],
303
+ { cwd: config2.localProjectLocation }
304
+ );
305
+ renderStepSuccess("Doned");
306
+ } catch (e) {
307
+ renderStepError("Performing initial commits failed", e);
308
+ }
309
+ }
310
+ async function changeShopifyStoreName(config2, answers) {
311
+ renderStepTitle(`Changing dev store name to ${answers.shopName}`);
312
+ const packageJson = loadPackageJson(config2.localProjectLocation);
313
+ if (!packageJson.scripts) {
314
+ return renderStepError("package.json has no scripts key");
315
+ }
316
+ packageJson.scripts["shopify:serve"] = `shopify theme dev -s ${answers.shopName}`;
317
+ try {
318
+ await writeFile(
319
+ `${config2.localProjectLocation}/package.json`,
320
+ JSON.stringify(packageJson, null, 2)
321
+ );
322
+ renderStepSuccess("Added \u{1F44D}");
323
+ } catch (e) {
324
+ renderStepError(`Changing dev store name to ${answers.shopName} failed`, e);
325
+ }
326
+ }
327
+ async function removeTemporaryClone(config2) {
328
+ renderStepTitle(`Removing ${config2.temporaryCloneLocation}`);
329
+ try {
330
+ await spawnPromise(
331
+ "rm",
332
+ [
333
+ "-rf",
334
+ config2.temporaryCloneLocation
335
+ ],
336
+ { stdio: "inherit" }
337
+ );
338
+ renderStepSuccess("All cleaned up");
339
+ } catch (e) {
340
+ renderStepError(`Removing ${config2.temporaryCloneLocation} failed`, e);
341
+ }
342
+ }
343
+ function loadPackageJson(location) {
344
+ return JSON.parse(
345
+ fs3.readFileSync(`${location}/package.json`).toString()
346
+ );
347
+ }
348
+
349
+ // src/commands/create/git/index.ts
350
+ import { Octokit } from "@octokit/rest";
351
+ import kleur3 from "kleur";
352
+
353
+ // src/commands/create/git/utils.ts
354
+ import slugify from "@sindresorhus/slugify";
355
+ function getRepoName(answers) {
356
+ return slugify(answers.projectName);
357
+ }
358
+
359
+ // src/commands/create/git/index.ts
360
+ async function setupGitHub(config2, answers) {
361
+ const octokit = new Octokit({
362
+ auth: config2.githubToken
363
+ });
364
+ renderStepTitle("Creating project on Github");
365
+ try {
366
+ const project = await createRemoteRepository();
367
+ kleur3.green(" \u2714 created project on Github");
368
+ await spawnPromise("git", ["remote", "add", "origin", project.data.ssh_url], { cwd: config2.localProjectLocation });
369
+ await spawnPromise("git", ["push", "-u", "origin", "master"], { cwd: config2.localProjectLocation });
370
+ kleur3.green(" \u2714 pushed master");
371
+ renderStepSuccess("Github project has been created and pushed up");
372
+ } catch (e) {
373
+ renderStepError("Github project creation failed", e);
374
+ }
375
+ function createRemoteRepository() {
376
+ return octokit.repos.createInOrg({
377
+ org: config2.githubOrganizationName,
378
+ name: getRepoName(answers),
379
+ private: true
380
+ });
381
+ }
382
+ }
383
+
384
+ // src/commands/create/index.ts
385
+ async function createProject() {
386
+ const answers = await inquirer.prompt(prompts);
387
+ const createConfig = __spreadProps(__spreadValues({}, config), {
388
+ localProjectLocation: `${config.localProjectDirectory}/${answers.projectName.toLowerCase().replaceAll(" ", "-")}`,
389
+ temporaryCloneLocation: `/tmp/${answers.projectName.toLowerCase().replaceAll(" ", "-")}`
390
+ });
391
+ await checkLocalDependencies();
392
+ await setupStarterTheme(createConfig, answers);
393
+ await setupGitHub(createConfig, answers);
394
+ await finish(createConfig, answers);
395
+ }
396
+ var prompts = [
397
+ {
398
+ type: "input",
399
+ name: "projectName",
400
+ message: "Project name",
401
+ validate(input) {
402
+ return new Promise((resolve) => {
403
+ resolve(input.length > 0);
404
+ });
405
+ }
406
+ },
407
+ {
408
+ type: "input",
409
+ name: "shopName",
410
+ message: "Shopify store name",
411
+ validate(input) {
412
+ return new Promise((resolve) => {
413
+ resolve(input.length > 0);
414
+ });
415
+ },
416
+ filter(input) {
417
+ return input.replace(".myshopify.com", "");
418
+ }
419
+ }
420
+ ];
421
+ async function finish(config2, answers) {
422
+ console.info(kleur4.bold().yellow("\nCongratulations! \u{1F973}\n"));
423
+ console.info(kleur4.cyan("Just to recap what we've just done:"));
424
+ console.info(kleur4.cyan(`- Cloned down the latest starter theme to ${config2.localProjectLocation}`));
425
+ console.info(kleur4.cyan(`- Prepared it with Git, installed all of the packages and setup the "${kleur4.bold().magenta("pnpm run dev")}" command ready for you`));
426
+ console.info(kleur4.cyan(`- Created a GitHub repository at ${kleur4.magenta(`https://github.com/${config2.githubOrganizationName}/${getRepoName(
427
+ answers
428
+ )}`)}`));
429
+ console.info();
430
+ console.info(kleur4.yellow("Not bad for running just 1 command! Happy dev'ing \u270C\uFE0F\n"));
431
+ }
432
+
433
+ // src/index.ts
434
+ program.version(package_default.version).description(package_default.description);
435
+ program.command("create").alias("c").description("Create a Shopify theme project").action(async () => await createProject());
436
+ program.parse(process.argv);
package/package.json CHANGED
@@ -1,27 +1,44 @@
1
1
  {
2
2
  "name": "@by-association-only/cli",
3
- "version": "2.3.2",
4
- "preferGlobal": true,
5
- "main": "index.js",
3
+ "version": "3.0.0",
4
+ "description": "By Association Only CLI",
5
+ "private": false,
6
+ "author": "BAO Agency",
6
7
  "license": "MIT",
7
- "bin": {
8
- "bao": "./index.js"
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "require": "./dist/index.js",
17
+ "import": "./dist/index.mjs",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "vite": "^4.0.4"
23
+ },
24
+ "devDependencies": {
25
+ "@types/inquirer": "^9.0.3",
26
+ "type-fest": "^3.5.1",
27
+ "vitest": "^0.25.7",
28
+ "tsconfig": "0.0.0"
9
29
  },
10
30
  "dependencies": {
11
- "@by-association-only/unisian-env": "^2.1.0",
12
- "@by-association-only/unisian-sync": "^2.1.0",
13
- "@octokit/rest": "^18.0.6",
14
- "@sindresorhus/slugify": "^1.1.0",
15
- "await-spawn": "^4.0.1",
16
- "cli-step": "^1.0.2",
17
- "command-exists": "^1.2.9",
18
- "commander": "^6.1.0",
19
- "dotenv": "^8.2.0",
20
- "inquirer": "^7.3.3",
21
- "is-git-url": "^1.0.0",
22
- "kleur": "^4.1.3",
23
- "node-fetch": "^2.6.1",
24
- "semver": "^7.3.2",
25
- "shopify-api-node": "^3.4.4"
31
+ "@octokit/rest": "^19.0.7",
32
+ "@sindresorhus/slugify": "^2.1.1",
33
+ "commander": "^9.5.0",
34
+ "inquirer": "^9.1.4",
35
+ "kleur": "^4.1.5"
36
+ },
37
+ "scripts": {
38
+ "dev": "npm run build -- --watch",
39
+ "build": "tsup src/index.ts --dts --format cjs,esm",
40
+ "watch": "tsup src/index.ts --dts --format cjs,esm --watch",
41
+ "lint": "eslint **/*.{t,j}s --fix",
42
+ "test": "vitest run"
26
43
  }
27
- }
44
+ }
package/.idea/bao-cli.iml DELETED
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
- <excludeFolder url="file://$MODULE_DIR$/temp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="2 space" />
4
- </state>
5
- </component>