create-expo-module 0.4.0 → 0.5.1

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.
@@ -11,9 +11,9 @@ const ejs_1 = __importDefault(require("ejs"));
11
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
12
12
  const path_1 = __importDefault(require("path"));
13
13
  const prompts_1 = __importDefault(require("prompts"));
14
- const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
15
14
  const createExampleApp_1 = require("./createExampleApp");
16
15
  const packageManager_1 = require("./packageManager");
16
+ const prompts_2 = require("./prompts");
17
17
  const resolvePackageManager_1 = require("./resolvePackageManager");
18
18
  const utils_1 = require("./utils");
19
19
  const packageJson = require('../package.json');
@@ -29,11 +29,14 @@ const IGNORES_PATHS = ['.DS_Store', 'build', 'node_modules', 'package.json'];
29
29
  * @param command An object from `commander`.
30
30
  */
31
31
  async function main(target, options) {
32
- const targetDir = target ? path_1.default.join(CWD, target) : CWD;
32
+ const slug = await askForPackageSlugAsync(target);
33
+ const targetDir = path_1.default.join(CWD, target || slug);
33
34
  await fs_extra_1.default.ensureDir(targetDir);
34
35
  await confirmTargetDirAsync(targetDir);
35
36
  options.target = targetDir;
36
- const data = await askForSubstitutionDataAsync(targetDir, options);
37
+ const data = await askForSubstitutionDataAsync(slug);
38
+ // Make one line break between prompts and progress logs
39
+ console.log();
37
40
  const packageManager = await (0, resolvePackageManager_1.resolvePackageManager)();
38
41
  const packagePath = options.source
39
42
  ? path_1.default.join(CWD, options.source)
@@ -100,18 +103,6 @@ async function getNpmTarballUrl(packageName, version = 'latest') {
100
103
  const { stdout } = await (0, spawn_async_1.default)('npm', ['view', `${packageName}@${version}`, 'dist.tarball']);
101
104
  return stdout.trim();
102
105
  }
103
- /**
104
- * Gets the username of currently logged in user. Used as a default in the prompt asking for the module author.
105
- */
106
- async function npmWhoamiAsync(targetDir) {
107
- try {
108
- const { stdout } = await (0, spawn_async_1.default)('npm', ['whoami'], { cwd: targetDir });
109
- return stdout.trim();
110
- }
111
- catch {
112
- return null;
113
- }
114
- }
115
106
  /**
116
107
  * Downloads the template from NPM registry.
117
108
  */
@@ -145,73 +136,26 @@ async function createModuleFromTemplate(templatePath, targetPath, data) {
145
136
  await fs_extra_1.default.outputFile(toPath, renderedContent, { encoding: 'utf8' });
146
137
  }
147
138
  }
139
+ /**
140
+ * Asks the user for the package slug (npm package name).
141
+ */
142
+ async function askForPackageSlugAsync(customTargetPath) {
143
+ const { slug } = await (0, prompts_1.default)((0, prompts_2.getSlugPrompt)(customTargetPath), {
144
+ onCancel: () => process.exit(0),
145
+ });
146
+ return slug;
147
+ }
148
148
  /**
149
149
  * Asks the user for some data necessary to render the template.
150
150
  * Some values may already be provided by command options, the prompt is skipped in that case.
151
151
  */
