@by-association-only/cli 3.5.0 โ 4.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.cjs +340 -0
- package/dist/index.js +278 -426
- package/dist/index.js.map +14 -0
- package/package.json +37 -46
- package/src/index.ts +14 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +0 -453
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["packages/cli/src/commands/create.ts", "packages/cli/src/utils.ts", "packages/cli/src/wrangler.ts", "packages/cli/src/constants.ts", "packages/cli/src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import * as fs from \"node:fs\";\nimport { intro, log, note, outro, spinner, text } from \"@clack/prompts\";\nimport * as path from \"node:path\";\nimport { Octokit } from \"octokit\";\nimport { GITHUB_INFO } from \"../utils\";\nimport {\n\tcreateD1Database,\n\tcreateR2Bucket,\n\tcreateKVNamespace,\n\tensureWranglerSessionExists,\n\twriteWranglerConfig, type ResourceProvisionResult,\n} from \"../wrangler\";\nimport { APP_REFERENCE_NAME } from \"../constants\";\nimport type { PartialCreateContext, ValidatedCreateContext } from \"../types\";\nimport color from 'picocolors';\n\nexport async function create (): Promise<void> {\n\tconst initialContext = await initializeContext();\n\n\tconst context = await validateEnvironment(initialContext);\n\n\tawait createGithubRepository(context)\n\tawait cloneGithubRepository(context)\n\tawait provisionCloudflareResources(context)\n\tawait cleanup(context)\n\n\tnote([\n\t\t`1. cd ${context.localPath}`,\n\t\t\"2. shopify app config link\",\n\t\t\"3. bun run dev\",\n\t].join(`\\n`), `${color.bgYellow(color.black(\"Next steps.\"))}`)\n\n\toutro(`Go and build something ${color.underline(color.italic(color.yellow(\"stupendous\")))}.`);\n}\n\nasync function initializeContext (): Promise<PartialCreateContext> {\n\tintro(`Setting up a new BAO ${APP_REFERENCE_NAME} project`);\n\n\tconst appName = await text({\n\t\tmessage: \"What is the name of your project?\",\n\t\tplaceholder: `my-${APP_REFERENCE_NAME.toLowerCase()}-project`,\n\t\tvalidate: value => {\n\t\t\tif (!value.match(/^[a-z0-9-]+$/)) {\n\t\t\t\treturn `Invalid app name: ${value}. App names can only contain lowercase letters, numbers, and dashes.`\n\t\t\t}\n\t\t}\n\t});\n\tconst repoName = `${String(appName)}-app`\n\tconst localPath = `./${repoName}`;\n\n\tif (fs.existsSync(localPath)) {\n\t\tlog.error(`Unable to continue as ${localPath} already exists`)\n\n\t\tprocess.exit(0)\n\t}\n\n\tconst s = spinner();\n\n\treturn {\n\t\tappName: String(appName),\n\t\trepoName,\n\t\tlocalPath,\n\t\tspinner: s,\n\t}\n}\n\nasync function validateEnvironment (initialContext: PartialCreateContext): Promise<ValidatedCreateContext> {\n\tinitialContext.spinner.start(\n\t\t\"Welcome! Checking to make sure your environment is set up correctly.\",\n\t);\n\n\tconst hasEnvironmentAccessToken = typeof process.env.GITHUB_TOKEN !== \"undefined\" && process.env.GITHUB_TOKEN.trim() !== \"\"\n\n\tif (!hasEnvironmentAccessToken) {\n\t\tlog.warning(`Unable to find a GITHUB_TOKEN environment variable. Please go to https://github.com/settings/tokens/new and create an access token to be able to use the CLI.`)\n\t}\n\n\tconst githubAccessToken = process.env.GITHUB_TOKEN || await text({\n\t\tmessage: \"Access token\",\n\t});\n\n\ttry {\n\t\tawait testGithubAccessTokenIsValid(String(githubAccessToken))\n\t} catch (error: any) {\n\t\tlog.error(`Invalid access token: ${error.message}`)\n\n\t\tprocess.exit(0);\n\t}\n\n\tawait ensureWranglerSessionExists(initialContext.spinner);\n\n\tinitialContext.spinner.stop(\"Validated environment\")\n\n\tnote(\n\t\t\"Before using R2, Queues, and Durable objects,\\n\" +\n\t\t\"make sure you've enabled them in the Cloudflare Dashboard.\\n\" +\n\t\t\"https://dash.cloudflare.com/\\n\" +\n\t\t\"Otherwise, the following commands might fail! ๐ฌ\",\n\t\t\"๐ Heads-up:\");\n\n\treturn {\n\t\t...initialContext,\n\t\tgithubPersonalAccessToken: String(githubAccessToken),\n\t\tcloudflare: {},\n\t}\n}\n\nasync function testGithubAccessTokenIsValid (accessToken: string): Promise<string> {\n\tconst octokit = new Octokit({\n\t\tauth: accessToken\n\t})\n\n\tconst { data: { login } } = await octokit.rest.users.getAuthenticated();\n\n\treturn login\n}\n\nasync function createGithubRepository (context: ValidatedCreateContext): Promise<void> {\n\tcontext.spinner.start(`Creating GitHub Repository ${context.repoName}`);\n\n\tconst octokit = new Octokit({\n\t\tauth: context.githubPersonalAccessToken\n\t})\n\n\ttry {\n\t\tconst appRepo = await octokit.rest.repos.createUsingTemplate({\n\t\t\ttemplate_owner: GITHUB_INFO.organization,\n\t\t\ttemplate_repo: GITHUB_INFO.templateRepository,\n\t\t\towner: GITHUB_INFO.organization,\n\t\t\tname: context.repoName,\n\t\t\tprivate: true\n\t\t})\n\n\t\tcontext.repoHttpUrl = appRepo.data.html_url\n\t\tcontext.repoSshUrl = appRepo.data.ssh_url\n\t} catch (error: any) {\n\t\tlog.error(`Unable to create Github Repository ${context.repoName}`);\n\t\tlog.error(error)\n\n\t\tprocess.exit(0);\n\t}\n\n\tcontext.spinner.stop(\"Github repository created! โญ\")\n}\n\nasync function cloneGithubRepository (context: ValidatedCreateContext) {\n\tif (typeof context.repoSshUrl === \"undefined\") {\n\t\tlog.error(`Unable to clone Github repository ${context.repoName} as can't find the .git URL`);\n\n\t\tprocess.exit(0);\n\t}\n\n\tcontext.spinner.start(`Cloning ${context.repoName} from GitHub`)\n\n\tawait new Promise(resolve => setTimeout(resolve, 5000));\n\n\tconst child = Bun.spawn([\"git\", \"clone\", context.repoSshUrl, context.localPath], {\n\t\tstderr: \"ignore\",\n\t\tstdout: \"ignore\",\n\t})\n\n\tawait child.exited;\n\n\tif (fs.existsSync(context.localPath)) {\n\t\tcontext.spinner.stop(`Successfully cloned repository to ${context.localPath}`);\n\n\t\treturn\n\t}\n\n\tcontext.spinner.stop()\n\tlog.error(`Unable to clone repository`)\n\n\tprocess.exit(0)\n}\n\nasync function provisionCloudflareResources (context: ValidatedCreateContext) {\n\tnote([\"Creating the following Cloudflare resources:\", \"- KV\", \"- D1\", \"- R2 Bucket\"].join(`\\n`))\n\n\tcontext.spinner.start(`Creating Cloudflare resources`);\n\n\tconst wranglerConfig = {\n\t\t$schema: \"node_modules/wrangler/config-schema.json\",\n\t\tname: context.appName,\n\t\tcompatibility_date: \"2025-09-21\",\n\t\tcompatibility_flags: [\"nodejs_compat\"],\n\t\tmain: \"@tanstack/react-start/server-entry\",\n\t\tdev: {\n\t\t\tip: \"0.0.0.0\",\n\t\t\tport: 8647\n\t\t},\n\t\tupload_source_maps: true,\n\t\tplacement: {\n\t\t\tmode: \"smart\",\n\t\t},\n\t\tobservability: {\n\t\t\tenabled: true,\n\t\t}\n\t}\n\n\tawait writeWranglerConfig(`${context.localPath}/wrangler.json`, wranglerConfig)\n\n\tconst results: ResourceProvisionResult[] = []\n\n\tcontext.spinner.message(`Creating KV namespace`);\n\tresults.push(await createKVNamespace(context.appName, context.localPath))\n\n\tcontext.spinner.message(`Creating D1 database`);\n\tresults.push(await createD1Database(context.appName, context.localPath))\n\n\tcontext.spinner.message(`Creating R2 bucket`);\n\tresults.push(await createR2Bucket(context.appName, context.localPath))\n\n\tfor (const result of results) {\n\t\tif (!result.success) {\n\t\t\tlog.error(result.message);\n\n\t\t\tprocess.exit(0);\n\t\t}\n\t}\n\n\tcontext.spinner.stop(\"Cloudflare resources created and wrangler.json updated\")\n\n\tconst allResults = results.map(r => r.message)\n\n\tnote(allResults.join(`\\n`), \"Here's what we did:\")\n}\n\nasync function cleanup (context: ValidatedCreateContext) {\n\tcontext.spinner.start(\"Removing unnecessary files from the template\")\n\n\tnote(\"Removing default shopify.app.toml\", \"๐งน Cleaning up\");\n\n\tfs.unlinkSync(path.join(context.localPath, \"shopify.app.toml\"))\n\n\tnote(\"Removing default shopify.app.production.toml\", \"๐งน Cleaning up\");\n\n\tfs.unlinkSync(path.join(context.localPath, \"shopify.app.production.toml\"))\n\n\tcontext.spinner.message(\"Installing packages\")\n\n\tconst packageInstall = Bun.spawn([\"bun\", \"install\"], {\n\t\tstderr: \"ignore\",\n\t\tstdout: \"ignore\",\n\t\tcwd: context.localPath\n\t})\n\tawait packageInstall.exited;\n\n\tcontext.spinner.message(\"Finalising app setup\")\n\n\tconst gitAdd = Bun.spawn([\"git\", \"add\", \".\"], {\n\t\tstderr: \"ignore\",\n\t\tstdout: \"ignore\",\n\t\tcwd: context.localPath\n\t})\n\tawait gitAdd.exited;\n\n\tconst gitCommit = Bun.spawn([\"git\", \"commit\", \"-m\", \"App setup\"], {\n\t\tstderr: \"ignore\",\n\t\tstdout: \"ignore\",\n\t\tcwd: context.localPath\n\t})\n\tawait gitCommit.exited;\n\n\tcontext.spinner.stop()\n}\n",
|
|
6
|
+
"export const PACKAGE_RUNNER_COMMAND = \"bunx\"\n\nexport const GITHUB_INFO = {\n\torganization: \"baoagency\",\n\ttemplateRepository: \"unisian\"\n} as const\n",
|
|
7
|
+
"import { cancel, confirm, isCancel, type spinner } from \"@clack/prompts\";\nimport { APP_REFERENCE_NAME } from \"./constants\";\nimport { PACKAGE_RUNNER_COMMAND } from \"./utils\";\nimport { readFile, writeFile } from \"node:fs/promises\";\n\nexport async function runWranglerCommand (command: string[], cwd?: string): Promise<{\n\tcode: number;\n\tstdout: string;\n\tstderr: string;\n}> {\n\tconst child = Bun.spawn([PACKAGE_RUNNER_COMMAND, \"wrangler@latest\", ...command], {\n\t\tstdin: \"pipe\",\n\t\tstderr: \"pipe\",\n\t\tcwd,\n\t\tenv: {\n\t\t\t...process.env,\n\t\t\tCLOUDFLARE_ACCOUNT_ID: \"824c12820335788e8daf77dba7e7891e\",\n\t\t},\n\t});\n\n\tconst stdout = await new Response(child.stdout).text();\n\tconst stderr = await new Response(child.stderr).text();\n\tconst code = await child.exited;\n\n\treturn new Promise((resolve, reject) => {\n\t\tif (code === 0) {\n\t\t\tresolve({\n\t\t\t\tcode,\n\t\t\t\tstdout,\n\t\t\t\tstderr,\n\t\t\t});\n\t\t}\n\n\t\treject({\n\t\t\tcode,\n\t\t\tstdout,\n\t\t\tstderr,\n\t\t});\n\t});\n}\n\nexport async function ensureWranglerAuthenticated (): Promise<boolean> {\n\ttry {\n\t\tconst result = await runWranglerCommand([\"whoami\"]);\n\n\t\treturn !result.stdout.includes(\"You are not authenticated\");\n\t} catch {\n\t\t// Some older versions of Wrangler return a non-zero exit code when\n\t\t// you're not logged in.\n\t\treturn false;\n\t}\n}\n\nexport async function wranglerLogin (): Promise<void> {\n\tconst child = Bun.spawn([PACKAGE_RUNNER_COMMAND, \"wrangler\", \"login\"], { stdin: \"inherit\" });\n\tconst code = await child.exited;\n\n\treturn await new Promise((resolve, reject) => {\n\t\tif (code === 0) {\n\t\t\tresolve();\n\t\t}\n\n\t\treject();\n\t});\n}\n\nexport async function ensureWranglerSessionExists (s: ReturnType<typeof spinner>): Promise<void> {\n\ts.message(\"Checking to make sure you have the Wrangler CLI installed and authenticated...\");\n\n\tif (!(\n\t\tawait ensureWranglerAuthenticated()\n\t)) {\n\t\ts.stop(\"Hmm. Looks like you're not logged in yet.\");\n\n\t\tconst wantsToLogIn = await confirm({\n\t\t\tmessage:\n\t\t\t\t`You need to be logged into wrangler to setup a ${APP_REFERENCE_NAME} app. Log in now?`,\n\t\t});\n\n\t\tif (isCancel(wantsToLogIn) || !wantsToLogIn) {\n\t\t\tcancel(\n\t\t\t\t`You need to be logged into wrangler to be able to setup a ${APP_REFERENCE_NAME} app.`,\n\t\t\t);\n\n\t\t\tprocess.exit(0);\n\t\t}\n\n\t\tawait wranglerLogin();\n\t}\n}\n\nexport async function getCurrentWranglerConfig (location: string): Promise<Record<string, any>> {\n\treturn JSON.parse(await readFile(location, \"utf-8\"));\n}\n\nexport async function writeWranglerConfig (location: string, config: Record<string, any>): Promise<void> {\n\treturn await writeFile(location, JSON.stringify(config, null, 2));\n}\n\nexport type ResourceProvisionResult = {\n\tsuccess: boolean;\n\tmessage: string;\n}\n\nexport async function createD1Database (name: string, cwd?: string): Promise<ResourceProvisionResult> {\n\ttry {\n\t\tawait runWranglerCommand([\"d1\", \"create\", name, \"--binding=DB\", \"--update-config=true\"], cwd);\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tmessage: `โ
D1 Database: ${name} created!`,\n\t\t};\n\t} catch (error: any) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tmessage: `โ D1 Database: ${error.stderr || error.stdout || error.message}`,\n\t\t};\n\t}\n}\n\nexport async function createKVNamespace (name: string, cwd?: string): Promise<ResourceProvisionResult> {\n\ttry {\n\t\tawait runWranglerCommand(\n\t\t\t[\"kv\", \"namespace\", \"create\", name, \"--binding=BUCKET\", \"--update-config=true\"],\n\t\t\tcwd,\n\t\t);\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tmessage: `โ
KV Namespace: ${name} created!`,\n\t\t};\n\t} catch (error: any) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tmessage: `โ KV Namespace: ${error.stderr || error.stdout || error.message}`,\n\t\t};\n\t}\n}\n\nexport async function createR2Bucket (name: string, cwd?: string): Promise<ResourceProvisionResult> {\n\ttry {\n\t\tawait runWranglerCommand(\n\t\t\t[\"r2\", \"bucket\", \"create\", name, \"--binding=BUCKET\", \"--update-config=true\"],\n\t\t\tcwd,\n\t\t);\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tmessage: `โ
KV Namespace: ${name} created!`,\n\t\t};\n\t} catch (error: any) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tmessage: `โ KV Namespace: ${error.stderr || error.stdout || error.message}`,\n\t\t};\n\t}\n}\n",
|
|
8
|
+
"export const APP_REFERENCE_NAME = \"Unisian\"\n",
|
|
9
|
+
"import { create } from \"./commands/create\";\n\n(async () => {\n\tawait create()\n})()\n"
|
|
10
|
+
],
|
|
11
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAoB,IAApB;AACuD,IAAvD;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+1,38 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"dev": "npm run build -- --watch",
|
|
42
|
-
"build": "tsup src/index.ts --dts --format cjs,esm",
|
|
43
|
-
"watch": "tsup src/index.ts --dts --format cjs,esm --watch",
|
|
44
|
-
"lint": "eslint **/*.{t,j}s --fix",
|
|
45
|
-
"test": "vitest run"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
2
|
+
"name": "@by-association-only/cli",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"bin": {
|
|
11
|
+
"bao": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"type-check": "tsc --noEmit"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@clack/core": "^0.5.0",
|
|
32
|
+
"@clack/prompts": "1.0.0-alpha.6",
|
|
33
|
+
"chalk": "^5.6.2",
|
|
34
|
+
"execa": "^9.6.0",
|
|
35
|
+
"octokit": "^5.0.5",
|
|
36
|
+
"picocolors": "^1.1.1"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { create } from './commands/create'
|
|
4
|
+
|
|
5
|
+
const args = Bun.argv.slice(2)
|
|
6
|
+
const [command, subcommand] = args
|
|
7
|
+
|
|
8
|
+
if (command === 'create' && subcommand === 'app') {
|
|
9
|
+
create().catch(console.error)
|
|
10
|
+
} else {
|
|
11
|
+
console.error('Unknown command. Usage: bao create app')
|
|
12
|
+
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/index.mjs
DELETED
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
|
|
22
|
-
// src/index.ts
|
|
23
|
-
import { program } from "commander";
|
|
24
|
-
|
|
25
|
-
// package.json
|
|
26
|
-
var package_default = {
|
|
27
|
-
name: "@by-association-only/cli",
|
|
28
|
-
version: "3.3.0",
|
|
29
|
-
description: "By Association Only CLI",
|
|
30
|
-
private: false,
|
|
31
|
-
author: "BAO Agency",
|
|
32
|
-
license: "MIT",
|
|
33
|
-
main: "./dist/index.js",
|
|
34
|
-
module: "./dist/index.mjs",
|
|
35
|
-
types: "./dist/index.d.ts",
|
|
36
|
-
bin: {
|
|
37
|
-
bao: "./dist/index.mjs"
|
|
38
|
-
},
|
|
39
|
-
files: [
|
|
40
|
-
"dist"
|
|
41
|
-
],
|
|
42
|
-
exports: {
|
|
43
|
-
".": {
|
|
44
|
-
require: "./dist/index.js",
|
|
45
|
-
import: "./dist/index.mjs",
|
|
46
|
-
types: "./dist/index.d.ts"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
scripts: {
|
|
50
|
-
dev: "npm run build -- --watch",
|
|
51
|
-
build: "tsup src/index.ts --dts --format cjs,esm",
|
|
52
|
-
watch: "tsup src/index.ts --dts --format cjs,esm --watch",
|
|
53
|
-
lint: "eslint **/*.{t,j}s --fix",
|
|
54
|
-
test: "vitest run"
|
|
55
|
-
},
|
|
56
|
-
peerDependencies: {
|
|
57
|
-
vite: "^4.0.4"
|
|
58
|
-
},
|
|
59
|
-
devDependencies: {
|
|
60
|
-
"@types/inquirer": "^9.0.3",
|
|
61
|
-
tsconfig: "workspace:*",
|
|
62
|
-
"type-fest": "^3.5.1",
|
|
63
|
-
vitest: "^0.25.7"
|
|
64
|
-
},
|
|
65
|
-
dependencies: {
|
|
66
|
-
"@octokit/rest": "^19.0.7",
|
|
67
|
-
"@sindresorhus/slugify": "^2.1.1",
|
|
68
|
-
commander: "^9.5.0",
|
|
69
|
-
inquirer: "^9.1.4",
|
|
70
|
-
kleur: "^4.1.5"
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/commands/create/index.ts
|
|
75
|
-
import inquirer from "inquirer";
|
|
76
|
-
import kleur4 from "kleur";
|
|
77
|
-
|
|
78
|
-
// src/commands/config.ts
|
|
79
|
-
import * as os from "os";
|
|
80
|
-
import * as fs from "fs";
|
|
81
|
-
var config = {
|
|
82
|
-
get localProjectDirectory() {
|
|
83
|
-
if (process.env.BAO_CODE_DIRECTORY) {
|
|
84
|
-
if (fs.existsSync(process.env.BAO_CODE_DIRECTORY)) {
|
|
85
|
-
return process.env.BAO_CODE_DIRECTORY;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return `${os.homedir()}/Code`;
|
|
89
|
-
},
|
|
90
|
-
get githubToken() {
|
|
91
|
-
return process.env.GITHUB_AUTH_TOKEN;
|
|
92
|
-
},
|
|
93
|
-
get githubOrganizationName() {
|
|
94
|
-
return "baoagency";
|
|
95
|
-
},
|
|
96
|
-
get starterThemeGitUrl() {
|
|
97
|
-
return "git@github.com:baoagency/do-not-look.git";
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// src/commands/utils.ts
|
|
102
|
-
import { execSync, spawn } from "child_process";
|
|
103
|
-
import kleur from "kleur";
|
|
104
|
-
function executableIsAvailable(name) {
|
|
105
|
-
const shell = (command) => execSync(command, { encoding: "utf8" });
|
|
106
|
-
try {
|
|
107
|
-
shell(`which ${name}`);
|
|
108
|
-
return true;
|
|
109
|
-
} catch (e) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function renderStepTitle(title) {
|
|
114
|
-
console.info(`
|
|
115
|
-
${kleur.magenta().bold().underline(title)}`);
|
|
116
|
-
}
|
|
117
|
-
function renderStepSuccess(text) {
|
|
118
|
-
console.info(`
|
|
119
|
-
${kleur.green().bold(`\u2714 ${text}`)}`);
|
|
120
|
-
}
|
|
121
|
-
function renderStepError(text, error) {
|
|
122
|
-
console.info(`
|
|
123
|
-
${kleur.bgRed().underline(`\u2716 ${text}`)}`);
|
|
124
|
-
throw new Error(error || text);
|
|
125
|
-
}
|
|
126
|
-
function spawnPromise(command, ...args) {
|
|
127
|
-
return new Promise((resolve, reject) => {
|
|
128
|
-
const child = spawn(command, ...args);
|
|
129
|
-
child.on("close", (code) => resolve(code));
|
|
130
|
-
child.on("error", (err) => reject(err));
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/commands/create/local.ts
|
|
135
|
-
import * as process2 from "process";
|
|
136
|
-
import * as fs2 from "fs";
|
|
137
|
-
import kleur2 from "kleur";
|
|
138
|
-
async function checkLocalDependencies() {
|
|
139
|
-
renderStepTitle("Checking dependencies");
|
|
140
|
-
const hasGithubToken = process2.env.GITHUB_AUTH_TOKEN !== void 0;
|
|
141
|
-
const gitExists = await executableIsAvailable("git");
|
|
142
|
-
const pnpmExists = await executableIsAvailable("pnpm");
|
|
143
|
-
const codeDirectoryExists = fs2.existsSync(config.localProjectDirectory);
|
|
144
|
-
const passed = hasGithubToken && gitExists && pnpmExists && codeDirectoryExists;
|
|
145
|
-
const renderIcon = (exists) => exists ? kleur2.green("\u2714") : kleur2.red("\u2716");
|
|
146
|
-
console.info(
|
|
147
|
-
`
|
|
148
|
-
${renderIcon(hasGithubToken)} GITHUB_AUTH_TOKEN
|
|
149
|
-
${renderIcon(gitExists)} git
|
|
150
|
-
${renderIcon(pnpmExists)} pnpm
|
|
151
|
-
${renderIcon(codeDirectoryExists)} ~/Code exists`
|
|
152
|
-
);
|
|
153
|
-
if (!hasGithubToken) {
|
|
154
|
-
console.info(`
|
|
155
|
-
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.
|
|
156
|
-
|
|
157
|
-
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.
|
|
158
|
-
`);
|
|
159
|
-
}
|
|
160
|
-
passed ? renderStepSuccess("yay dependencies") : renderStepError("Dependencies failed");
|
|
161
|
-
return passed;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// src/commands/create/starter-theme/index.ts
|
|
165
|
-
import * as fs3 from "fs";
|
|
166
|
-
import { readdir, writeFile } from "fs/promises";
|
|
167
|
-
async function setupStarterTheme(config2, answers) {
|
|
168
|
-
await cloneStarterThemeRepository(config2);
|
|
169
|
-
await moveStarterThemeToProjectLocation(config2);
|
|
170
|
-
await rewriteWorkspacePackageVersions(config2);
|
|
171
|
-
await addHuskyPrepareLine(config2);
|
|
172
|
-
await gitInit(config2);
|
|
173
|
-
await pnpmInstall(config2);
|
|
174
|
-
await doInitialCommits(config2);
|
|
175
|
-
await changeShopifyStoreName(config2, answers);
|
|
176
|
-
await removeTemporaryClone(config2);
|
|
177
|
-
}
|
|
178
|
-
async function cloneStarterThemeRepository(config2) {
|
|
179
|
-
renderStepTitle("Cloning starter theme repository");
|
|
180
|
-
try {
|
|
181
|
-
await spawnPromise(
|
|
182
|
-
"git",
|
|
183
|
-
[
|
|
184
|
-
"clone",
|
|
185
|
-
config2.starterThemeGitUrl,
|
|
186
|
-
config2.temporaryCloneLocation
|
|
187
|
-
],
|
|
188
|
-
{ stdio: "inherit" }
|
|
189
|
-
);
|
|
190
|
-
renderStepSuccess("yay, starter theme");
|
|
191
|
-
} catch (e) {
|
|
192
|
-
renderStepError("Git clone failed", e);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async function moveStarterThemeToProjectLocation(config2) {
|
|
196
|
-
renderStepTitle("Extracting starter theme");
|
|
197
|
-
const themeLocation = `${config2.temporaryCloneLocation}/themes/starter-theme`;
|
|
198
|
-
try {
|
|
199
|
-
await spawnPromise(
|
|
200
|
-
"mv",
|
|
201
|
-
[themeLocation, config2.localProjectLocation]
|
|
202
|
-
);
|
|
203
|
-
renderStepSuccess(`Moved theme to ${config2.localProjectLocation}`);
|
|
204
|
-
} catch (e) {
|
|
205
|
-
renderStepError("Git clone failed", e);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
async function rewriteWorkspacePackageVersions(config2) {
|
|
209
|
-
renderStepTitle("Fixing package.json versions");
|
|
210
|
-
const packageJson = loadPackageJson(config2.localProjectLocation);
|
|
211
|
-
const rewrittenPackageJson = await rewritePackages(packageJson);
|
|
212
|
-
try {
|
|
213
|
-
await writeFile(
|
|
214
|
-
`${config2.localProjectLocation}/package.json`,
|
|
215
|
-
JSON.stringify(rewrittenPackageJson, null, 2)
|
|
216
|
-
);
|
|
217
|
-
renderStepSuccess("Updated package.json dependency versions");
|
|
218
|
-
} catch (e) {
|
|
219
|
-
renderStepError("Rewriting package.json versions failed", e);
|
|
220
|
-
}
|
|
221
|
-
async function findVersionForPackage(packageName) {
|
|
222
|
-
const packagesLocation = `${config2.temporaryCloneLocation}/packages`;
|
|
223
|
-
const folders = (await readdir(packagesLocation, { withFileTypes: true })).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
224
|
-
const foundPackage = folders.map((folder) => loadPackageJson(`${packagesLocation}/${folder}`)).find((packageJSON) => packageJSON.name === packageName);
|
|
225
|
-
if (!foundPackage)
|
|
226
|
-
return null;
|
|
227
|
-
return `^${foundPackage.version}`;
|
|
228
|
-
}
|
|
229
|
-
async function rewritePackages(packageJson2) {
|
|
230
|
-
await rewriteListOfPackages("dependencies");
|
|
231
|
-
await rewriteListOfPackages("devDependencies");
|
|
232
|
-
await rewriteListOfPackages("peerDependencies");
|
|
233
|
-
return packageJson2;
|
|
234
|
-
async function rewriteListOfPackages(key) {
|
|
235
|
-
const dependencies = packageJson2[key];
|
|
236
|
-
if (typeof dependencies === "undefined")
|
|
237
|
-
return;
|
|
238
|
-
for (const [packageName, version] of Object.entries(dependencies)) {
|
|
239
|
-
if (version !== "workspace:*")
|
|
240
|
-
continue;
|
|
241
|
-
const packageVersion = await findVersionForPackage(packageName);
|
|
242
|
-
if (!packageVersion)
|
|
243
|
-
continue;
|
|
244
|
-
dependencies[packageName] = packageVersion;
|
|
245
|
-
}
|
|
246
|
-
return packageJson2;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
async function addHuskyPrepareLine(config2) {
|
|
251
|
-
renderStepTitle("Setting up Husky");
|
|
252
|
-
const packageJson = loadPackageJson(config2.localProjectLocation);
|
|
253
|
-
packageJson.scripts.prepare = "husky install";
|
|
254
|
-
try {
|
|
255
|
-
await writeFile(
|
|
256
|
-
`${config2.localProjectLocation}/package.json`,
|
|
257
|
-
JSON.stringify(packageJson, null, 2)
|
|
258
|
-
);
|
|
259
|
-
renderStepSuccess("Added Husky prepare script");
|
|
260
|
-
} catch (e) {
|
|
261
|
-
renderStepError("Setting up Husky failed", e);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function gitInit(config2) {
|
|
265
|
-
renderStepTitle("Git in here");
|
|
266
|
-
try {
|
|
267
|
-
await spawnPromise(
|
|
268
|
-
"git",
|
|
269
|
-
[
|
|
270
|
-
"init"
|
|
271
|
-
],
|
|
272
|
-
{ stdio: "inherit", cwd: config2.localProjectLocation }
|
|
273
|
-
);
|
|
274
|
-
renderStepSuccess("Git is in here");
|
|
275
|
-
} catch (e) {
|
|
276
|
-
renderStepError("Git isn't here", e);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
async function pnpmInstall(config2) {
|
|
280
|
-
renderStepTitle("Installing dependencies");
|
|
281
|
-
try {
|
|
282
|
-
await spawnPromise(
|
|
283
|
-
"pnpm",
|
|
284
|
-
[
|
|
285
|
-
"install"
|
|
286
|
-
],
|
|
287
|
-
{ stdio: "inherit", cwd: config2.localProjectLocation }
|
|
288
|
-
);
|
|
289
|
-
renderStepSuccess("Dependencies installed");
|
|
290
|
-
} catch (e) {
|
|
291
|
-
renderStepError("Installing dependencies failed", e);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
async function doInitialCommits(config2) {
|
|
295
|
-
renderStepTitle("Performing initial commits");
|
|
296
|
-
try {
|
|
297
|
-
await spawnPromise(
|
|
298
|
-
"git",
|
|
299
|
-
["add", "."],
|
|
300
|
-
{ cwd: config2.localProjectLocation }
|
|
301
|
-
);
|
|
302
|
-
await spawnPromise(
|
|
303
|
-
"git",
|
|
304
|
-
["commit", "-m", "Initial commit"],
|
|
305
|
-
{ cwd: config2.localProjectLocation }
|
|
306
|
-
);
|
|
307
|
-
renderStepSuccess("Doned");
|
|
308
|
-
} catch (e) {
|
|
309
|
-
renderStepError("Performing initial commits failed", e);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
async function changeShopifyStoreName(config2, answers) {
|
|
313
|
-
renderStepTitle(`Changing dev store name to ${answers.shopName}`);
|
|
314
|
-
const packageJson = loadPackageJson(config2.localProjectLocation);
|
|
315
|
-
if (!packageJson.scripts) {
|
|
316
|
-
return renderStepError("package.json has no scripts key");
|
|
317
|
-
}
|
|
318
|
-
packageJson.scripts["shopify:serve"] = `shopify theme dev -s ${answers.shopName} --live-reload full-page`;
|
|
319
|
-
try {
|
|
320
|
-
await writeFile(
|
|
321
|
-
`${config2.localProjectLocation}/package.json`,
|
|
322
|
-
JSON.stringify(packageJson, null, 2)
|
|
323
|
-
);
|
|
324
|
-
renderStepSuccess("Added \u{1F44D}");
|
|
325
|
-
} catch (e) {
|
|
326
|
-
renderStepError(`Changing dev store name to ${answers.shopName} failed`, e);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
async function removeTemporaryClone(config2) {
|
|
330
|
-
renderStepTitle(`Removing ${config2.temporaryCloneLocation}`);
|
|
331
|
-
try {
|
|
332
|
-
await spawnPromise(
|
|
333
|
-
"rm",
|
|
334
|
-
[
|
|
335
|
-
"-rf",
|
|
336
|
-
config2.temporaryCloneLocation
|
|
337
|
-
],
|
|
338
|
-
{ stdio: "inherit" }
|
|
339
|
-
);
|
|
340
|
-
renderStepSuccess("All cleaned up");
|
|
341
|
-
} catch (e) {
|
|
342
|
-
renderStepError(`Removing ${config2.temporaryCloneLocation} failed`, e);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
function loadPackageJson(location) {
|
|
346
|
-
return JSON.parse(
|
|
347
|
-
fs3.readFileSync(`${location}/package.json`).toString()
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// src/commands/create/git/index.ts
|
|
352
|
-
import { Octokit } from "@octokit/rest";
|
|
353
|
-
import kleur3 from "kleur";
|
|
354
|
-
|
|
355
|
-
// src/commands/create/git/utils.ts
|
|
356
|
-
import slugify from "@sindresorhus/slugify";
|
|
357
|
-
function getRepoName(answers) {
|
|
358
|
-
return slugify(answers.projectName);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// src/commands/create/git/index.ts
|
|
362
|
-
async function setupGitHub(config2, answers) {
|
|
363
|
-
const octokit = new Octokit({
|
|
364
|
-
auth: config2.githubToken
|
|
365
|
-
});
|
|
366
|
-
renderStepTitle("Creating project on Github");
|
|
367
|
-
try {
|
|
368
|
-
const project = await createRemoteRepository();
|
|
369
|
-
kleur3.green(" \u2714 created project on Github");
|
|
370
|
-
await spawnPromise("git", ["remote", "add", "origin", project.data.ssh_url], { cwd: config2.localProjectLocation });
|
|
371
|
-
await spawnPromise("git", ["push", "-u", "origin", "master"], { cwd: config2.localProjectLocation });
|
|
372
|
-
kleur3.green(" \u2714 pushed master");
|
|
373
|
-
renderStepSuccess("Github project has been created and pushed up");
|
|
374
|
-
} catch (e) {
|
|
375
|
-
renderStepError("Github project creation failed", e);
|
|
376
|
-
}
|
|
377
|
-
function createRemoteRepository() {
|
|
378
|
-
return octokit.repos.createInOrg({
|
|
379
|
-
org: config2.githubOrganizationName,
|
|
380
|
-
name: getRepoName(answers),
|
|
381
|
-
private: true
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// src/commands/create/index.ts
|
|
387
|
-
async function createProject() {
|
|
388
|
-
const answers = await inquirer.prompt(prompts);
|
|
389
|
-
const createConfig = __spreadProps(__spreadValues({}, config), {
|
|
390
|
-
localProjectLocation: `${config.localProjectDirectory}/${answers.projectName.toLowerCase().replaceAll(" ", "-")}`,
|
|
391
|
-
temporaryCloneLocation: `/tmp/${answers.projectName.toLowerCase().replaceAll(" ", "-")}`
|
|
392
|
-
});
|
|
393
|
-
await checkLocalDependencies();
|
|
394
|
-
await setupStarterTheme(createConfig, answers);
|
|
395
|
-
await setupGitHub(createConfig, answers);
|
|
396
|
-
await finish(createConfig, answers);
|
|
397
|
-
}
|
|
398
|
-
var prompts = [
|
|
399
|
-
{
|
|
400
|
-
type: "input",
|
|
401
|
-
name: "projectName",
|
|
402
|
-
message: "Project name",
|
|
403
|
-
validate(input) {
|
|
404
|
-
return new Promise((resolve) => {
|
|
405
|
-
resolve(input.length > 0);
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
type: "input",
|
|
411
|
-
name: "shopName",
|
|
412
|
-
message: "Shopify store name",
|
|
413
|
-
validate(input) {
|
|
414
|
-
return new Promise((resolve) => {
|
|
415
|
-
resolve(input.length > 0);
|
|
416
|
-
});
|
|
417
|
-
},
|
|
418
|
-
filter(input) {
|
|
419
|
-
return input.replace(".myshopify.com", "");
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
];
|
|
423
|
-
async function finish(config2, answers) {
|
|
424
|
-
console.info(kleur4.bold().yellow("\nCongratulations! \u{1F973}\n"));
|
|
425
|
-
console.info(kleur4.cyan("Just to recap what we've just done:"));
|
|
426
|
-
console.info(kleur4.cyan(`- Cloned down the latest starter theme to ${config2.localProjectLocation}`));
|
|
427
|
-
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`));
|
|
428
|
-
console.info(kleur4.cyan(`- Created a GitHub repository at ${kleur4.magenta(`https://github.com/${config2.githubOrganizationName}/${getRepoName(
|
|
429
|
-
answers
|
|
430
|
-
)}`)}`));
|
|
431
|
-
console.info();
|
|
432
|
-
console.info(kleur4.yellow("Not bad for running just 1 command! Happy dev'ing \u270C\uFE0F\n"));
|
|
433
|
-
const otherAnswers = await inquirer.prompt([{
|
|
434
|
-
type: "confirm",
|
|
435
|
-
name: "runDev",
|
|
436
|
-
message: 'Would you like me to run "pnpm run dev" for you?'
|
|
437
|
-
}]);
|
|
438
|
-
if (otherAnswers.runDev) {
|
|
439
|
-
await spawnPromise(
|
|
440
|
-
"pnpm",
|
|
441
|
-
[
|
|
442
|
-
"run",
|
|
443
|
-
"dev"
|
|
444
|
-
],
|
|
445
|
-
{ stdio: "inherit" }
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// src/index.ts
|
|
451
|
-
program.version(package_default.version).description(package_default.description);
|
|
452
|
-
program.command("create").alias("c").description("Create a Shopify theme project").action(async () => await createProject());
|
|
453
|
-
program.parse(process.argv);
|