@shopify/create-app 3.34.0 → 3.36.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.
@@ -1,4 +1,6 @@
1
+ /// <reference types="node" />
1
2
  import Command from '@shopify/cli-kit/node/base-command';
3
+ import { URL } from 'url';
2
4
  export default class Init extends Command {
3
5
  static aliases: string[];
4
6
  static flags: {
@@ -2,12 +2,15 @@ import initPrompt, { templateURLMap } from '../prompts/init.js';
2
2
  import initService from '../services/init.js';
3
3
  import { Flags } from '@oclif/core';
4
4
  import { globalFlags } from '@shopify/cli-kit/node/cli';
5
- import { path, error, output } from '@shopify/cli-kit';
5
+ import { error, output } from '@shopify/cli-kit';
6
6
  import Command from '@shopify/cli-kit/node/base-command';
7
+ import { resolvePath } from '@shopify/cli-kit/node/path';
8
+ // eslint-disable-next-line node/prefer-global/url
9
+ import { URL } from 'url';
7
10
  export default class Init extends Command {
8
11
  async run() {
9
12
  const { flags } = await this.parse(Init);
10
- const directory = flags.path ? path.resolve(flags.path) : process.cwd();
13
+ const directory = flags.path ? resolvePath(flags.path) : process.cwd();
11
14
  this.validateTemplateValue(flags.template);
12
15
  const promptAnswers = await initPrompt({
13
16
  name: flags.name,
@@ -56,7 +59,7 @@ Init.flags = {
56
59
  path: Flags.string({
57
60
  char: 'p',
58
61
  env: 'SHOPIFY_FLAG_PATH',
59
- parse: (input, _) => Promise.resolve(path.resolve(input)),
62
+ parse: (input, _) => Promise.resolve(resolvePath(input)),
60
63
  hidden: false,
61
64
  }),
62
65
  template: Flags.string({
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAA;AAC7D,OAAO,WAAW,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,OAAO,EAAC,WAAW,EAAC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GAAG,EAAE,8BAA8B;QACnC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;QACnB,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,oBAAoB;QACzB,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI;KACb,CAAC;CACH,CAAA","sourcesContent":["import initPrompt, {templateURLMap} from '../prompts/init.js'\nimport initService from '../services/init.js'\nimport {Flags} from '@oclif/core'\nimport {globalFlags} from '@shopify/cli-kit/node/cli'\nimport {path, error, output} from '@shopify/cli-kit'\nimport Command from '@shopify/cli-kit/node/base-command'\n\nexport default class Init extends Command {\n static aliases = ['create-app']\n\n static flags = {\n ...globalFlags,\n name: Flags.string({\n char: 'n',\n env: 'SHOPIFY_FLAG_NAME',\n hidden: false,\n }),\n path: Flags.string({\n char: 'p',\n env: 'SHOPIFY_FLAG_PATH',\n parse: (input, _) => Promise.resolve(path.resolve(input)),\n hidden: false,\n }),\n template: Flags.string({\n description: `The app template. Accepts one of the following:\n - <${Object.keys(templateURLMap).join('|')}>\n - Any GitHub repo with optional branch and subpath, e.g., https://github.com/Shopify/<repository>/[subpath]#[branch]`,\n env: 'SHOPIFY_FLAG_TEMPLATE',\n }),\n 'package-manager': Flags.string({\n char: 'd',\n env: 'SHOPIFY_FLAG_PACKAGE_MANAGER',\n hidden: false,\n options: ['npm', 'yarn', 'pnpm'],\n }),\n local: Flags.boolean({\n char: 'l',\n env: 'SHOPIFY_FLAG_LOCAL',\n default: false,\n hidden: true,\n }),\n }\n\n async run(): Promise<void> {\n const {flags} = await this.parse(Init)\n const directory = flags.path ? path.resolve(flags.path) : process.cwd()\n\n this.validateTemplateValue(flags.template)\n\n const promptAnswers = await initPrompt({\n name: flags.name,\n template: flags.template,\n directory,\n })\n\n await initService({\n name: promptAnswers.name,\n packageManager: flags['package-manager'],\n template: promptAnswers.template,\n local: flags.local,\n directory,\n })\n }\n\n validateTemplateValue(template: string | undefined) {\n if (!template) {\n return\n }\n\n const url = this.parseURL(template)\n if (url && url.origin !== 'https://github.com')\n throw new error.Abort(\n 'Only GitHub repository references are supported, ' +\n 'e.g., https://github.com/Shopify/<repository>/[subpath]#[branch]',\n )\n if (!url && !Object.keys(templateURLMap).includes(template))\n throw new error.Abort(\n output.content`Only ${Object.keys(templateURLMap)\n .map((alias) => output.content`${output.token.yellow(alias)}`.value)\n .join(', ')} template aliases are supported`,\n )\n }\n\n parseURL(url: string): URL | undefined {\n try {\n return new URL(url)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n }\n}\n"]}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAA;AAC7D,OAAO,WAAW,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,kBAAkB,CAAA;AAC9C,OAAO,OAAO,MAAM,oCAAoC,CAAA;AACxD,OAAO,EAAC,WAAW,EAAC,MAAM,4BAA4B,CAAA;AACtD,kDAAkD;AAClD,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IAoCvC,KAAK,CAAC,GAAG;QACP,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACtC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAA;QAEtE,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D;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,SAAS,CAAA;SACjB;IACH,CAAC;;AAlFM,YAAO,GAAG,CAAC,YAAY,CAAC,CAAA;AAExB,UAAK,GAAG;IACb,GAAG,WAAW;IACd,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,mBAAmB;QACxB,MAAM,EAAE,KAAK;KACd,CAAC;IACF,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,mBAAmB;QACxB,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACxD,MAAM,EAAE,KAAK;KACd,CAAC;IACF,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC;QACrB,WAAW,EAAE;YACP,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;4HAC2E;QACtH,GAAG,EAAE,uBAAuB;KAC7B,CAAC;IACF,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAAC;QAC9B,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,8BAA8B;QACnC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;QACnB,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,oBAAoB;QACzB,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI;KACb,CAAC;CACH,CAAA","sourcesContent":["import initPrompt, {templateURLMap} from '../prompts/init.js'\nimport initService from '../services/init.js'\nimport {Flags} from '@oclif/core'\nimport {globalFlags} from '@shopify/cli-kit/node/cli'\nimport {error, output} from '@shopify/cli-kit'\nimport Command from '@shopify/cli-kit/node/base-command'\nimport {resolvePath} from '@shopify/cli-kit/node/path'\n// eslint-disable-next-line node/prefer-global/url\nimport {URL} from 'url'\n\nexport default class Init extends Command {\n static aliases = ['create-app']\n\n static flags = {\n ...globalFlags,\n name: Flags.string({\n char: 'n',\n env: 'SHOPIFY_FLAG_NAME',\n hidden: false,\n }),\n path: Flags.string({\n char: 'p',\n env: 'SHOPIFY_FLAG_PATH',\n parse: (input, _) => Promise.resolve(resolvePath(input)),\n hidden: false,\n }),\n template: Flags.string({\n description: `The app template. Accepts one of the following:\n - <${Object.keys(templateURLMap).join('|')}>\n - Any GitHub repo with optional branch and subpath, e.g., https://github.com/Shopify/<repository>/[subpath]#[branch]`,\n env: 'SHOPIFY_FLAG_TEMPLATE',\n }),\n 'package-manager': Flags.string({\n char: 'd',\n env: 'SHOPIFY_FLAG_PACKAGE_MANAGER',\n hidden: false,\n options: ['npm', 'yarn', 'pnpm'],\n }),\n local: Flags.boolean({\n char: 'l',\n env: 'SHOPIFY_FLAG_LOCAL',\n default: false,\n hidden: true,\n }),\n }\n\n async run(): Promise<void> {\n const {flags} = await this.parse(Init)\n const directory = flags.path ? resolvePath(flags.path) : process.cwd()\n\n this.validateTemplateValue(flags.template)\n\n const promptAnswers = await initPrompt({\n name: flags.name,\n template: flags.template,\n directory,\n })\n\n await initService({\n name: promptAnswers.name,\n packageManager: flags['package-manager'],\n template: promptAnswers.template,\n local: flags.local,\n directory,\n })\n }\n\n validateTemplateValue(template: string | undefined) {\n if (!template) {\n return\n }\n\n const url = this.parseURL(template)\n if (url && url.origin !== 'https://github.com')\n throw new error.Abort(\n 'Only GitHub repository references are supported, ' +\n 'e.g., https://github.com/Shopify/<repository>/[subpath]#[branch]',\n )\n if (!url && !Object.keys(templateURLMap).includes(template))\n throw new error.Abort(\n output.content`Only ${Object.keys(templateURLMap)\n .map((alias) => output.content`${output.token.yellow(alias)}`.value)\n .join(', ')} template aliases are supported`,\n )\n }\n\n parseURL(url: string): URL | undefined {\n try {\n return new URL(url)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n }\n}\n"]}
@@ -17,7 +17,7 @@ const init = async (options, prompt = ui.prompt) => {
17
17
  questions.push({
18
18
  type: 'input',
19
19
  name: 'name',
20
- preface: '\nWelcome. Let’s get started by naming your app. You can change it later.',
20
+ preface: '\nWelcome. Let’s get started by naming your app. You can change it later.\n',
21
21
  message: "Your app's name?",
22
22
  default: defaults.name,
23
23
  validate: (value) => {
@@ -27,6 +27,9 @@ const init = async (options, prompt = ui.prompt) => {
27
27
  if (value.length > 30) {
28
28
  return 'Enter a shorter name (30 character max.)';
29
29
  }
30
+ if (value.toLowerCase().includes('shopify')) {
31
+ return "App Name can't include the word 'shopify'";
32
+ }
30
33
  return true;
31
34
  },
32
35
  });
@@ -43,7 +46,7 @@ const init = async (options, prompt = ui.prompt) => {
43
46
  name: 'template',
44
47
  choices: templateList,
45
48
  message: 'Which template would you like to use?',
46
- default: defaults.template,
49
+ default: Object.keys(templateURLMap).find((key) => templateURLMap[key] === defaults.template),
47
50
  });
48
51
  }
49
52
  const promptOutput = await prompt(questions);
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/prompts/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,EAAE,EAAC,MAAM,kBAAkB,CAAA;AACnC,OAAO,EAAC,iCAAiC,EAAC,MAAM,0BAA0B,CAAA;AAa1E,8DAA8D;AAC9D,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,sDAAsD;IAC5D,GAAG,EAAE,qDAAqD;IAC1D,IAAI,EAAE,sDAAsD;CACpD,CAAA;AAEV,MAAM,IAAI,GAAG,KAAK,EAAE,OAAoB,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM,EAAuB,EAAE;IACnF,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,MAAM,iCAAiC,CAAC,EAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAC,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AO,CAAC,QAAuC,CAAC,CAAA;IACnF,OAAO,CAAC,QAAQ,GAAG,WAAW,IAAI,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAA;IAEvE,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,eAAe,IAAI,CAAA","sourcesContent":["import {ui} from '@shopify/cli-kit'\nimport {generateRandomNameForSubdirectory} from '@shopify/cli-kit/node/fs'\n\ninterface InitOptions {\n name?: string\n template?: string\n directory: string\n}\n\ninterface InitOutput {\n name: string\n template: string\n}\n\n// Eventually this list should be taken from a remote location\n// That way we don't have to update the CLI every time we add a template\nexport const templateURLMap = {\n node: 'https://github.com/Shopify/shopify-app-template-node',\n php: 'https://github.com/Shopify/shopify-app-template-php',\n ruby: 'https://github.com/Shopify/shopify-app-template-ruby',\n} as const\n\nconst init = async (options: InitOptions, prompt = ui.prompt): Promise<InitOutput> => {\n const defaults = {\n name: await generateRandomNameForSubdirectory({suffix: 'app', directory: options.directory}),\n template: templateURLMap.node,\n } as const\n\n const questions: ui.Question<'name' | 'template'>[] = []\n if (!options.name) {\n questions.push({\n type: 'input',\n name: 'name',\n preface: '\\nWelcome. Let’s get started by naming your app. You can change it later.',\n message: \"Your app's name?\",\n default: defaults.name,\n validate: (value) => {\n if (value.length === 0) {\n return \"App Name can't be empty\"\n }\n if (value.length > 30) {\n return 'Enter a shorter name (30 character max.)'\n }\n return true\n },\n })\n }\n\n if (!options.template && Object.keys(templateURLMap).length > 1) {\n const templateList = Object.keys(templateURLMap).map((key) => {\n return {\n name: key,\n value: key,\n }\n })\n questions.push({\n type: 'select',\n name: 'template',\n choices: templateList,\n message: 'Which template would you like to use?',\n default: defaults.template,\n })\n }\n\n const promptOutput: InitOutput = await prompt(questions)\n const answers = {\n ...options,\n ...promptOutput,\n }\n\n const templateURL = templateURLMap[answers.template as keyof typeof templateURLMap]\n answers.template = templateURL || answers.template || defaults.template\n\n return answers\n}\n\nexport default init\n"]}
1
+ {"version":3,"file":"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C,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/D,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC3D,OAAO;gBACL,IAAI,EAAE,GAAG;gBACT,KAAK,EAAE,GAAG;aACX,CAAA;QACH,CAAC,CAAC,CAAA;QACF,SAAS,CAAC,IAAI,CAAC;YACb,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,YAAY;YACrB,OAAO,EAAE,uCAAuC;YAChD,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CACvC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAA8B,CAAC,KAAK,QAAQ,CAAC,QAAQ,CAC9E;SACF,CAAC,CAAA;KACH;IAED,MAAM,YAAY,GAAe,MAAM,MAAM,CAAC,SAAS,CAAC,CAAA;IACxD,MAAM,OAAO,GAAG;QACd,GAAG,OAAO;QACV,GAAG,YAAY;KAChB,CAAA;IAED,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,QAAuC,CAAC,CAAA;IACnF,OAAO,CAAC,QAAQ,GAAG,WAAW,IAAI,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAA;IAEvE,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,eAAe,IAAI,CAAA","sourcesContent":["import {ui} from '@shopify/cli-kit'\nimport {generateRandomNameForSubdirectory} from '@shopify/cli-kit/node/fs'\n\ninterface InitOptions {\n name?: string\n template?: string\n directory: string\n}\n\ninterface InitOutput {\n name: string\n template: string\n}\n\n// Eventually this list should be taken from a remote location\n// That way we don't have to update the CLI every time we add a template\nexport const templateURLMap = {\n node: 'https://github.com/Shopify/shopify-app-template-node',\n php: 'https://github.com/Shopify/shopify-app-template-php',\n ruby: 'https://github.com/Shopify/shopify-app-template-ruby',\n} as const\n\nconst init = async (options: InitOptions, prompt = ui.prompt): Promise<InitOutput> => {\n const defaults = {\n name: await generateRandomNameForSubdirectory({suffix: 'app', directory: options.directory}),\n template: templateURLMap.node,\n } as const\n\n const questions: ui.Question<'name' | 'template'>[] = []\n if (!options.name) {\n questions.push({\n type: 'input',\n name: 'name',\n preface: '\\nWelcome. Let’s get started by naming your app. You can change it later.\\n',\n message: \"Your app's name?\",\n default: defaults.name,\n validate: (value) => {\n if (value.length === 0) {\n return \"App Name can't be empty\"\n }\n if (value.length > 30) {\n return 'Enter a shorter name (30 character max.)'\n }\n if (value.toLowerCase().includes('shopify')) {\n return \"App Name can't include the word 'shopify'\"\n }\n return true\n },\n })\n }\n\n if (!options.template && Object.keys(templateURLMap).length > 1) {\n const templateList = Object.keys(templateURLMap).map((key) => {\n return {\n name: key,\n value: key,\n }\n })\n questions.push({\n type: 'select',\n name: 'template',\n choices: templateList,\n message: 'Which template would you like to use?',\n default: Object.keys(templateURLMap).find(\n (key) => templateURLMap[key as 'node' | 'php' | 'ruby'] === defaults.template,\n ),\n })\n }\n\n const promptOutput: InitOutput = await prompt(questions)\n const answers = {\n ...options,\n ...promptOutput,\n }\n\n const templateURL = templateURLMap[answers.template as keyof typeof templateURLMap]\n answers.template = templateURL || answers.template || defaults.template\n\n return answers\n}\n\nexport default init\n"]}
@@ -1,126 +1,94 @@
1
1
  import { getDeepInstallNPMTasks, updateCLIDependencies } from '../utils/template/npm.js';
2
2
  import cleanup from '../utils/template/cleanup.js';
3
- import { path, file, ui, npm, git, error, output } from '@shopify/cli-kit';
4
- import { packageManager, packageManagerUsedForCreating } from '@shopify/cli-kit/node/node-package-manager';
5
- import { renderSuccess } from '@shopify/cli-kit/node/ui';
3
+ import { error, output } from '@shopify/cli-kit';
4
+ import { findUpAndReadPackageJson, packageManager, packageManagerUsedForCreating, writePackageJSON, } from '@shopify/cli-kit/node/node-package-manager';
5
+ import { renderSuccess, renderTasks } from '@shopify/cli-kit/node/ui';
6
6
  import { parseGitHubRepositoryReference } from '@shopify/cli-kit/node/github';
7
7
  import { hyphenate } from '@shopify/cli-kit/common/string';
8
8
  import { recursiveLiquidTemplateCopy } from '@shopify/cli-kit/node/liquid';
9
- import { isShopify, isUnitTest } from '@shopify/cli-kit/node/environment/local';
9
+ import { isShopify } from '@shopify/cli-kit/node/environment/local';
10
+ import { downloadGitRepository, initializeGitRepository } from '@shopify/cli-kit/node/git';
11
+ import { appendFile, fileExists, inTemporaryDirectory, mkdir, moveFile } from '@shopify/cli-kit/node/fs';
12
+ import { joinPath } from '@shopify/cli-kit/node/path';
13
+ import { username } from '@shopify/cli-kit/node/os';
10
14
  async function init(options) {
11
15
  const packageManager = inferPackageManager(options.packageManager);
12
16
  const hyphenizedName = hyphenate(options.name);
13
- const outputDirectory = path.join(options.directory, hyphenizedName);
17
+ const outputDirectory = joinPath(options.directory, hyphenizedName);
14
18
  const githubRepo = parseGitHubRepositoryReference(options.template);
15
19
  await ensureAppDirectoryIsAvailable(outputDirectory, hyphenizedName);
16
- await file.inTemporaryDirectory(async (tmpDir) => {
17
- const templateDownloadDir = path.join(tmpDir, 'download');
20
+ await inTemporaryDirectory(async (tmpDir) => {
21
+ const templateDownloadDir = joinPath(tmpDir, 'download');
18
22
  const templatePathDir = githubRepo.filePath
19
- ? path.join(templateDownloadDir, githubRepo.filePath)
23
+ ? joinPath(templateDownloadDir, githubRepo.filePath)
20
24
  : templateDownloadDir;
21
- const templateScaffoldDir = path.join(tmpDir, 'app');
25
+ const templateScaffoldDir = joinPath(tmpDir, 'app');
22
26
  const repoUrl = githubRepo.branch ? `${githubRepo.baseURL}#${githubRepo.branch}` : githubRepo.baseURL;
23
- await file.mkdir(templateDownloadDir);
24
- let tasks = [];
25
- await ui.task({
26
- title: `Downloading template from ${repoUrl}`,
27
+ await mkdir(templateDownloadDir);
28
+ const tasks = [
29
+ {
30
+ title: `Downloading template from ${repoUrl}`,
31
+ task: async () => {
32
+ await downloadGitRepository({
33
+ repoUrl,
34
+ destination: templateDownloadDir,
35
+ shallow: true,
36
+ });
37
+ },
38
+ },
39
+ ];
40
+ tasks.push({
41
+ title: 'Parsing liquid',
27
42
  task: async () => {
28
- await git.downloadRepository({
29
- repoUrl,
30
- destination: templateDownloadDir,
31
- shallow: true,
43
+ await recursiveLiquidTemplateCopy(templatePathDir, templateScaffoldDir, {
44
+ dependency_manager: packageManager,
45
+ app_name: options.name,
32
46
  });
33
- return { successMessage: `Downloaded template from ${repoUrl}` };
34
47
  },
35
- });
36
- tasks = tasks.concat([
37
- {
38
- title: `Initialize your app ${hyphenizedName}`,
39
- task: async (_, parentTask) => {
40
- parentTask.title = `Initializing your app ${hyphenizedName}`;
41
- return parentTask.newListr([
42
- {
43
- title: 'Parse liquid',
44
- task: async (_, task) => {
45
- task.title = 'Parsing liquid';
46
- await recursiveLiquidTemplateCopy(templatePathDir, templateScaffoldDir, {
47
- dependency_manager: packageManager,
48
- app_name: options.name,
49
- });
50
- task.title = 'Liquid parsed';
51
- },
52
- },
53
- {
54
- title: 'Update package.json',
55
- task: async (_, task) => {
56
- task.title = 'Updating package.json';
57
- const packageJSON = await npm.readPackageJSON(templateScaffoldDir);
58
- await npm.updateAppData(packageJSON, hyphenizedName);
59
- await updateCLIDependencies({ packageJSON, local: options.local, directory: templateScaffoldDir });
60
- await npm.writePackageJSON(templateScaffoldDir, packageJSON);
61
- // Ensure that the installation of dependencies doesn't fail when using
62
- // pnpm due to missing peerDependencies.
63
- if (packageManager === 'pnpm') {
64
- await file.append(path.join(templateScaffoldDir, '.npmrc'), `auto-install-peers=true\n`);
65
- }
66
- task.title = 'Updated package.json';
67
- parentTask.title = 'App initialized';
68
- },
69
- },
70
- ]);
71
- },
48
+ }, {
49
+ title: 'Updating package.json',
50
+ task: async () => {
51
+ const packageJSON = (await findUpAndReadPackageJson(templateScaffoldDir)).content;
52
+ packageJSON.name = hyphenizedName;
53
+ packageJSON.author = (await username()) ?? '';
54
+ await updateCLIDependencies({ packageJSON, local: options.local, directory: templateScaffoldDir });
55
+ await writePackageJSON(templateScaffoldDir, packageJSON);
56
+ // Ensure that the installation of dependencies doesn't fail when using
57
+ // pnpm due to missing peerDependencies.
58
+ if (packageManager === 'pnpm') {
59
+ await appendFile(joinPath(templateScaffoldDir, '.npmrc'), `auto-install-peers=true\n`);
60
+ }
72
61
  },
73
- ]);
62
+ });
74
63
  if (await isShopify()) {
75
64
  tasks.push({
76
- title: "[Shopifolks-only] Configure the project's NPM registry",
77
- task: async (_, task) => {
78
- task.title = "[Shopifolks-only] Configuring the project's NPM registry";
79
- const npmrcPath = path.join(templateScaffoldDir, '.npmrc');
65
+ title: "[Shopifolks-only] Configuring the project's NPM registry",
66
+ task: async () => {
67
+ const npmrcPath = joinPath(templateScaffoldDir, '.npmrc');
80
68
  const npmrcContent = `@shopify:registry=https://registry.npmjs.org\n`;
81
- await file.append(npmrcPath, npmrcContent);
82
- task.title = "[Shopifolks-only] Project's NPM registry configured.";
69
+ await appendFile(npmrcPath, npmrcContent);
83
70
  },
84
71
  });
85
72
  }
86
- tasks = tasks.concat([
87
- {
88
- title: `Install dependencies with ${packageManager}`,
89
- task: async (_, parentTask) => {
90
- parentTask.title = `Installing dependencies with ${packageManager}`;
91
- function didInstallEverything() {
92
- parentTask.title = `Dependencies installed with ${packageManager}`;
93
- }
94
- return parentTask.newListr(await getDeepInstallNPMTasks({
95
- from: templateScaffoldDir,
96
- packageManager,
97
- didInstallEverything,
98
- }), { concurrent: false });
99
- },
73
+ tasks.push({
74
+ title: 'Installing dependencies',
75
+ task: async () => {
76
+ const subtasks = await getDeepInstallNPMTasks({ from: templateScaffoldDir, packageManager });
77
+ return subtasks;
100
78
  },
101
- {
102
- title: 'Clean up',
103
- task: async (_, task) => {
104
- task.title = 'Cleaning up';
105
- await cleanup(templateScaffoldDir);
106
- task.title = 'Completed clean up';
107
- },
79
+ }, {
80
+ title: 'Cleaning up',
81
+ task: async () => {
82
+ await cleanup(templateScaffoldDir);
108
83
  },
109
- {
110
- title: 'Initializing a Git repository...',
111
- task: async (_, task) => {
112
- await git.initializeRepository(templateScaffoldDir);
113
- task.title = 'Git repository initialized';
114
- },
84
+ }, {
85
+ title: 'Initializing a Git repository...',
86
+ task: async () => {
87
+ await initializeGitRepository(templateScaffoldDir);
115
88
  },
116
- ]);
117
- const list = ui.newListr(tasks, {
118
- concurrent: false,
119
- rendererOptions: { collapse: false },
120
- rendererSilent: isUnitTest(),
121
89
  });
122
- await list.run();
123
- await file.move(templateScaffoldDir, outputDirectory);
90
+ await renderTasks(tasks);
91
+ await moveFile(templateScaffoldDir, outputDirectory);
124
92
  });
125
93
  renderSuccess({
126
94
  headline: [{ userInput: hyphenizedName }, 'is ready for you to build!'],
@@ -146,7 +114,7 @@ function inferPackageManager(optionsPackageManager) {
146
114
  return usedPackageManager === 'unknown' ? 'npm' : usedPackageManager;
147
115
  }
148
116
  async function ensureAppDirectoryIsAvailable(directory, name) {
149
- const exists = await file.exists(directory);
117
+ const exists = await fileExists(directory);
150
118
  if (exists)
151
119
  throw new error.Abort(`\nA directory with this name (${name}) already exists.\nChoose a new name for your app.`);
152
120
  }
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/services/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAE,qBAAqB,EAAC,MAAM,0BAA0B,CAAA;AACtF,OAAO,OAAO,MAAM,8BAA8B,CAAA;AAElD,OAAO,EAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAC,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAC,cAAc,EAAkB,6BAA6B,EAAC,MAAM,4CAA4C,CAAA;AACxH,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAC,8BAA8B,EAAC,MAAM,8BAA8B,CAAA;AAC3E,OAAO,EAAC,SAAS,EA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,2BAA2B,CAAC,cAAc,EAAE,oBAAoB,CAAC,EAAC,CAAC;YAC5G,CAAC,sBAAsB,EAAE,EAAC,OAAO,EAAE,MAAM,CAAC,2BAA2B,CAAC,cAAc,EAAE,KAAK,CAAC,EAAC,CAAC;SAC/F;QACD,SAAS,EAAE;YACT,EAAC,IAAI,EAAE,EAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,EAAC,EAAC;YAC3D;gBACE,kCAAkC;gBAClC,EAAC,OAAO,EAAE,GAAG,MAAM,CAAC,2BAA2B,CAAC,cAAc,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,EAAC;aAC5F;SACF;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,qBAAyC;IACpE,IAAI,qBAAqB,IAAI,cAAc,CAAC,QAAQ,CAAC,qBAAuC,CAAC,EAAE;QAC7F,OAAO,qBAAuC,CAAA;KAC/C;IACD,MAAM,kBAAkB,GAAG,6BAA6B,EAAE,CAAA;IAC1D,OAAO,kBAAkB,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAA;AACtE,CAAC;AAED,KAAK,UAAU,6BAA6B,CAAC,SAAiB,EAAE,IAAY;IAC1E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC3C,IAAI,MAAM;QACR,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,iCAAiC,IAAI,oDAAoD,CAAC,CAAA;AACpH,CAAC;AAED,eAAe,IAAI,CAAA","sourcesContent":["import {getDeepInstallNPMTasks, updateCLIDependencies} from '../utils/template/npm.js'\nimport cleanup from '../utils/template/cleanup.js'\n\nimport {path, file, ui, npm, git, error, output} from '@shopify/cli-kit'\nimport {packageManager, PackageManager, packageManagerUsedForCreating} from '@shopify/cli-kit/node/node-package-manager'\nimport {renderSuccess} from '@shopify/cli-kit/node/ui'\nimport {parseGitHubRepositoryReference} from '@shopify/cli-kit/node/github'\nimport {hyphenate} from '@shopify/cli-kit/common/string'\nimport {recursiveLiquidTemplateCopy} from '@shopify/cli-kit/node/liquid'\nimport {isShopify, isUnitTest} from '@shopify/cli-kit/node/environment/local'\n\ninterface InitOptions {\n name: string\n directory: string\n template: string\n packageManager: string | undefined\n local: boolean\n}\n\nasync function init(options: InitOptions) {\n const packageManager: PackageManager = inferPackageManager(options.packageManager)\n const hyphenizedName = hyphenate(options.name)\n const outputDirectory = path.join(options.directory, hyphenizedName)\n const githubRepo = parseGitHubRepositoryReference(options.template)\n\n await ensureAppDirectoryIsAvailable(outputDirectory, hyphenizedName)\n\n await file.inTemporaryDirectory(async (tmpDir) => {\n const templateDownloadDir = path.join(tmpDir, 'download')\n const templatePathDir = githubRepo.filePath\n ? path.join(templateDownloadDir, githubRepo.filePath)\n : templateDownloadDir\n const templateScaffoldDir = path.join(tmpDir, 'app')\n const repoUrl = githubRepo.branch ? `${githubRepo.baseURL}#${githubRepo.branch}` : githubRepo.baseURL\n\n await file.mkdir(templateDownloadDir)\n let tasks: ui.ListrTasks = []\n\n await ui.task({\n title: `Downloading template from ${repoUrl}`,\n task: async () => {\n await git.downloadRepository({\n repoUrl,\n destination: templateDownloadDir,\n shallow: true,\n })\n return {successMessage: `Downloaded template from ${repoUrl}`}\n },\n })\n\n tasks = tasks.concat([\n {\n title: `Initialize your app ${hyphenizedName}`,\n task: async (_, parentTask) => {\n parentTask.title = `Initializing your app ${hyphenizedName}`\n return parentTask.newListr([\n {\n title: 'Parse liquid',\n task: async (_, task) => {\n task.title = 'Parsing liquid'\n await recursiveLiquidTemplateCopy(templatePathDir, templateScaffoldDir, {\n dependency_manager: packageManager,\n app_name: options.name,\n })\n\n task.title = 'Liquid parsed'\n },\n },\n {\n title: 'Update package.json',\n task: async (_, task) => {\n task.title = 'Updating package.json'\n const packageJSON = await npm.readPackageJSON(templateScaffoldDir)\n\n await npm.updateAppData(packageJSON, hyphenizedName)\n await updateCLIDependencies({packageJSON, local: options.local, directory: templateScaffoldDir})\n\n await npm.writePackageJSON(templateScaffoldDir, packageJSON)\n\n // Ensure that the installation of dependencies doesn't fail when using\n // pnpm due to missing peerDependencies.\n if (packageManager === 'pnpm') {\n await file.append(path.join(templateScaffoldDir, '.npmrc'), `auto-install-peers=true\\n`)\n }\n\n task.title = 'Updated package.json'\n parentTask.title = 'App initialized'\n },\n },\n ])\n },\n },\n ])\n\n if (await isShopify()) {\n tasks.push({\n title: \"[Shopifolks-only] Configure the project's NPM registry\",\n task: async (_, task) => {\n task.title = \"[Shopifolks-only] Configuring the project's NPM registry\"\n const npmrcPath = path.join(templateScaffoldDir, '.npmrc')\n const npmrcContent = `@shopify:registry=https://registry.npmjs.org\\n`\n await file.append(npmrcPath, npmrcContent)\n task.title = \"[Shopifolks-only] Project's NPM registry configured.\"\n },\n })\n }\n\n tasks = tasks.concat([\n {\n title: `Install dependencies with ${packageManager}`,\n task: async (_, parentTask) => {\n parentTask.title = `Installing dependencies with ${packageManager}`\n function didInstallEverything() {\n parentTask.title = `Dependencies installed with ${packageManager}`\n }\n\n return parentTask.newListr(\n await getDeepInstallNPMTasks({\n from: templateScaffoldDir,\n packageManager,\n didInstallEverything,\n }),\n {concurrent: false},\n )\n },\n },\n {\n title: 'Clean up',\n task: async (_, task) => {\n task.title = 'Cleaning up'\n await cleanup(templateScaffoldDir)\n task.title = 'Completed clean up'\n },\n },\n {\n title: 'Initializing a Git repository...',\n task: async (_, task) => {\n await git.initializeRepository(templateScaffoldDir)\n task.title = 'Git repository initialized'\n },\n },\n ])\n\n const list = ui.newListr(tasks, {\n concurrent: false,\n rendererOptions: {collapse: false},\n rendererSilent: isUnitTest(),\n })\n await list.run()\n\n await file.move(templateScaffoldDir, outputDirectory)\n })\n\n renderSuccess({\n headline: [{userInput: hyphenizedName}, 'is ready for you to build!'],\n nextSteps: [\n ['Run', {command: `cd ${hyphenizedName}`}],\n ['For extensions, run', {command: output.formatPackageManagerCommand(packageManager, 'generate extension')}],\n ['To see your app, run', {command: output.formatPackageManagerCommand(packageManager, 'dev')}],\n ],\n reference: [\n {link: {label: 'Shopify docs', url: 'https://shopify.dev'}},\n [\n 'For an overview of commands, run',\n {command: `${output.formatPackageManagerCommand(packageManager, 'shopify app', '--help')}`},\n ],\n ],\n })\n}\n\nfunction inferPackageManager(optionsPackageManager: string | undefined): PackageManager {\n if (optionsPackageManager && packageManager.includes(optionsPackageManager as PackageManager)) {\n return optionsPackageManager as PackageManager\n }\n const usedPackageManager = packageManagerUsedForCreating()\n return usedPackageManager === 'unknown' ? 'npm' : usedPackageManager\n}\n\nasync function ensureAppDirectoryIsAvailable(directory: string, name: string): Promise<void> {\n const exists = await file.exists(directory)\n if (exists)\n throw new error.Abort(`\\nA directory with this name (${name}) already exists.\\nChoose a new name for your app.`)\n}\n\nexport default init\n"]}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/services/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAE,qBAAqB,EAAC,MAAM,0BAA0B,CAAA;AACtF,OAAO,OAAO,MAAM,8BAA8B,CAAA;AAElD,OAAO,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EACL,wBAAwB,EACxB,cAAc,EAEd,6BAA6B,EAC7B,gBAAgB,GACjB,MAAM,4CAA4C,CAAA;AACnD,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAC,8BAA8B,EAAC,MAAM,8BAA8B,CAAA;AAC3E,OAAO,EAAC,SAAS,EAAC,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAC,2BAA2B,EAAC,MAAM,8BAA8B,CAAA;AAExE,OAAO,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAA;AACjE,OAAO,EAAC,qBAAqB,EAAE,uBAAuB,EAAC,MAAM,2BAA2B,CAAA;AACxF,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,oBAAoB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C,EAAC;YAC3D;gBACE,kCAAkC;gBAClC,EAAC,OAAO,EAAE,GAAG,MAAM,CAAC,2BAA2B,CAAC,cAAc,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,EAAC;aAC5F;SACF;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,qBAAyC;IACpE,IAAI,qBAAqB,IAAI,cAAc,CAAC,QAAQ,CAAC,qBAAuC,CAAC,EAAE;QAC7F,OAAO,qBAAuC,CAAA;KAC/C;IACD,MAAM,kBAAkB,GAAG,6BAA6B,EAAE,CAAA;IAC1D,OAAO,kBAAkB,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAA;AACtE,CAAC;AAED,KAAK,UAAU,6BAA6B,CAAC,SAAiB,EAAE,IAAY;IAC1E,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAA;IAC1C,IAAI,MAAM;QACR,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,iCAAiC,IAAI,oDAAoD,CAAC,CAAA;AACpH,CAAC;AAED,eAAe,IAAI,CAAA","sourcesContent":["import {getDeepInstallNPMTasks, updateCLIDependencies} from '../utils/template/npm.js'\nimport cleanup from '../utils/template/cleanup.js'\n\nimport {error, output} from '@shopify/cli-kit'\nimport {\n findUpAndReadPackageJson,\n packageManager,\n PackageManager,\n packageManagerUsedForCreating,\n writePackageJSON,\n} from '@shopify/cli-kit/node/node-package-manager'\nimport {renderSuccess, renderTasks} from '@shopify/cli-kit/node/ui'\nimport {parseGitHubRepositoryReference} from '@shopify/cli-kit/node/github'\nimport {hyphenate} from '@shopify/cli-kit/common/string'\nimport {recursiveLiquidTemplateCopy} from '@shopify/cli-kit/node/liquid'\nimport {Task} from '@shopify/cli-kit/src/private/node/ui/components/Tasks.js'\nimport {isShopify} from '@shopify/cli-kit/node/environment/local'\nimport {downloadGitRepository, initializeGitRepository} from '@shopify/cli-kit/node/git'\nimport {appendFile, fileExists, inTemporaryDirectory, mkdir, moveFile} from '@shopify/cli-kit/node/fs'\nimport {joinPath} from '@shopify/cli-kit/node/path'\nimport {username} from '@shopify/cli-kit/node/os'\n\ninterface InitOptions {\n name: string\n directory: string\n template: string\n packageManager: string | undefined\n local: boolean\n}\n\nasync function init(options: InitOptions) {\n const packageManager: PackageManager = inferPackageManager(options.packageManager)\n const hyphenizedName = hyphenate(options.name)\n const outputDirectory = joinPath(options.directory, hyphenizedName)\n const githubRepo = parseGitHubRepositoryReference(options.template)\n\n await ensureAppDirectoryIsAvailable(outputDirectory, hyphenizedName)\n\n await inTemporaryDirectory(async (tmpDir) => {\n const templateDownloadDir = joinPath(tmpDir, 'download')\n const templatePathDir = githubRepo.filePath\n ? joinPath(templateDownloadDir, githubRepo.filePath)\n : templateDownloadDir\n const templateScaffoldDir = joinPath(tmpDir, 'app')\n const repoUrl = githubRepo.branch ? `${githubRepo.baseURL}#${githubRepo.branch}` : githubRepo.baseURL\n\n await mkdir(templateDownloadDir)\n const tasks: Task<unknown>[] = [\n {\n title: `Downloading template from ${repoUrl}`,\n task: async () => {\n await downloadGitRepository({\n repoUrl,\n destination: templateDownloadDir,\n shallow: true,\n })\n },\n },\n ]\n\n tasks.push(\n {\n title: 'Parsing liquid',\n task: async () => {\n await recursiveLiquidTemplateCopy(templatePathDir, templateScaffoldDir, {\n dependency_manager: packageManager,\n app_name: options.name,\n })\n },\n },\n {\n title: 'Updating package.json',\n task: async () => {\n const packageJSON = (await findUpAndReadPackageJson(templateScaffoldDir)).content\n packageJSON.name = hyphenizedName\n packageJSON.author = (await username()) ?? ''\n await updateCLIDependencies({packageJSON, local: options.local, directory: templateScaffoldDir})\n\n await writePackageJSON(templateScaffoldDir, packageJSON)\n\n // Ensure that the installation of dependencies doesn't fail when using\n // pnpm due to missing peerDependencies.\n if (packageManager === 'pnpm') {\n await appendFile(joinPath(templateScaffoldDir, '.npmrc'), `auto-install-peers=true\\n`)\n }\n },\n },\n )\n\n if (await isShopify()) {\n tasks.push({\n title: \"[Shopifolks-only] Configuring the project's NPM registry\",\n task: async () => {\n const npmrcPath = joinPath(templateScaffoldDir, '.npmrc')\n const npmrcContent = `@shopify:registry=https://registry.npmjs.org\\n`\n await appendFile(npmrcPath, npmrcContent)\n },\n })\n }\n\n tasks.push(\n {\n title: 'Installing dependencies',\n task: async () => {\n const subtasks = await getDeepInstallNPMTasks({from: templateScaffoldDir, packageManager})\n return subtasks\n },\n },\n {\n title: 'Cleaning up',\n task: async () => {\n await cleanup(templateScaffoldDir)\n },\n },\n {\n title: 'Initializing a Git repository...',\n task: async () => {\n await initializeGitRepository(templateScaffoldDir)\n },\n },\n )\n\n await renderTasks(tasks)\n\n await moveFile(templateScaffoldDir, outputDirectory)\n })\n\n renderSuccess({\n headline: [{userInput: hyphenizedName}, 'is ready for you to build!'],\n nextSteps: [\n ['Run', {command: `cd ${hyphenizedName}`}],\n ['For extensions, run', {command: output.formatPackageManagerCommand(packageManager, 'generate extension')}],\n ['To see your app, run', {command: output.formatPackageManagerCommand(packageManager, 'dev')}],\n ],\n reference: [\n {link: {label: 'Shopify docs', url: 'https://shopify.dev'}},\n [\n 'For an overview of commands, run',\n {command: `${output.formatPackageManagerCommand(packageManager, 'shopify app', '--help')}`},\n ],\n ],\n })\n}\n\nfunction inferPackageManager(optionsPackageManager: string | undefined): PackageManager {\n if (optionsPackageManager && packageManager.includes(optionsPackageManager as PackageManager)) {\n return optionsPackageManager as PackageManager\n }\n const usedPackageManager = packageManagerUsedForCreating()\n return usedPackageManager === 'unknown' ? 'npm' : usedPackageManager\n}\n\nasync function ensureAppDirectoryIsAvailable(directory: string, name: string): Promise<void> {\n const exists = await fileExists(directory)\n if (exists)\n throw new error.Abort(`\\nA directory with this name (${name}) already exists.\\nChoose a new name for your app.`)\n}\n\nexport default init\n"]}