152
- async function askForSubstitutionDataAsync(targetDir, options) {
153
- var _a, _b;
154
- const defaultPackageSlug = path_1.default.basename(targetDir);
155
- const useDefaultSlug = options.target && (0, validate_npm_package_name_1.default)(defaultPackageSlug);
156
- const defaultProjectName = defaultPackageSlug
157
- .replace(/^./, (match) => match.toUpperCase())
158
- .replace(/\W+(\w)/g, (_, p1) => p1.toUpperCase());
159
- const promptQueries = [
160
- {
161
- type: 'text',
162
- name: 'slug',
163
- message: 'What is the package slug?',
164
- initial: defaultPackageSlug,
165
- resolvedValue: useDefaultSlug ? defaultPackageSlug : null,
166
- validate: (input) => (0, validate_npm_package_name_1.default)(input).validForNewPackages || 'Must be a valid npm package name',
167
- },
168
- {
169
- type: 'text',
170
- name: 'name',
171
- message: 'What is the project name?',
172
- initial: defaultProjectName,
173
- },
174
- {
175
- type: 'text',
176
- name: 'description',
177
- message: 'How would you describe the module?',
178
- validate: (input) => !!input || 'Cannot be empty',
179
- },
180
- {
181
- type: 'text',
182
- name: 'package',
183
- message: 'What is the Android package name?',
184
- initial: `expo.modules.${defaultPackageSlug.replace(/\W/g, '').toLowerCase()}`,
185
- },
186
- {
187
- type: 'text',
188
- name: 'author',
189
- message: 'Who is the author?',
190
- initial: (_a = (await npmWhoamiAsync(targetDir))) !== null && _a !== void 0 ? _a : '',
191
- },
192
- {
193
- type: 'text',
194
- name: 'license',
195
- message: 'What is the license?',
196
- initial: 'MIT',
197
- },
198
- {
199
- type: 'text',
200
- name: 'repo',
201
- message: 'What is the repository URL?',
202
- validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
203
- },
204
- ];
152
+ async function askForSubstitutionDataAsync(slug) {
153
+ const promptQueries = await (0, prompts_2.getSubstitutionDataPrompts)(slug);
205
154
  // Stop the process when the user cancels/exits the prompt.
206
155
  const onCancel = () => {
207
156
  process.exit(0);
208
157
  };
209
- const answers = {};
210
- for (const query of promptQueries) {
211
- const { name, resolvedValue } = query;
212
- answers[name] = (_b = resolvedValue !== null && resolvedValue !== void 0 ? resolvedValue : options[name]) !== null && _b !== void 0 ? _b : (await (0, prompts_1.default)(query, { onCancel }))[name];
213
- }
214
- const { slug, name, description, package: projectPackage, author, license, repo } = answers;
158
+ const { name, description, package: projectPackage, authorName, authorEmail, authorUrl, repo, } = await (0, prompts_1.default)(promptQueries, { onCancel });
215
159
  return {
216
160
  project: {
217
161
  slug,
@@ -220,8 +164,8 @@ async function askForSubstitutionDataAsync(targetDir, options) {
220
164
  description,
221
165
  package: projectPackage,
222
166
  },
223
- author,
224
- license,
167
+ author: `${authorName} <${authorEmail}> (${authorUrl})`,
168
+ license: 'MIT',
225
169
  repo,
226
170
  };
227
171
  }
@@ -236,7 +180,7 @@ async function confirmTargetDirAsync(targetDir) {
236
180
  const { shouldContinue } = await (0, prompts_1.default)({
237
181
  type: 'confirm',
238
182
  name: 'shouldContinue',
239
- message: `The target directory ${chalk_1.default.magenta(targetDir)} is not empty.\nDo you want to continue anyway?`,
183
+ message: `The target directory ${chalk_1.default.magenta(targetDir)} is not empty, do you want to continue anyway?`,
240
184
  initial: true,
241
185
  }, {
242
186
  onCancel: () => false,
@@ -250,14 +194,8 @@ program
250
194
  .name(packageJson.name)
251
195
  .version(packageJson.version)
252
196
  .description(packageJson.description)
253
- .arguments('[target_dir]')
197
+ .arguments('[path]')
254
198
  .option('-s, --source <source_dir>', 'Local path to the template. By default it downloads `expo-module-template` from NPM.')
255
- .option('-n, --name <module_name>', 'Name of the native module.')
256
- .option('-d, --description <description>', 'Description of the module.')
257
- .option('-p, --package <package>', 'The Android package name.')
258
- .option('-a, --author <author>', 'The author name.')
259
- .option('-l, --license <license>', 'The license that the module is distributed with.')
260
- .option('-r, --repo <repo_url>', 'The URL to the repository.')
261
199
  .option('--with-readme', 'Whether to include README.md file.', false)
262
200
  .option('--with-changelog', 'Whether to include CHANGELOG.md file.', false)
263
201
  .option('--no-example', 'Whether to skip creating the example app.', false)
@@ -1 +1 @@
1
- {"version":3,"file":"create-expo-module.js","sourceRoot":"","sources":["../src/create-expo-module.ts"],"names":[],"mappings":";;;;;AAAA,oEAA2C;AAC3C,kDAA0B;AAC1B,yCAAoC;AACpC,wEAA+C;AAC/C,8CAAsB;AACtB,wDAA0B;AAC1B,gDAAwB;AACxB,sDAA8B;AAC9B,0FAA2D;AAE3D,yDAAsD;AACtD,qDAAuD;AACvD,mEAAgE;AAEhE,mCAAkC;AAElC,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE/C,oFAAoF;AACpF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAElD,iEAAiE;AACjE,yDAAyD;AACzD,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;AAE7E;;;;;GAKG;AACH,KAAK,UAAU,IAAI,CAAC,MAA0B,EAAE,OAAuB;IACrE,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAExD,MAAM,kBAAE,CAAC,SAAS,CAAC,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Content":["import spawnAsync from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport { Command } from 'commander';\nimport downloadTarball from 'download-tarball';\nimport ejs from 'ejs';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport prompts from 'prompts';\nimport validateNpmPackage from 'validate-npm-package-name';\n\nimport { createExampleApp } from './createExampleApp';\nimport { installDependencies } from './packageManager';\nimport { resolvePackageManager } from './resolvePackageManager';\nimport { CommandOptions, CustomPromptObject, SubstitutionData } from './types';\nimport { newStep } from './utils';\n\nconst packageJson = require('../package.json');\n\n// `yarn run` may change the current working dir, then we should use `INIT_CWD` env.\nconst CWD = process.env.INIT_CWD || process.cwd();\n\n// Ignore some paths. Especially `package.json` as it is rendered\n// from `$package.json` file instead of the original one.\nconst IGNORES_PATHS = ['.DS_Store', 'build', 'node_modules', 'package.json'];\n\n/**\n * The main function of the command.\n *\n * @param target Path to the directory where to create the module. Defaults to current working dir.\n * @param command An object from `commander`.\n */\nasync function main(target: string | undefined, options: CommandOptions) {\n const targetDir = target ? path.join(CWD, target) : CWD;\n\n await fs.ensureDir(targetDir);\n await confirmTargetDirAsync(targetDir);\n\n options.target = targetDir;\n\n const data = await askForSubstitutionDataAsync(targetDir, options);\n const packageManager = await resolvePackageManager();\n const packagePath = options.source\n ? path.join(CWD, options.source)\n : await downloadPackageAsync(targetDir);\n\n await newStep('Creating the module from template files', async (step) => {\n await createModuleFromTemplate(packagePath, targetDir, data);\n step.succeed('Created the module from template files');\n });\n\n await newStep('Installing module dependencies', async (step) => {\n await installDependencies(packageManager, targetDir);\n step.succeed('Installed module dependencies');\n });\n\n await newStep('Compiling TypeScript files', async (step) => {\n await spawnAsync(packageManager, ['run', 'build'], {\n cwd: targetDir,\n stdio: 'ignore',\n });\n step.succeed('Compiled TypeScript files');\n });\n\n if (!options.source) {\n // Files in the downloaded tarball are wrapped in `package` dir.\n // We should remove it after all.\n await fs.remove(packagePath);\n }\n if (!options.withReadme) {\n await fs.remove(path.join(targetDir, 'README.md'));\n }\n if (!options.withChangelog) {\n await fs.remove(path.join(targetDir, 'CHANGELOG.md'));\n }\n if (options.example) {\n // Create \"example\" folder\n await createExampleApp(data, targetDir, packageManager);\n }\n\n console.log();\n console.log('✅ Successfully created Expo module');\n}\n\n/**\n * Recursively scans for the files within the directory. Returned paths are relative to the `root` path.\n */\nasync function getFilesAsync(root: string, dir: string | null = null): Promise<string[]> {\n const files: string[] = [];\n const baseDir = dir ? path.join(root, dir) : root;\n\n for (const file of await fs.readdir(baseDir)) {\n const relativePath = dir ? path.join(dir, file) : file;\n\n if (IGNORES_PATHS.includes(relativePath) || IGNORES_PATHS.includes(file)) {\n continue;\n }\n\n const fullPath = path.join(baseDir, file);\n const stat = await fs.lstat(fullPath);\n\n if (stat.isDirectory()) {\n files.push(...(await getFilesAsync(root, relativePath)));\n } else {\n files.push(relativePath);\n }\n }\n return files;\n}\n\n/**\n * Asks NPM registry for the url to the tarball.\n */\nasync function getNpmTarballUrl(packageName: string, version: string = 'latest'): Promise<string> {\n const { stdout } = await spawnAsync('npm', ['view', `${packageName}@${version}`, 'dist.tarball']);\n return stdout.trim();\n}\n\n/**\n * Gets the username of currently logged in user. Used as a default in the prompt asking for the module author.\n */\nasync function npmWhoamiAsync(targetDir: string): Promise<string | null> {\n try {\n const { stdout } = await spawnAsync('npm', ['whoami'], { cwd: targetDir });\n return stdout.trim();\n } catch {\n return null;\n }\n}\n\n/**\n * Downloads the template from NPM registry.\n */\nasync function downloadPackageAsync(targetDir: string): Promise<string> {\n return await newStep('Downloading module template from npm', async (step) => {\n const tarballUrl = await getNpmTarballUrl('expo-module-template');\n\n await downloadTarball({\n url: tarballUrl,\n dir: targetDir,\n });\n\n step.succeed('Downloaded module template from npm');\n\n return path.join(targetDir, 'package');\n });\n}\n\n/**\n * Creates the module based on the `ejs` template (e.g. `expo-module-template` package).\n */\nasync function createModuleFromTemplate(\n templatePath: string,\n targetPath: string,\n data: SubstitutionData\n) {\n const files = await getFilesAsync(templatePath);\n\n // Iterate through all template files.\n for (const file of files) {\n const renderedRelativePath = ejs.render(file.replace(/^\\$/, ''), data, {\n openDelimiter: '{',\n closeDelimiter: '}',\n escape: (value: string) => value.replace('.', path.sep),\n });\n const fromPath = path.join(templatePath, file);\n const toPath = path.join(targetPath, renderedRelativePath);\n const template = await fs.readFile(fromPath, { encoding: 'utf8' });\n const renderedContent = ejs.render(template, data);\n\n await fs.outputFile(toPath, renderedContent, { encoding: 'utf8' });\n }\n}\n\n/**\n * Asks the user for some data necessary to render the template.\n * Some values may already be provided by command options, the prompt is skipped in that case.\n */\nasync function askForSubstitutionDataAsync(\n targetDir: string,\n options: CommandOptions\n): Promise<SubstitutionData> {\n const defaultPackageSlug = path.basename(targetDir);\n const useDefaultSlug = options.target && validateNpmPackage(defaultPackageSlug);\n const defaultProjectName = defaultPackageSlug\n .replace(/^./, (match) => match.toUpperCase())\n .replace(/\\W+(\\w)/g, (_, p1) => p1.toUpperCase());\n\n const promptQueries: CustomPromptObject[] = [\n {\n type: 'text',\n name: 'slug',\n message: 'What is the package slug?',\n initial: defaultPackageSlug,\n resolvedValue: useDefaultSlug ? defaultPackageSlug : null,\n validate: (input) =>\n validateNpmPackage(input).validForNewPackages || 'Must be a valid npm package name',\n },\n {\n type: 'text',\n name: 'name',\n message: 'What is the project name?',\n initial: defaultProjectName,\n },\n {\n type: 'text',\n name: 'description',\n message: 'How would you describe the module?',\n validate: (input) => !!input || 'Cannot be empty',\n },\n {\n type: 'text',\n name: 'package',\n message: 'What is the Android package name?',\n initial: `expo.modules.${defaultPackageSlug.replace(/\\W/g, '').toLowerCase()}`,\n },\n {\n type: 'text',\n name: 'author',\n message: 'Who is the author?',\n initial: (await npmWhoamiAsync(targetDir)) ?? '',\n },\n {\n type: 'text',\n name: 'license',\n message: 'What is the license?',\n initial: 'MIT',\n },\n {\n type: 'text',\n name: 'repo',\n message: 'What is the repository URL?',\n validate: (input) => /^https?:\\/\\//.test(input) || 'Must be a valid URL',\n },\n ];\n\n // Stop the process when the user cancels/exits the prompt.\n const onCancel = () => {\n process.exit(0);\n };\n\n const answers: Record<string, string> = {};\n for (const query of promptQueries) {\n const { name, resolvedValue } = query;\n answers[name] = resolvedValue ?? options[name] ?? (await prompts(query, { onCancel }))[name];\n }\n\n const { slug, name, description, package: projectPackage, author, license, repo } = answers;\n\n return {\n project: {\n slug,\n name,\n version: '0.1.0',\n description,\n package: projectPackage,\n },\n author,\n license,\n repo,\n };\n}\n\n/**\n * Checks whether the target directory is empty and if not, asks the user to confirm if he wants to continue.\n */\nasync function confirmTargetDirAsync(targetDir: string): Promise<void> {\n const files = await fs.readdir(targetDir);\n\n if (files.length === 0) {\n return;\n }\n const { shouldContinue } = await prompts(\n {\n type: 'confirm',\n name: 'shouldContinue',\n message: `The target directory ${chalk.magenta(\n targetDir\n )} is not empty.\\nDo you want to continue anyway?`,\n initial: true,\n },\n {\n onCancel: () => false,\n }\n );\n if (!shouldContinue) {\n process.exit(0);\n }\n}\n\nconst program = new Command();\n\nprogram\n .name(packageJson.name)\n .version(packageJson.version)\n .description(packageJson.description)\n .arguments('[target_dir]')\n .option(\n '-s, --source <source_dir>',\n 'Local path to the template. By default it downloads `expo-module-template` from NPM.'\n )\n .option('-n, --name <module_name>', 'Name of the native module.')\n .option('-d, --description <description>', 'Description of the module.')\n .option('-p, --package <package>', 'The Android package name.')\n .option('-a, --author <author>', 'The author name.')\n .option('-l, --license <license>', 'The license that the module is distributed with.')\n .option('-r, --repo <repo_url>', 'The URL to the repository.')\n .option('--with-readme', 'Whether to include README.md file.', false)\n .option('--with-changelog', 'Whether to include CHANGELOG.md file.', false)\n .option('--no-example', 'Whether to skip creating the example app.', false)\n .action(main);\n\nprogram.parse(process.argv);\n"]}
1
+ {"version":3,"file":"create-expo-module.js","sourceRoot":"","sources":["../src/create-expo-module.ts"],"names":[],"mappings":";;;;;AAAA,oEAA2C;AAC3C,kDAA0B;AAC1B,yCAAoC;AACpC,wEAA+C;AAC/C,8CAAsB;AACtB,wDAA0B;AAC1B,gD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CAAC,CAAC;IAE1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,OAAO;KACR;IACD,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,IAAA,iBAAO,EACtC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,wBAAwB,eAAK,CAAC,OAAO,CAC5C,SAAS,CACV,gDAAgD;QACjD,OAAO,EAAE,IAAI;KACd,EACD;QACE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;KACtB,CACF,CAAC;IACF,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;KACtB,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;KAC5B,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC;KACpC,SAAS,CAAC,QAAQ,CAAC;KACnB,MAAM,CACL,2BAA2B,EAC3B,sFAAsF,CACvF;KACA,MAAM,CAAC,eAAe,EAAE,oCAAoC,EAAE,KAAK,CAAC;KACpE,MAAM,CAAC,kBAAkB,EAAE,uCAAuC,EAAE,KAAK,CAAC;KAC1E,MAAM,CAAC,cAAc,EAAE,2CAA2C,EAAE,KAAK,CAAC;KAC1E,MAAM,CAAC,IAAI,CAAC,CAAC;AAEhB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import spawnAsync from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport { Command } from 'commander';\nimport downloadTarball from 'download-tarball';\nimport ejs from 'ejs';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport prompts from 'prompts';\n\nimport { createExampleApp } from './createExampleApp';\nimport { installDependencies } from './packageManager';\nimport { getSlugPrompt, getSubstitutionDataPrompts } from './prompts';\nimport { resolvePackageManager } from './resolvePackageManager';\nimport { CommandOptions, SubstitutionData } from './types';\nimport { newStep } from './utils';\n\nconst packageJson = require('../package.json');\n\n// `yarn run` may change the current working dir, then we should use `INIT_CWD` env.\nconst CWD = process.env.INIT_CWD || process.cwd();\n\n// Ignore some paths. Especially `package.json` as it is rendered\n// from `$package.json` file instead of the original one.\nconst IGNORES_PATHS = ['.DS_Store', 'build', 'node_modules', 'package.json'];\n\n/**\n * The main function of the command.\n *\n * @param target Path to the directory where to create the module. Defaults to current working dir.\n * @param command An object from `commander`.\n */\nasync function main(target: string | undefined, options: CommandOptions) {\n const slug = await askForPackageSlugAsync(target);\n const targetDir = path.join(CWD, target || slug);\n\n await fs.ensureDir(targetDir);\n await confirmTargetDirAsync(targetDir);\n\n options.target = targetDir;\n\n const data = await askForSubstitutionDataAsync(slug);\n\n // Make one line break between prompts and progress logs\n console.log();\n\n const packageManager = await resolvePackageManager();\n const packagePath = options.source\n ? path.join(CWD, options.source)\n : await downloadPackageAsync(targetDir);\n\n await newStep('Creating the module from template files', async (step) => {\n await createModuleFromTemplate(packagePath, targetDir, data);\n step.succeed('Created the module from template files');\n });\n\n await newStep('Installing module dependencies', async (step) => {\n await installDependencies(packageManager, targetDir);\n step.succeed('Installed module dependencies');\n });\n\n await newStep('Compiling TypeScript files', async (step) => {\n await spawnAsync(packageManager, ['run', 'build'], {\n cwd: targetDir,\n stdio: 'ignore',\n });\n step.succeed('Compiled TypeScript files');\n });\n\n if (!options.source) {\n // Files in the downloaded tarball are wrapped in `package` dir.\n // We should remove it after all.\n await fs.remove(packagePath);\n }\n if (!options.withReadme) {\n await fs.remove(path.join(targetDir, 'README.md'));\n }\n if (!options.withChangelog) {\n await fs.remove(path.join(targetDir, 'CHANGELOG.md'));\n }\n if (options.example) {\n // Create \"example\" folder\n await createExampleApp(data, targetDir, packageManager);\n }\n\n console.log();\n console.log('✅ Successfully created Expo module');\n}\n\n/**\n * Recursively scans for the files within the directory. Returned paths are relative to the `root` path.\n */\nasync function getFilesAsync(root: string, dir: string | null = null): Promise<string[]> {\n const files: string[] = [];\n const baseDir = dir ? path.join(root, dir) : root;\n\n for (const file of await fs.readdir(baseDir)) {\n const relativePath = dir ? path.join(dir, file) : file;\n\n if (IGNORES_PATHS.includes(relativePath) || IGNORES_PATHS.includes(file)) {\n continue;\n }\n\n const fullPath = path.join(baseDir, file);\n const stat = await fs.lstat(fullPath);\n\n if (stat.isDirectory()) {\n files.push(...(await getFilesAsync(root, relativePath)));\n } else {\n files.push(relativePath);\n }\n }\n return files;\n}\n\n/**\n * Asks NPM registry for the url to the tarball.\n */\nasync function getNpmTarballUrl(packageName: string, version: string = 'latest'): Promise<string> {\n const { stdout } = await spawnAsync('npm', ['view', `${packageName}@${version}`, 'dist.tarball']);\n return stdout.trim();\n}\n\n/**\n * Downloads the template from NPM registry.\n */\nasync function downloadPackageAsync(targetDir: string): Promise<string> {\n return await newStep('Downloading module template from npm', async (step) => {\n const tarballUrl = await getNpmTarballUrl('expo-module-template');\n\n await downloadTarball({\n url: tarballUrl,\n dir: targetDir,\n });\n\n step.succeed('Downloaded module template from npm');\n\n return path.join(targetDir, 'package');\n });\n}\n\n/**\n * Creates the module based on the `ejs` template (e.g. `expo-module-template` package).\n */\nasync function createModuleFromTemplate(\n templatePath: string,\n targetPath: string,\n data: SubstitutionData\n) {\n const files = await getFilesAsync(templatePath);\n\n // Iterate through all template files.\n for (const file of files) {\n const renderedRelativePath = ejs.render(file.replace(/^\\$/, ''), data, {\n openDelimiter: '{',\n closeDelimiter: '}',\n escape: (value: string) => value.replace('.', path.sep),\n });\n const fromPath = path.join(templatePath, file);\n const toPath = path.join(targetPath, renderedRelativePath);\n const template = await fs.readFile(fromPath, { encoding: 'utf8' });\n const renderedContent = ejs.render(template, data);\n\n await fs.outputFile(toPath, renderedContent, { encoding: 'utf8' });\n }\n}\n\n/**\n * Asks the user for the package slug (npm package name).\n */\nasync function askForPackageSlugAsync(customTargetPath?: string): Promise<string> {\n const { slug } = await prompts(getSlugPrompt(customTargetPath), {\n onCancel: () => process.exit(0),\n });\n return slug;\n}\n\n/**\n * Asks the user for some data necessary to render the template.\n * Some values may already be provided by command options, the prompt is skipped in that case.\n */\nasync function askForSubstitutionDataAsync(slug: string): Promise<SubstitutionData> {\n const promptQueries = await getSubstitutionDataPrompts(slug);\n\n // Stop the process when the user cancels/exits the prompt.\n const onCancel = () => {\n process.exit(0);\n };\n\n const {\n name,\n description,\n package: projectPackage,\n authorName,\n authorEmail,\n authorUrl,\n repo,\n } = await prompts(promptQueries, { onCancel });\n\n return {\n project: {\n slug,\n name,\n version: '0.1.0',\n description,\n package: projectPackage,\n },\n author: `${authorName} <${authorEmail}> (${authorUrl})`,\n license: 'MIT',\n repo,\n };\n}\n\n/**\n * Checks whether the target directory is empty and if not, asks the user to confirm if he wants to continue.\n */\nasync function confirmTargetDirAsync(targetDir: string): Promise<void> {\n const files = await fs.readdir(targetDir);\n\n if (files.length === 0) {\n return;\n }\n const { shouldContinue } = await prompts(\n {\n type: 'confirm',\n name: 'shouldContinue',\n message: `The target directory ${chalk.magenta(\n targetDir\n )} is not empty, do you want to continue anyway?`,\n initial: true,\n },\n {\n onCancel: () => false,\n }\n );\n if (!shouldContinue) {\n process.exit(0);\n }\n}\n\nconst program = new Command();\n\nprogram\n .name(packageJson.name)\n .version(packageJson.version)\n .description(packageJson.description)\n .arguments('[path]')\n .option(\n '-s, --source <source_dir>',\n 'Local path to the template. By default it downloads `expo-module-template` from NPM.'\n )\n .option('--with-readme', 'Whether to include README.md file.', false)\n .option('--with-changelog', 'Whether to include CHANGELOG.md file.', false)\n .option('--no-example', 'Whether to skip creating the example app.', false)\n .action(main);\n\nprogram.parse(process.argv);\n"]}
@@ -15,18 +15,23 @@ const DEPENDENCIES_TO_REMOVE = ['expo-status-bar', 'expo-splash-screen'];
15
15
  * Initializes a new Expo project as an example app.
16
16
  */
17
17
  async function createExampleApp(data, targetDir, packageManager) {
18
+ // Package name for the example app
18
19
  const exampleProjectSlug = `${data.project.slug}-example`;
20
+ // `expo init` creates a new folder with the same name as the project slug
21
+ const appTmpPath = path_1.default.join(targetDir, exampleProjectSlug);
22
+ // Path to the target example dir
23
+ const appTargetPath = path_1.default.join(targetDir, 'example');
24
+ if (!(await fs_extra_1.default.pathExists(appTargetPath))) {
25
+ // The template doesn't include the example app, so just skip this phase
26
+ return;
27
+ }
19
28
  await (0, utils_1.newStep)('Initializing the example app', async (step) => {
20
- await (0, spawn_async_1.default)('expo', ['init', exampleProjectSlug, '--template', 'expo-template-blank-typescript'], {
29
+ await (0, spawn_async_1.default)(packageManager, ['create', 'expo-app', '--', exampleProjectSlug, '--template', 'blank-typescript', '--yes'], {
21
30
  cwd: targetDir,
22
- stdio: ['ignore', 'ignore', 'inherit'],
31
+ stdio: 'ignore',
23
32
  });
24
33
  step.succeed('Initialized the example app');
25
34
  });
26
- // `expo init` creates a new folder with the same name as the project slug
27
- const appTmpPath = path_1.default.join(targetDir, exampleProjectSlug);
28
- // Path to the target example dir
29
- const appTargetPath = path_1.default.join(targetDir, 'example');
30
35
  await (0, utils_1.newStep)('Configuring the example app', async (step) => {
31
36
  // "example" folder already exists and contains template files,
32
37
  // that should replace these created by `expo init`.
@@ -1 +1 @@
1
- {"version":3,"file":"createExampleApp.js","sourceRoot":"","sources":["../src/createExampleApp.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA2C;AAC3C,wDAA0B;AAC1B,gDAAwB;AAExB,qDAAuD;AAGvD,mCAAkC;AAElC,kFAAkF;AAClF,MAAM,sBAAsB,GAAG,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;AAEzE;;GAEG;AACI,KAAK,UAAU,gBAAgB,CACpC,IAAsB,EACtB,SAAiB,EACjB,cAAkC;IAElC,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC;IAE1D,MAAM,IAAA,eAAO,EAAC,8BAA8B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC3D,M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AQ,EAAE,MAAM,CAAC;KACpC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import spawnAsync from '@expo/spawn-async';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { installDependencies } from './packageManager';\nimport { PackageManagerName } from './resolvePackageManager';\nimport { SubstitutionData } from './types';\nimport { newStep } from './utils';\n\n// These dependencies will be removed from the example app (`expo init` adds them)\nconst DEPENDENCIES_TO_REMOVE = ['expo-status-bar', 'expo-splash-screen'];\n\n/**\n * Initializes a new Expo project as an example app.\n */\nexport async function createExampleApp(\n data: SubstitutionData,\n targetDir: string,\n packageManager: PackageManagerName\n): Promise<void> {\n const exampleProjectSlug = `${data.project.slug}-example`;\n\n await newStep('Initializing the example app', async (step) => {\n await spawnAsync(\n 'expo',\n ['init', exampleProjectSlug, '--template', 'expo-template-blank-typescript'],\n {\n cwd: targetDir,\n stdio: ['ignore', 'ignore', 'inherit'],\n }\n );\n step.succeed('Initialized the example app');\n });\n\n // `expo init` creates a new folder with the same name as the project slug\n const appTmpPath = path.join(targetDir, exampleProjectSlug);\n\n // Path to the target example dir\n const appTargetPath = path.join(targetDir, 'example');\n\n await newStep('Configuring the example app', async (step) => {\n // \"example\" folder already exists and contains template files,\n // that should replace these created by `expo init`.\n await moveFiles(appTargetPath, appTmpPath);\n\n // Cleanup the \"example\" dir\n await fs.rmdir(appTargetPath);\n\n // Move the temporary example app to \"example\" dir\n await fs.rename(appTmpPath, appTargetPath);\n\n await addMissingAppConfigFields(appTargetPath, data);\n\n step.succeed('Configured the example app');\n });\n\n await prebuildExampleApp(appTargetPath);\n\n await modifyPackageJson(appTargetPath);\n\n await newStep('Installing dependencies in the example app', async (step) => {\n await installDependencies(packageManager, appTargetPath);\n await podInstall(appTargetPath);\n step.succeed('Installed dependencies in the example app');\n });\n}\n\n/**\n * Copies files from one directory to another.\n */\nasync function moveFiles(fromPath: string, toPath: string): Promise<void> {\n for (const file of await fs.readdir(fromPath)) {\n await fs.move(path.join(fromPath, file), path.join(toPath, file), {\n overwrite: true,\n });\n }\n}\n\n/**\n * Adds missing configuration that are required to run `expo prebuild`.\n */\nasync function addMissingAppConfigFields(appPath: string, data: SubstitutionData): Promise<void> {\n const appConfigPath = path.join(appPath, 'app.json');\n const appConfig = await fs.readJson(appConfigPath);\n const appId = `${data.project.package}.example`;\n\n // Android package name needs to be added to app.json\n if (!appConfig.expo.android) {\n appConfig.expo.android = {};\n }\n appConfig.expo.android.package = appId;\n\n // Specify iOS bundle identifier\n if (!appConfig.expo.ios) {\n appConfig.expo.ios = {};\n }\n appConfig.expo.ios.bundleIdentifier = appId;\n\n await fs.writeJson(appConfigPath, appConfig, {\n spaces: 2,\n });\n}\n\n/**\n * Applies necessary changes to **package.json** of the example app.\n * It means setting the autolinking config and removing unnecessary dependencies.\n */\nasync function modifyPackageJson(appPath: string): Promise<void> {\n const packageJsonPath = path.join(appPath, 'package.json');\n const packageJson = await fs.readJson(packageJsonPath);\n\n if (!packageJson.expo) {\n packageJson.expo = {};\n }\n\n // Set the native modules dir to the root folder,\n // so that the autolinking can detect and link the module.\n packageJson.expo.autolinking = {\n nativeModulesDir: '..',\n };\n\n // Remove unnecessary dependencies\n for (const dependencyToRemove of DEPENDENCIES_TO_REMOVE) {\n delete packageJson.dependencies[dependencyToRemove];\n }\n\n await fs.writeJson(packageJsonPath, packageJson, {\n spaces: 2,\n });\n}\n\n/**\n * Runs `expo prebuild` in the example app.\n */\nasync function prebuildExampleApp(exampleAppPath: string): Promise<void> {\n await newStep('Prebuilding the example app', async (step) => {\n await spawnAsync('expo', ['prebuild', '--no-install'], {\n cwd: exampleAppPath,\n stdio: ['ignore', 'ignore', 'pipe'],\n });\n step.succeed('Prebuilt the example app');\n });\n}\n\n/**\n * Runs `pod install` in the iOS project at the given path.\n */\nasync function podInstall(appPath: string): Promise<void> {\n await spawnAsync('pod', ['install'], {\n cwd: path.join(appPath, 'ios'),\n stdio: ['ignore', 'ignore', 'pipe'],\n });\n}\n"]}
1
+ {"version":3,"file":"createExamp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AAC,cAAsB;IACtD,MAAM,IAAA,eAAO,EAAC,6BAA6B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC1D,MAAM,IAAA,qBAAU,EAAC,MAAM,EAAE,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE;YACrD,GAAG,EAAE,cAAc;YACnB,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC;SACpC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,UAAU,CAAC,OAAe;IACvC,MAAM,IAAA,qBAAU,EAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;QACnC,GAAG,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;QAC9B,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC;KACpC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import spawnAsync from '@expo/spawn-async';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { installDependencies } from './packageManager';\nimport { PackageManagerName } from './resolvePackageManager';\nimport { SubstitutionData } from './types';\nimport { newStep } from './utils';\n\n// These dependencies will be removed from the example app (`expo init` adds them)\nconst DEPENDENCIES_TO_REMOVE = ['expo-status-bar', 'expo-splash-screen'];\n\n/**\n * Initializes a new Expo project as an example app.\n */\nexport async function createExampleApp(\n data: SubstitutionData,\n targetDir: string,\n packageManager: PackageManagerName\n): Promise<void> {\n // Package name for the example app\n const exampleProjectSlug = `${data.project.slug}-example`;\n\n // `expo init` creates a new folder with the same name as the project slug\n const appTmpPath = path.join(targetDir, exampleProjectSlug);\n\n // Path to the target example dir\n const appTargetPath = path.join(targetDir, 'example');\n\n if (!(await fs.pathExists(appTargetPath))) {\n // The template doesn't include the example app, so just skip this phase\n return;\n }\n\n await newStep('Initializing the example app', async (step) => {\n await spawnAsync(\n packageManager,\n ['create', 'expo-app', '--', exampleProjectSlug, '--template', 'blank-typescript', '--yes'],\n {\n cwd: targetDir,\n stdio: 'ignore',\n }\n );\n step.succeed('Initialized the example app');\n });\n\n await newStep('Configuring the example app', async (step) => {\n // \"example\" folder already exists and contains template files,\n // that should replace these created by `expo init`.\n await moveFiles(appTargetPath, appTmpPath);\n\n // Cleanup the \"example\" dir\n await fs.rmdir(appTargetPath);\n\n // Move the temporary example app to \"example\" dir\n await fs.rename(appTmpPath, appTargetPath);\n\n await addMissingAppConfigFields(appTargetPath, data);\n\n step.succeed('Configured the example app');\n });\n\n await prebuildExampleApp(appTargetPath);\n\n await modifyPackageJson(appTargetPath);\n\n await newStep('Installing dependencies in the example app', async (step) => {\n await installDependencies(packageManager, appTargetPath);\n await podInstall(appTargetPath);\n step.succeed('Installed dependencies in the example app');\n });\n}\n\n/**\n * Copies files from one directory to another.\n */\nasync function moveFiles(fromPath: string, toPath: string): Promise<void> {\n for (const file of await fs.readdir(fromPath)) {\n await fs.move(path.join(fromPath, file), path.join(toPath, file), {\n overwrite: true,\n });\n }\n}\n\n/**\n * Adds missing configuration that are required to run `expo prebuild`.\n */\nasync function addMissingAppConfigFields(appPath: string, data: SubstitutionData): Promise<void> {\n const appConfigPath = path.join(appPath, 'app.json');\n const appConfig = await fs.readJson(appConfigPath);\n const appId = `${data.project.package}.example`;\n\n // Android package name needs to be added to app.json\n if (!appConfig.expo.android) {\n appConfig.expo.android = {};\n }\n appConfig.expo.android.package = appId;\n\n // Specify iOS bundle identifier\n if (!appConfig.expo.ios) {\n appConfig.expo.ios = {};\n }\n appConfig.expo.ios.bundleIdentifier = appId;\n\n await fs.writeJson(appConfigPath, appConfig, {\n spaces: 2,\n });\n}\n\n/**\n * Applies necessary changes to **package.json** of the example app.\n * It means setting the autolinking config and removing unnecessary dependencies.\n */\nasync function modifyPackageJson(appPath: string): Promise<void> {\n const packageJsonPath = path.join(appPath, 'package.json');\n const packageJson = await fs.readJson(packageJsonPath);\n\n if (!packageJson.expo) {\n packageJson.expo = {};\n }\n\n // Set the native modules dir to the root folder,\n // so that the autolinking can detect and link the module.\n packageJson.expo.autolinking = {\n nativeModulesDir: '..',\n };\n\n // Remove unnecessary dependencies\n for (const dependencyToRemove of DEPENDENCIES_TO_REMOVE) {\n delete packageJson.dependencies[dependencyToRemove];\n }\n\n await fs.writeJson(packageJsonPath, packageJson, {\n spaces: 2,\n });\n}\n\n/**\n * Runs `expo prebuild` in the example app.\n */\nasync function prebuildExampleApp(exampleAppPath: string): Promise<void> {\n await newStep('Prebuilding the example app', async (step) => {\n await spawnAsync('expo', ['prebuild', '--no-install'], {\n cwd: exampleAppPath,\n stdio: ['ignore', 'ignore', 'pipe'],\n });\n step.succeed('Prebuilt the example app');\n });\n}\n\n/**\n * Runs `pod install` in the iOS project at the given path.\n */\nasync function podInstall(appPath: string): Promise<void> {\n await spawnAsync('pod', ['install'], {\n cwd: path.join(appPath, 'ios'),\n stdio: ['ignore', 'ignore', 'pipe'],\n });\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { PromptObject } from 'prompts';
2
+ export declare function getSlugPrompt(customTargetPath?: string | null): PromptObject<string>;
3
+ export declare function getSubstitutionDataPrompts(slug: string): Promise<PromptObject<string>[]>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSubstitutionDataPrompts = exports.getSlugPrompt = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
9
+ const utils_1 = require("./utils");
10
+ function getSlugPrompt(customTargetPath) {
11
+ const targetBasename = customTargetPath && path_1.default.basename(customTargetPath);
12
+ const initial = targetBasename && (0, validate_npm_package_name_1.default)(targetBasename).validForNewPackages
13
+ ? targetBasename
14
+ : 'my-module';
15
+ return {
16
+ type: 'text',
17
+ name: 'slug',
18
+ message: 'What is the name of the npm package?',
19
+ initial,
20
+ validate: (input) => (0, validate_npm_package_name_1.default)(input).validForNewPackages || 'Must be a valid npm package name',
21
+ };
22
+ }
23
+ exports.getSlugPrompt = getSlugPrompt;
24
+ async function getSubstitutionDataPrompts(slug) {
25
+ return [
26
+ {
27
+ type: 'text',
28
+ name: 'name',
29
+ message: 'What is the native module name?',
30
+ initial: () => {
31
+ return slug
32
+ .replace(/^@/, '')
33
+ .replace(/^./, (match) => match.toUpperCase())
34
+ .replace(/\W+(\w)/g, (_, p1) => p1.toUpperCase());
35
+ },
36
+ validate: (input) => !!input || 'The native module name cannot be empty',
37
+ },
38
+ {
39
+ type: 'text',
40
+ name: 'description',
41
+ message: 'How would you describe the module?',
42
+ initial: 'My new module',
43
+ validate: (input) => !!input || 'The description cannot be empty',
44
+ },
45
+ {
46
+ type: 'text',
47
+ name: 'package',
48
+ message: 'What is the Android package name?',
49
+ initial: () => {
50
+ const namespace = slug
51
+ .replace(/\W/g, '')
52
+ .replace(/^(expo|reactnative)/, '')
53
+ .toLowerCase();
54
+ return `expo.modules.${namespace}`;
55
+ },
56
+ validate: (input) => !!input || 'The Android package name cannot be empty',
57
+ },
58
+ {
59
+ type: 'text',
60
+ name: 'authorName',
61
+ message: 'What is the name of the package author?',
62
+ initial: await (0, utils_1.findMyName)(),
63
+ validate: (input) => !!input || 'Cannot be empty',
64
+ },
65
+ {
66
+ type: 'text',
67
+ name: 'authorEmail',
68
+ message: 'What is the email address of the author?',
69
+ initial: await (0, utils_1.findGitHubEmail)(),
70
+ },
71
+ {
72
+ type: 'text',
73
+ name: 'authorUrl',
74
+ message: "What is the URL to the author's GitHub profile?",
75
+ initial: async (_, answers) => await (0, utils_1.findGitHubProfileUrl)(answers.authorEmail),
76
+ },
77
+ {
78
+ type: 'text',
79
+ name: 'repo',
80
+ message: 'What is the URL for the repository?',
81
+ initial: async (_, answers) => await (0, utils_1.guessRepoUrl)(answers.authorUrl, slug),
82
+ validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
83
+ },
84
+ ];
85
+ }
86
+ exports.getSubstitutionDataPrompts = getSubstitutionDataPrompts;
87
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,0FAA2D;AAE3D,mCAA0F;AAE1F,SAAgB,aAAa,CAAC,gBAAgC;IAC5D,MAAM,cAAc,GAAG,gBAAgB,IAAI,cAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC3E,MAAM,OAAO,GACX,cAAc,IAAI,IAAA,mCAAkB,EAAC,cAAc,CAAC,CAAC,mBAAmB;QACtE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,WAAW,CAAC;IAElB,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,sCAAsC;QAC/C,OAAO;QACP,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAClB,IAAA,mCAAkB,EAAC,KAAK,CAAC,CAAC,mBAAmB,IAAI,kCAAkC;KACtF,CAAC;AACJ,CAAC;AAfD,sCAeC;AAEM,KAAK,UAAU,0BAA0B,CAAC,IAAY;IAC3D,OAAO;QACL;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,iCAAiC;YAC1C,OAAO,EAAE,GAAG,EAAE;gBACZ,OAAO,IAAI;qBACR,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;qBACjB,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;qBAC7C,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YACtD,CAAC;YACD,QAAQ,EAAE,CA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,EAAE,MAAM;YACZ,OAAO,EAAE,qCAAqC;YAC9C,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,OAAwB,EAAE,EAAE,CAAC,MAAM,IAAA,oBAAY,EAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;YAC3F,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,qBAAqB;SACzE;KACF,CAAC;AACJ,CAAC;AA9DD,gEA8DC","sourcesContent":["import path from 'path';\nimport { Answers, PromptObject } from 'prompts';\nimport validateNpmPackage from 'validate-npm-package-name';\n\nimport { findGitHubEmail, findGitHubProfileUrl, findMyName, guessRepoUrl } from './utils';\n\nexport function getSlugPrompt(customTargetPath?: string | null): PromptObject<string> {\n const targetBasename = customTargetPath && path.basename(customTargetPath);\n const initial =\n targetBasename && validateNpmPackage(targetBasename).validForNewPackages\n ? targetBasename\n : 'my-module';\n\n return {\n type: 'text',\n name: 'slug',\n message: 'What is the name of the npm package?',\n initial,\n validate: (input) =>\n validateNpmPackage(input).validForNewPackages || 'Must be a valid npm package name',\n };\n}\n\nexport async function getSubstitutionDataPrompts(slug: string): Promise<PromptObject<string>[]> {\n return [\n {\n type: 'text',\n name: 'name',\n message: 'What is the native module name?',\n initial: () => {\n return slug\n .replace(/^@/, '')\n .replace(/^./, (match) => match.toUpperCase())\n .replace(/\\W+(\\w)/g, (_, p1) => p1.toUpperCase());\n },\n validate: (input) => !!input || 'The native module name cannot be empty',\n },\n {\n type: 'text',\n name: 'description',\n message: 'How would you describe the module?',\n initial: 'My new module',\n validate: (input) => !!input || 'The description cannot be empty',\n },\n {\n type: 'text',\n name: 'package',\n message: 'What is the Android package name?',\n initial: () => {\n const namespace = slug\n .replace(/\\W/g, '')\n .replace(/^(expo|reactnative)/, '')\n .toLowerCase();\n return `expo.modules.${namespace}`;\n },\n validate: (input) => !!input || 'The Android package name cannot be empty',\n },\n {\n type: 'text',\n name: 'authorName',\n message: 'What is the name of the package author?',\n initial: await findMyName(),\n validate: (input) => !!input || 'Cannot be empty',\n },\n {\n type: 'text',\n name: 'authorEmail',\n message: 'What is the email address of the author?',\n initial: await findGitHubEmail(),\n },\n {\n type: 'text',\n name: 'authorUrl',\n message: \"What is the URL to the author's GitHub profile?\",\n initial: async (_, answers: Answers<string>) =>\n await findGitHubProfileUrl(answers.authorEmail),\n },\n {\n type: 'text',\n name: 'repo',\n message: 'What is the URL for the repository?',\n initial: async (_, answers: Answers<string>) => await guessRepoUrl(answers.authorUrl, slug),\n validate: (input) => /^https?:\\/\\//.test(input) || 'Must be a valid URL',\n },\n ];\n}\n"]}
package/build/types.d.ts CHANGED
@@ -5,12 +5,6 @@ import { PromptObject } from 'prompts';
5
5
  export declare type CommandOptions = {
6
6
  target: string;
7
7
  source?: string;
8
- name?: string;
9
- description?: string;
10
- package?: string;
11
- author?: string;
12
- license?: string;
13
- repo?: string;
14
8
  withReadme: boolean;
15
9
  withChangelog: boolean;
16
10
  example: boolean;
@@ -34,3 +28,4 @@ export declare type CustomPromptObject = PromptObject & {
34
28
  name: string;
35
29
  resolvedValue?: string | null;
36
30
  };
31
+ export declare type Answers = Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PromptObject } from 'prompts';\n\n/**\n * Possible command options.\n */\nexport type CommandOptions = {\n target: string;\n source?: string;\n name?: string;\n description?: string;\n package?: string;\n author?: string;\n license?: string;\n repo?: string;\n withReadme: boolean;\n withChangelog: boolean;\n example: boolean;\n};\n\n/**\n * Represents an object that is passed to `ejs` when rendering the template.\n */\nexport type SubstitutionData = {\n project: {\n slug: string;\n name: string;\n version: string;\n description: string;\n package: string;\n };\n author: string;\n license: string;\n repo: string;\n};\n\nexport type CustomPromptObject = PromptObject & {\n name: string;\n resolvedValue?: string | null;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PromptObject } from 'prompts';\n\n/**\n * Possible command options.\n */\nexport type CommandOptions = {\n target: string;\n source?: string;\n withReadme: boolean;\n withChangelog: boolean;\n example: boolean;\n};\n\n/**\n * Represents an object that is passed to `ejs` when rendering the template.\n */\nexport type SubstitutionData = {\n project: {\n slug: string;\n name: string;\n version: string;\n description: string;\n package: string;\n };\n author: string;\n license: string;\n repo: string;\n};\n\nexport type CustomPromptObject = PromptObject & {\n name: string;\n resolvedValue?: string | null;\n};\n\nexport type Answers = Record<string, string>;\n"]}
package/build/utils.d.ts CHANGED
@@ -1,3 +1,19 @@
1
1
  import ora from 'ora';
2
2
  export declare type StepOptions = ora.Options;
3
3
  export declare function newStep<Result>(title: string, action: (step: ora.Ora) => Promise<Result> | Result, options?: StepOptions): Promise<Result>;
4
+ /**
5
+ * Finds user's name by reading it from the git config.
6
+ */
7
+ export declare function findMyName(): Promise<string>;
8
+ /**
9
+ * Finds user's email by reading it from the git config.
10
+ */
11
+ export declare function findGitHubEmail(): Promise<string>;
12
+ /**
13
+ * Get the GitHub username from an email address if the email can be found in any commits on GitHub.
14
+ */
15
+ export declare function findGitHubProfileUrl(email: string): Promise<string>;
16
+ /**
17
+ * Guesses the repository URL based on the author profile URL and the package slug.
18
+ */
19
+ export declare function guessRepoUrl(authorUrl: string, slug: string): Promise<string>;
package/build/utils.js CHANGED
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.newStep = void 0;
6
+ exports.guessRepoUrl = exports.findGitHubProfileUrl = exports.findGitHubEmail = exports.findMyName = exports.newStep = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
9
+ const github_username_1 = __importDefault(require("github-username"));
8
10
  const ora_1 = __importDefault(require("ora"));
9
11
  async function newStep(title, action, options = {}) {
10
12
  const disabled = process.env.CI || process.env.EXPO_DEBUG;
@@ -25,4 +27,53 @@ async function newStep(title, action, options = {}) {
25
27
  }
26
28
  }
27
29
  exports.newStep = newStep;
30
+ /**
31
+ * Finds user's name by reading it from the git config.
32
+ */
33
+ async function findMyName() {
34
+ try {
35
+ return cross_spawn_1.default.sync('git', ['config', '--get', 'user.name']).stdout.toString().trim();
36
+ }
37
+ catch {
38
+ return '';
39
+ }
40
+ }
41
+ exports.findMyName = findMyName;
42
+ /**
43
+ * Finds user's email by reading it from the git config.
44
+ */
45
+ async function findGitHubEmail() {
46
+ try {
47
+ return cross_spawn_1.default.sync('git', ['config', '--get', 'user.email']).stdout.toString().trim();
48
+ }
49
+ catch {
50
+ return '';
51
+ }
52
+ }
53
+ exports.findGitHubEmail = findGitHubEmail;
54
+ /**
55
+ * Get the GitHub username from an email address if the email can be found in any commits on GitHub.
56
+ */
57
+ async function findGitHubProfileUrl(email) {
58
+ var _a;
59
+ try {
60
+ const username = (_a = (await (0, github_username_1.default)(email))) !== null && _a !== void 0 ? _a : '';
61
+ return `https://github.com/${username}`;
62
+ }
63
+ catch {
64
+ return '';
65
+ }
66
+ }
67
+ exports.findGitHubProfileUrl = findGitHubProfileUrl;
68
+ /**
69
+ * Guesses the repository URL based on the author profile URL and the package slug.
70
+ */
71
+ async function guessRepoUrl(authorUrl, slug) {
72
+ if (/^https?:\/\/github.com\/[^/]+/.test(authorUrl)) {
73
+ const normalizedSlug = slug.replace(/^@/, '').replace(/\//g, '-');
74
+ return `${authorUrl}/${normalizedSlug}`;
75
+ }
76
+ return '';
77
+ }
78
+ exports.guessRepoUrl = guessRepoUrl;
28
79
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,8CAAsB;AAIf,KAAK,UAAU,OAAO,CAC3B,KAAa,EACb,MAAmD,EACnD,UAAuB,EAAE;IAEzB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1D,MAAM,IAAI,GAAG,IAAA,aAAG,EAAC;QACf,IAAI,EAAE,eAAK,CAAC,IAAI,CAAC,KAAK,CAAC;QACvB,SAAS,EAAE,CAAC,QAAQ;QACpB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM;QAClD,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,IAAI,CAAC,KAAK,EAAE,CAAC;IAEb,IAAI;QACF,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;KAC3B;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AAtBD,0BAsBC","sourcesContent":["import chalk from 'chalk';\nimport ora from 'ora';\n\nexport type StepOptions = ora.Options;\n\nexport async function newStep<Result>(\n title: string,\n action: (step: ora.Ora) => Promise<Result> | Result,\n options: StepOptions = {}\n): Promise<Result> {\n const disabled = process.env.CI || process.env.EXPO_DEBUG;\n const step = ora({\n text: chalk.bold(title),\n isEnabled: !disabled,\n stream: disabled ? process.stdout : process.stderr,\n ...options,\n });\n\n step.start();\n\n try {\n return await action(step);\n } catch (error) {\n step.fail();\n console.error(error);\n process.exit(1);\n }\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,8DAAgC;AAChC,sEAA6C;AAC7C,8CAAsB;AAIf,KAAK,UAAU,OAAO,CAC3B,KAAa,EACb,MAAmD,EACnD,UAAuB,EAAE;IAEzB,MAAM,QAAQ,GAAG,OAAO,CAAC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AG,MAAA,CAAC,MAAM,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC,mCAAI,EAAE,CAAC;QACrD,OAAO,sBAAsB,QAAQ,EAAE,CAAC;KACzC;IAAC,MAAM;QACN,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAPD,oDAOC;AAED;;GAEG;AACI,KAAK,UAAU,YAAY,CAAC,SAAiB,EAAE,IAAY;IAChE,IAAI,+BAA+B,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAClE,OAAO,GAAG,SAAS,IAAI,cAAc,EAAE,CAAC;KACzC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAND,oCAMC","sourcesContent":["import chalk from 'chalk';\nimport spawn from 'cross-spawn';\nimport githubUsername from 'github-username';\nimport ora from 'ora';\n\nexport type StepOptions = ora.Options;\n\nexport async function newStep<Result>(\n title: string,\n action: (step: ora.Ora) => Promise<Result> | Result,\n options: StepOptions = {}\n): Promise<Result> {\n const disabled = process.env.CI || process.env.EXPO_DEBUG;\n const step = ora({\n text: chalk.bold(title),\n isEnabled: !disabled,\n stream: disabled ? process.stdout : process.stderr,\n ...options,\n });\n\n step.start();\n\n try {\n return await action(step);\n } catch (error) {\n step.fail();\n console.error(error);\n process.exit(1);\n }\n}\n\n/**\n * Finds user's name by reading it from the git config.\n */\nexport async function findMyName(): Promise<string> {\n try {\n return spawn.sync('git', ['config', '--get', 'user.name']).stdout.toString().trim();\n } catch {\n return '';\n }\n}\n\n/**\n * Finds user's email by reading it from the git config.\n */\nexport async function findGitHubEmail(): Promise<string> {\n try {\n return spawn.sync('git', ['config', '--get', 'user.email']).stdout.toString().trim();\n } catch {\n return '';\n }\n}\n\n/**\n * Get the GitHub username from an email address if the email can be found in any commits on GitHub.\n */\nexport async function findGitHubProfileUrl(email: string): Promise<string> {\n try {\n const username = (await githubUsername(email)) ?? '';\n return `https://github.com/${username}`;\n } catch {\n return '';\n }\n}\n\n/**\n * Guesses the repository URL based on the author profile URL and the package slug.\n */\nexport async function guessRepoUrl(authorUrl: string, slug: string) {\n if (/^https?:\\/\\/github.com\\/[^/]+/.test(authorUrl)) {\n const normalizedSlug = slug.replace(/^@/, '').replace(/\\//g, '-');\n return `${authorUrl}/${normalizedSlug}`;\n }\n return '';\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-expo-module",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "The script to create the Expo module",
5
5
  "main": "build/create-expo-module.js",
6
6
  "types": "build/create-expo-module.d.ts",
@@ -36,9 +36,11 @@
36
36
  "@expo/spawn-async": "^1.5.0",
37
37
  "chalk": "^4.1.2",
38
38
  "commander": "^8.3.0",
39
+ "cross-spawn": "^7.0.3",
39
40
  "download-tarball": "^2.0.0",
40
41
  "ejs": "^3.1.7",
41
42
  "fs-extra": "^10.0.0",
43
+ "github-username": "^6.0.0",
42
44
  "ora": "^5.4.1",
43
45
  "prompts": "^2.4.2",
44
46
  "validate-npm-package-name": "^4.0.0"
@@ -48,5 +50,5 @@
48
50
  "@types/prompts": "^2.0.14",
49
51
  "expo-module-scripts": "^2.0.0"
50
52
  },
51
- "gitHead": "c6678c65b68e45062d49a2deea8e822f69388278"
53
+ "gitHead": "c49ce1b2b24471f95a26dfc172d513ac0dde32ce"
52
54
  }
@@ -6,12 +6,12 @@ import ejs from 'ejs';
6
6
  import fs from 'fs-extra';
7
7
  import path from 'path';
8
8
  import prompts from 'prompts';
9
- import validateNpmPackage from 'validate-npm-package-name';
10
9
 
11
10
  import { createExampleApp } from './createExampleApp';
12
11
  import { installDependencies } from './packageManager';
12
+ import { getSlugPrompt, getSubstitutionDataPrompts } from './prompts';
13
13
  import { resolvePackageManager } from './resolvePackageManager';
14
- import { CommandOptions, CustomPromptObject, SubstitutionData } from './types';
14
+ import { CommandOptions, SubstitutionData } from './types';
15
15
  import { newStep } from './utils';
16
16
 
17
17
  const packageJson = require('../package.json');
@@ -30,14 +30,19 @@ const IGNORES_PATHS = ['.DS_Store', 'build', 'node_modules', 'package.json'];
30
30
  * @param command An object from `commander`.
31
31
  */
32
32
  async function main(target: string | undefined, options: CommandOptions) {
33
- const targetDir = target ? path.join(CWD, target) : CWD;
33
+ const slug = await askForPackageSlugAsync(target);
34
+ const targetDir = path.join(CWD, target || slug);
34
35
 
35
36
  await fs.ensureDir(targetDir);
36
37
  await confirmTargetDirAsync(targetDir);
37
38
 
38
39
  options.target = targetDir;
39
40
 
40
- const data = await askForSubstitutionDataAsync(targetDir, options);
41
+ const data = await askForSubstitutionDataAsync(slug);
42
+
43
+ // Make one line break between prompts and progress logs
44
+ console.log();
45
+
41
46
  const packageManager = await resolvePackageManager();
42
47
  const packagePath = options.source
43
48
  ? path.join(CWD, options.source)
@@ -115,18 +120,6 @@ async function getNpmTarballUrl(packageName: string, version: string = 'latest')
115
120
  return stdout.trim();
116
121
  }
117
122
 
118
- /**
119
- * Gets the username of currently logged in user. Used as a default in the prompt asking for the module author.
120
- */
121
- async function npmWhoamiAsync(targetDir: string): Promise<string | null> {
122
- try {
123
- const { stdout } = await spawnAsync('npm', ['whoami'], { cwd: targetDir });
124
- return stdout.trim();
125
- } catch {
126
- return null;
127
- }
128
- }
129
-
130
123
  /**
131
124
  * Downloads the template from NPM registry.
132
125
  */
@@ -171,80 +164,37 @@ async function createModuleFromTemplate(
171
164
  }
172
165
  }
173
166
 
167
+ /**
168
+ * Asks the user for the package slug (npm package name).
169
+ */
170
+ async function askForPackageSlugAsync(customTargetPath?: string): Promise<string> {
171
+ const { slug } = await prompts(getSlugPrompt(customTargetPath), {
172
+ onCancel: () => process.exit(0),
173
+ });
174
+ return slug;
175
+ }
176
+
174
177
  /**
175
178
  * Asks the user for some data necessary to render the template.
176
179
  * Some values may already be provided by command options, the prompt is skipped in that case.
177
180
  */
178
- async function askForSubstitutionDataAsync(
179
- targetDir: string,
180
- options: CommandOptions
181
- ): Promise<SubstitutionData> {
182
- const defaultPackageSlug = path.basename(targetDir);
183
- const useDefaultSlug = options.target && validateNpmPackage(defaultPackageSlug);
184
- const defaultProjectName = defaultPackageSlug
185
- .replace(/^./, (match) => match.toUpperCase())
186
- .replace(/\W+(\w)/g, (_, p1) => p1.toUpperCase());
187
-
188
- const promptQueries: CustomPromptObject[] = [
189
- {
190
- type: 'text',
191
- name: 'slug',
192
- message: 'What is the package slug?',
193
- initial: defaultPackageSlug,
194
- resolvedValue: useDefaultSlug ? defaultPackageSlug : null,
195
- validate: (input) =>
196
- validateNpmPackage(input).validForNewPackages || 'Must be a valid npm package name',
197
- },
198
- {
199
- type: 'text',
200
- name: 'name',
201
- message: 'What is the project name?',
202
- initial: defaultProjectName,
203
- },
204
- {
205
- type: 'text',
206
- name: 'description',
207
- message: 'How would you describe the module?',
208
- validate: (input) => !!input || 'Cannot be empty',
209
- },
210
- {
211
- type: 'text',
212
- name: 'package',
213
- message: 'What is the Android package name?',
214
- initial: `expo.modules.${defaultPackageSlug.replace(/\W/g, '').toLowerCase()}`,
215
- },
216
- {
217
- type: 'text',
218
- name: 'author',
219
- message: 'Who is the author?',
220
- initial: (await npmWhoamiAsync(targetDir)) ?? '',
221
- },
222
- {
223
- type: 'text',
224
- name: 'license',
225
- message: 'What is the license?',
226
- initial: 'MIT',
227
- },
228
- {
229
- type: 'text',
230
- name: 'repo',
231
- message: 'What is the repository URL?',
232
- validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
233
- },
234
- ];
181
+ async function askForSubstitutionDataAsync(slug: string): Promise<SubstitutionData> {
182
+ const promptQueries = await getSubstitutionDataPrompts(slug);
235
183
 
236
184
  // Stop the process when the user cancels/exits the prompt.
237
185
  const onCancel = () => {
238
186
  process.exit(0);
239
187
  };
240
188
 
241
- const answers: Record<string, string> = {};
242
- for (const query of promptQueries) {
243
- const { name, resolvedValue } = query;
244
- answers[name] = resolvedValue ?? options[name] ?? (await prompts(query, { onCancel }))[name];
245
- }
246
-
247
- const { slug, name, description, package: projectPackage, author, license, repo } = answers;
189
+ const {
190
+ name,
191
+ description,
192
+ package: projectPackage,
193
+ authorName,
194
+ authorEmail,
195
+ authorUrl,
196
+ repo,
197
+ } = await prompts(promptQueries, { onCancel });
248
198
 
249
199
  return {
250
200
  project: {
@@ -254,8 +204,8 @@ async function askForSubstitutionDataAsync(
254
204
  description,
255
205
  package: projectPackage,
256
206
  },
257
- author,
258
- license,
207
+ author: `${authorName} <${authorEmail}> (${authorUrl})`,
208
+ license: 'MIT',
259
209
  repo,
260
210
  };
261
211
  }
@@ -275,7 +225,7 @@ async function confirmTargetDirAsync(targetDir: string): Promise<void> {
275
225
  name: 'shouldContinue',
276
226
  message: `The target directory ${chalk.magenta(
277
227
  targetDir
278
- )} is not empty.\nDo you want to continue anyway?`,
228
+ )} is not empty, do you want to continue anyway?`,
279
229
  initial: true,
280
230
  },
281
231
  {
@@ -293,17 +243,11 @@ program
293
243
  .name(packageJson.name)
294
244
  .version(packageJson.version)
295
245
  .description(packageJson.description)
296
- .arguments('[target_dir]')
246
+ .arguments('[path]')
297
247
  .option(
298
248
  '-s, --source <source_dir>',
299
249
  'Local path to the template. By default it downloads `expo-module-template` from NPM.'
300
250
  )
301
- .option('-n, --name <module_name>', 'Name of the native module.')
302
- .option('-d, --description <description>', 'Description of the module.')
303
- .option('-p, --package <package>', 'The Android package name.')
304
- .option('-a, --author <author>', 'The author name.')
305
- .option('-l, --license <license>', 'The license that the module is distributed with.')
306
- .option('-r, --repo <repo_url>', 'The URL to the repository.')
307
251
  .option('--with-readme', 'Whether to include README.md file.', false)
308
252
  .option('--with-changelog', 'Whether to include CHANGELOG.md file.', false)
309
253
  .option('--no-example', 'Whether to skip creating the example app.', false)
@@ -18,26 +18,32 @@ export async function createExampleApp(
18
18
  targetDir: string,
19
19
  packageManager: PackageManagerName
20
20
  ): Promise<void> {
21
+ // Package name for the example app
21
22
  const exampleProjectSlug = `${data.project.slug}-example`;
22
23
 
24
+ // `expo init` creates a new folder with the same name as the project slug
25
+ const appTmpPath = path.join(targetDir, exampleProjectSlug);
26
+
27
+ // Path to the target example dir
28
+ const appTargetPath = path.join(targetDir, 'example');
29
+
30
+ if (!(await fs.pathExists(appTargetPath))) {
31
+ // The template doesn't include the example app, so just skip this phase
32
+ return;
33
+ }
34
+
23
35
  await newStep('Initializing the example app', async (step) => {
24
36
  await spawnAsync(
25
- 'expo',
26
- ['init', exampleProjectSlug, '--template', 'expo-template-blank-typescript'],
37
+ packageManager,
38
+ ['create', 'expo-app', '--', exampleProjectSlug, '--template', 'blank-typescript', '--yes'],
27
39
  {
28
40
  cwd: targetDir,
29
- stdio: ['ignore', 'ignore', 'inherit'],
41
+ stdio: 'ignore',
30
42
  }
31
43
  );
32
44
  step.succeed('Initialized the example app');
33
45
  });
34
46
 
35
- // `expo init` creates a new folder with the same name as the project slug
36
- const appTmpPath = path.join(targetDir, exampleProjectSlug);
37
-
38
- // Path to the target example dir
39
- const appTargetPath = path.join(targetDir, 'example');
40
-
41
47
  await newStep('Configuring the example app', async (step) => {
42
48
  // "example" folder already exists and contains template files,
43
49
  // that should replace these created by `expo init`.
package/src/prompts.ts ADDED
@@ -0,0 +1,86 @@
1
+ import path from 'path';
2
+ import { Answers, PromptObject } from 'prompts';
3
+ import validateNpmPackage from 'validate-npm-package-name';
4
+
5
+ import { findGitHubEmail, findGitHubProfileUrl, findMyName, guessRepoUrl } from './utils';
6
+
7
+ export function getSlugPrompt(customTargetPath?: string | null): PromptObject<string> {
8
+ const targetBasename = customTargetPath && path.basename(customTargetPath);
9
+ const initial =
10
+ targetBasename && validateNpmPackage(targetBasename).validForNewPackages
11
+ ? targetBasename
12
+ : 'my-module';
13
+
14
+ return {
15
+ type: 'text',
16
+ name: 'slug',
17
+ message: 'What is the name of the npm package?',
18
+ initial,
19
+ validate: (input) =>
20
+ validateNpmPackage(input).validForNewPackages || 'Must be a valid npm package name',
21
+ };
22
+ }
23
+
24
+ export async function getSubstitutionDataPrompts(slug: string): Promise<PromptObject<string>[]> {
25
+ return [
26
+ {
27
+ type: 'text',
28
+ name: 'name',
29
+ message: 'What is the native module name?',
30
+ initial: () => {
31
+ return slug
32
+ .replace(/^@/, '')
33
+ .replace(/^./, (match) => match.toUpperCase())
34
+ .replace(/\W+(\w)/g, (_, p1) => p1.toUpperCase());
35
+ },
36
+ validate: (input) => !!input || 'The native module name cannot be empty',
37
+ },
38
+ {
39
+ type: 'text',
40
+ name: 'description',
41
+ message: 'How would you describe the module?',
42
+ initial: 'My new module',
43
+ validate: (input) => !!input || 'The description cannot be empty',
44
+ },
45
+ {
46
+ type: 'text',
47
+ name: 'package',
48
+ message: 'What is the Android package name?',
49
+ initial: () => {
50
+ const namespace = slug
51
+ .replace(/\W/g, '')
52
+ .replace(/^(expo|reactnative)/, '')
53
+ .toLowerCase();
54
+ return `expo.modules.${namespace}`;
55
+ },
56
+ validate: (input) => !!input || 'The Android package name cannot be empty',
57
+ },
58
+ {
59
+ type: 'text',
60
+ name: 'authorName',
61
+ message: 'What is the name of the package author?',
62
+ initial: await findMyName(),
63
+ validate: (input) => !!input || 'Cannot be empty',
64
+ },
65
+ {
66
+ type: 'text',
67
+ name: 'authorEmail',
68
+ message: 'What is the email address of the author?',
69
+ initial: await findGitHubEmail(),
70
+ },
71
+ {
72
+ type: 'text',
73
+ name: 'authorUrl',
74
+ message: "What is the URL to the author's GitHub profile?",
75
+ initial: async (_, answers: Answers<string>) =>
76
+ await findGitHubProfileUrl(answers.authorEmail),
77
+ },
78
+ {
79
+ type: 'text',
80
+ name: 'repo',
81
+ message: 'What is the URL for the repository?',
82
+ initial: async (_, answers: Answers<string>) => await guessRepoUrl(answers.authorUrl, slug),
83
+ validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
84
+ },
85
+ ];
86
+ }
package/src/types.ts CHANGED
@@ -6,12 +6,6 @@ import { PromptObject } from 'prompts';
6
6
  export type CommandOptions = {
7
7
  target: string;
8
8
  source?: string;
9
- name?: string;
10
- description?: string;
11
- package?: string;
12
- author?: string;
13
- license?: string;
14
- repo?: string;
15
9
  withReadme: boolean;
16
10
  withChangelog: boolean;
17
11
  example: boolean;
@@ -37,3 +31,5 @@ export type CustomPromptObject = PromptObject & {
37
31
  name: string;
38
32
  resolvedValue?: string | null;
39
33
  };
34
+
35
+ export type Answers = Record<string, string>;
package/src/utils.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import chalk from 'chalk';
2
+ import spawn from 'cross-spawn';
3
+ import githubUsername from 'github-username';
2
4
  import ora from 'ora';
3
5
 
4
6
  export type StepOptions = ora.Options;
@@ -26,3 +28,48 @@ export async function newStep<Result>(
26
28
  process.exit(1);
27
29
  }
28
30
  }
31
+
32
+ /**
33
+ * Finds user's name by reading it from the git config.
34
+ */
35
+ export async function findMyName(): Promise<string> {
36
+ try {
37
+ return spawn.sync('git', ['config', '--get', 'user.name']).stdout.toString().trim();
38
+ } catch {
39
+ return '';
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Finds user's email by reading it from the git config.
45
+ */
46
+ export async function findGitHubEmail(): Promise<string> {
47
+ try {
48
+ return spawn.sync('git', ['config', '--get', 'user.email']).stdout.toString().trim();
49
+ } catch {
50
+ return '';
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Get the GitHub username from an email address if the email can be found in any commits on GitHub.
56
+ */
57
+ export async function findGitHubProfileUrl(email: string): Promise<string> {
58
+ try {
59
+ const username = (await githubUsername(email)) ?? '';
60
+ return `https://github.com/${username}`;
61
+ } catch {
62
+ return '';
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Guesses the repository URL based on the author profile URL and the package slug.
68
+ */
69
+ export async function guessRepoUrl(authorUrl: string, slug: string) {
70
+ if (/^https?:\/\/github.com\/[^/]+/.test(authorUrl)) {
71
+ const normalizedSlug = slug.replace(/^@/, '').replace(/\//g, '-');
72
+ return `${authorUrl}/${normalizedSlug}`;
73
+ }
74
+ return '';
75
+ }