create-expo-module 0.5.8 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/create-expo-module.js +7 -1
- package/build/create-expo-module.js.map +1 -1
- package/build/telemetry.d.ts +20 -0
- package/build/telemetry.js +94 -0
- package/build/telemetry.js.map +1 -0
- package/package.json +5 -2
- package/src/create-expo-module.ts +8 -1
- package/src/telemetry.ts +111 -0
|
@@ -16,6 +16,7 @@ const createExampleApp_1 = require("./createExampleApp");
|
|
|
16
16
|
const packageManager_1 = require("./packageManager");
|
|
17
17
|
const prompts_2 = require("./prompts");
|
|
18
18
|
const resolvePackageManager_1 = require("./resolvePackageManager");
|
|
19
|
+
const telemetry_1 = require("./telemetry");
|
|
19
20
|
const utils_1 = require("./utils");
|
|
20
21
|
const debug = require('debug')('create-expo-module:main');
|
|
21
22
|
const packageJson = require('../package.json');
|
|
@@ -54,6 +55,7 @@ async function main(target, options) {
|
|
|
54
55
|
const packagePath = options.source
|
|
55
56
|
? path_1.default.join(CWD, options.source)
|
|
56
57
|
: await downloadPackageAsync(targetDir);
|
|
58
|
+
(0, telemetry_1.logEventAsync)((0, telemetry_1.eventCreateExpoModule)(packageManager, options));
|
|
57
59
|
await (0, utils_1.newStep)('Creating the module from template files', async (step) => {
|
|
58
60
|
await createModuleFromTemplate(packagePath, targetDir, data);
|
|
59
61
|
step.succeed('Created the module from template files');
|
|
@@ -252,5 +254,9 @@ program
|
|
|
252
254
|
.option('--with-changelog', 'Whether to include CHANGELOG.md file.', false)
|
|
253
255
|
.option('--no-example', 'Whether to skip creating the example app.', false)
|
|
254
256
|
.action(main);
|
|
255
|
-
program
|
|
257
|
+
program
|
|
258
|
+
.hook('postAction', async () => {
|
|
259
|
+
await (0, telemetry_1.getTelemetryClient)().flush?.();
|
|
260
|
+
})
|
|
261
|
+
.parse(process.argv);
|
|
256
262
|
//# sourceMappingURL=create-expo-module.js.map
|
|
@@ -1 +1 @@
|
|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,CAAC,SAAS,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,6CAA6C,CAAC,CAAC;AAC/F,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 { boolish } from 'getenv';\nimport path from 'path';\nimport prompts from 'prompts';\n\nimport { createExampleApp } from './createExampleApp';\nimport { installDependencies } from './packageManager';\nimport { getSlugPrompt, getSubstitutionDataPrompts } from './prompts';\nimport {\n formatRunCommand,\n PackageManagerName,\n resolvePackageManager,\n} from './resolvePackageManager';\nimport { CommandOptions, SubstitutionData } from './types';\nimport { newStep } from './utils';\n\nconst debug = require('debug')('create-expo-module:main') as typeof console.log;\nconst packageJson = require('../package.json');\n\n// Opt in to using beta versions\nconst EXPO_BETA = boolish('EXPO_BETA', false);\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 = [\n '.DS_Store',\n 'build',\n 'node_modules',\n 'package.json',\n '.npmignore',\n '.gitignore',\n];\n\n// Url to the documentation on Expo Modules\nconst DOCS_URL = 'https://docs.expo.dev/modules';\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('Creating an empty Git repository', async (step) => {\n try {\n await spawnAsync('git', ['init'], {\n cwd: targetDir,\n stdio: 'ignore',\n });\n step.succeed('Created an empty Git repository');\n } catch (e: any) {\n step.fail(e.toString());\n }\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 printFurtherInstructions(targetDir, packageManager, options.example);\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 debug(`Using module template ${chalk.bold(packageName)}@${chalk.bold(version)}`);\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(\n 'expo-module-template',\n EXPO_BETA ? 'next' : 'latest'\n );\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\nfunction handleSuffix(name: string, suffix: string): string {\n if (name.endsWith(suffix)) {\n return name;\n }\n return `${name}${suffix}`;\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(/\\./g, 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 moduleName: handleSuffix(name, 'Module'),\n viewName: handleSuffix(name, 'View'),\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\n/**\n * Prints how the user can follow up once the script finishes creating the module.\n */\nfunction printFurtherInstructions(\n targetDir: string,\n packageManager: PackageManagerName,\n includesExample: boolean\n) {\n if (includesExample) {\n const commands = [\n `cd ${path.relative(CWD, targetDir)}`,\n formatRunCommand(packageManager, 'open:ios'),\n formatRunCommand(packageManager, 'open:android'),\n ];\n\n console.log();\n console.log(\n 'To start developing your module, navigate to the directory and open iOS and Android projects of the example app'\n );\n commands.forEach((command) => console.log(chalk.gray('>'), chalk.bold(command)));\n console.log();\n }\n console.log(`Visit ${chalk.blue.bold(DOCS_URL)} for the documentation on Expo Modules APIs`);\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"]}
|
|
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,mCAAiC;AACjC,gDAAwB;AACxB,sDAA8B;AAE9B,yDAAsD;AACtD,qDAAuD;AACvD,uCAAsE;AACtE,mEAIiC;AACjC,2CAAuF;AAEvF,mCAAkC;AAElC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAuB,CAAC;AAChF,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE/C,gCAAgC;AAChC,MAAM,SAAS,GAAG,IAAA,gBAAO,EAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AAE9C,oFAAoF;AACpF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAElD,iEAAiE;AACjE,yDAAyD;AACzD,MAAM,aAAa,GAAG;IACpB,WAAW;IACX,OAAO;IACP,cAAc;IACd,cAAc;IACd,YA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AM,IAAA,8BAAkB,GAAE,CAAC,KAAK,EAAE,EAAE,CAAC;AACvC,CAAC,CAAC;KACD,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 { boolish } from 'getenv';\nimport path from 'path';\nimport prompts from 'prompts';\n\nimport { createExampleApp } from './createExampleApp';\nimport { installDependencies } from './packageManager';\nimport { getSlugPrompt, getSubstitutionDataPrompts } from './prompts';\nimport {\n formatRunCommand,\n PackageManagerName,\n resolvePackageManager,\n} from './resolvePackageManager';\nimport { eventCreateExpoModule, getTelemetryClient, logEventAsync } from './telemetry';\nimport { CommandOptions, SubstitutionData } from './types';\nimport { newStep } from './utils';\n\nconst debug = require('debug')('create-expo-module:main') as typeof console.log;\nconst packageJson = require('../package.json');\n\n// Opt in to using beta versions\nconst EXPO_BETA = boolish('EXPO_BETA', false);\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 = [\n '.DS_Store',\n 'build',\n 'node_modules',\n 'package.json',\n '.npmignore',\n '.gitignore',\n];\n\n// Url to the documentation on Expo Modules\nconst DOCS_URL = 'https://docs.expo.dev/modules';\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 logEventAsync(eventCreateExpoModule(packageManager, options));\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('Creating an empty Git repository', async (step) => {\n try {\n await spawnAsync('git', ['init'], {\n cwd: targetDir,\n stdio: 'ignore',\n });\n step.succeed('Created an empty Git repository');\n } catch (e: any) {\n step.fail(e.toString());\n }\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 printFurtherInstructions(targetDir, packageManager, options.example);\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 debug(`Using module template ${chalk.bold(packageName)}@${chalk.bold(version)}`);\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(\n 'expo-module-template',\n EXPO_BETA ? 'next' : 'latest'\n );\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\nfunction handleSuffix(name: string, suffix: string): string {\n if (name.endsWith(suffix)) {\n return name;\n }\n return `${name}${suffix}`;\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(/\\./g, 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 moduleName: handleSuffix(name, 'Module'),\n viewName: handleSuffix(name, 'View'),\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\n/**\n * Prints how the user can follow up once the script finishes creating the module.\n */\nfunction printFurtherInstructions(\n targetDir: string,\n packageManager: PackageManagerName,\n includesExample: boolean\n) {\n if (includesExample) {\n const commands = [\n `cd ${path.relative(CWD, targetDir)}`,\n formatRunCommand(packageManager, 'open:ios'),\n formatRunCommand(packageManager, 'open:android'),\n ];\n\n console.log();\n console.log(\n 'To start developing your module, navigate to the directory and open iOS and Android projects of the example app'\n );\n commands.forEach((command) => console.log(chalk.gray('>'), chalk.bold(command)));\n console.log();\n }\n console.log(`Visit ${chalk.blue.bold(DOCS_URL)} for the documentation on Expo Modules APIs`);\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\n .hook('postAction', async () => {\n await getTelemetryClient().flush?.();\n })\n .parse(process.argv);\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import TelemetryClient from '@expo/rudder-sdk-node';
|
|
2
|
+
import { CommandOptions } from './types';
|
|
3
|
+
export declare function getTelemetryClient(): TelemetryClient;
|
|
4
|
+
type Event = {
|
|
5
|
+
event: 'create expo module';
|
|
6
|
+
properties: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
export declare function logEventAsync(event: Event): Promise<void>;
|
|
9
|
+
export declare function eventCreateExpoModule(packageManager: string, options: CommandOptions): {
|
|
10
|
+
event: "create expo module";
|
|
11
|
+
properties: {
|
|
12
|
+
nodeVersion: string;
|
|
13
|
+
packageManager: string;
|
|
14
|
+
withTemplate: boolean;
|
|
15
|
+
withReadme: boolean;
|
|
16
|
+
withChangelog: boolean;
|
|
17
|
+
withExample: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
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.eventCreateExpoModule = exports.logEventAsync = exports.getTelemetryClient = void 0;
|
|
7
|
+
const getUserState_1 = require("@expo/config/build/getUserState");
|
|
8
|
+
const json_file_1 = __importDefault(require("@expo/json-file"));
|
|
9
|
+
const rudder_sdk_node_1 = __importDefault(require("@expo/rudder-sdk-node"));
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const getenv_1 = require("getenv");
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
const packageJson = require('../package.json');
|
|
14
|
+
/** If telemetry is disabled by the user */
|
|
15
|
+
const EXPO_NO_TELEMETRY = (0, getenv_1.boolish)('EXPO_NO_TELEMETRY', false);
|
|
16
|
+
/** If the tool is running in a sanboxed environment, either staging or local envs */
|
|
17
|
+
const EXPO_SANDBOX = (0, getenv_1.boolish)('EXPO_STAGING', false) || (0, getenv_1.boolish)('EXPO_LOCAL', false);
|
|
18
|
+
/** The telemetry client instance to use */
|
|
19
|
+
let client = null;
|
|
20
|
+
/** The anonymous identity ID */
|
|
21
|
+
let telemetryId = null;
|
|
22
|
+
function getTelemetryClient() {
|
|
23
|
+
if (!client) {
|
|
24
|
+
client = new rudder_sdk_node_1.default(EXPO_SANDBOX ? '24TKICqYKilXM480mA7ktgVDdea' : '24TKR7CQAaGgIrLTgu3Fp4OdOkI', // expo unified,
|
|
25
|
+
'https://cdp.expo.dev/v1/batch', {
|
|
26
|
+
flushInterval: 300,
|
|
27
|
+
});
|
|
28
|
+
// Empty the telemetry queue on exit
|
|
29
|
+
process.on('SIGINT', () => client?.flush?.());
|
|
30
|
+
process.on('SIGTERM', () => client?.flush?.());
|
|
31
|
+
}
|
|
32
|
+
return client;
|
|
33
|
+
}
|
|
34
|
+
exports.getTelemetryClient = getTelemetryClient;
|
|
35
|
+
/** Get the randomly generated anonymous ID from the persistent storage, see @expo/cli */
|
|
36
|
+
async function getTelemetryIdAsync() {
|
|
37
|
+
const settings = new json_file_1.default((0, getUserState_1.getUserStatePath)(), {
|
|
38
|
+
ensureDir: true,
|
|
39
|
+
jsonParseErrorDefault: {},
|
|
40
|
+
cantReadFileDefault: {},
|
|
41
|
+
});
|
|
42
|
+
let id = await settings.getAsync('uuid', null);
|
|
43
|
+
if (!id) {
|
|
44
|
+
id = crypto_1.default.randomUUID();
|
|
45
|
+
await settings.setAsync('uuid', id);
|
|
46
|
+
}
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
function getTelemetryContext() {
|
|
50
|
+
const PLATFORM_NAMES = {
|
|
51
|
+
darwin: 'Mac',
|
|
52
|
+
win32: 'Windows',
|
|
53
|
+
linux: 'Linux',
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
os: { name: PLATFORM_NAMES[os_1.default.platform()] ?? os_1.default.platform(), version: os_1.default.release() },
|
|
57
|
+
app: { name: 'create-expo-module', version: packageJson.version ?? undefined },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function logEventAsync(event) {
|
|
61
|
+
if (EXPO_NO_TELEMETRY) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!telemetryId) {
|
|
65
|
+
telemetryId = await getTelemetryIdAsync();
|
|
66
|
+
getTelemetryClient().identify({ anonymousId: telemetryId });
|
|
67
|
+
}
|
|
68
|
+
const commonProperties = {
|
|
69
|
+
source: 'create-expo-module',
|
|
70
|
+
source_version: packageJson.version ?? undefined,
|
|
71
|
+
};
|
|
72
|
+
getTelemetryClient().track({
|
|
73
|
+
...event,
|
|
74
|
+
properties: { ...event.properties, ...commonProperties },
|
|
75
|
+
anonymousId: telemetryId,
|
|
76
|
+
context: getTelemetryContext(),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.logEventAsync = logEventAsync;
|
|
80
|
+
function eventCreateExpoModule(packageManager, options) {
|
|
81
|
+
return {
|
|
82
|
+
event: 'create expo module',
|
|
83
|
+
properties: {
|
|
84
|
+
nodeVersion: process.version,
|
|
85
|
+
packageManager,
|
|
86
|
+
withTemplate: !!options.source,
|
|
87
|
+
withReadme: options.withReadme,
|
|
88
|
+
withChangelog: options.withChangelog,
|
|
89
|
+
withExample: options.example,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
exports.eventCreateExpoModule = eventCreateExpoModule;
|
|
94
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAmE;AACnE,gEAAuC;AACvC,4EAAoD;AACpD,oDAA4B;AAC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AuB;IACnF,OAAO;QACL,KAAK,EAAE,oBAA6B;QACpC,UAAU,EAAE;YACV,WAAW,EAAE,OAAO,CAAC,OAAO;YAC5B,cAAc;YACd,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM;YAC9B,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,WAAW,EAAE,OAAO,CAAC,OAAO;SAC7B;KACF,CAAC;AACJ,CAAC;AAZD,sDAYC","sourcesContent":["import { getUserStatePath } from '@expo/config/build/getUserState';\nimport JsonFile from '@expo/json-file';\nimport TelemetryClient from '@expo/rudder-sdk-node';\nimport crypto from 'crypto';\nimport { boolish } from 'getenv';\nimport os from 'os';\n\nimport { CommandOptions } from './types';\n\nconst packageJson = require('../package.json');\n\n/** If telemetry is disabled by the user */\nconst EXPO_NO_TELEMETRY = boolish('EXPO_NO_TELEMETRY', false);\n/** If the tool is running in a sanboxed environment, either staging or local envs */\nconst EXPO_SANDBOX = boolish('EXPO_STAGING', false) || boolish('EXPO_LOCAL', false);\n\n/** The telemetry client instance to use */\nlet client: TelemetryClient | null = null;\n/** The anonymous identity ID */\nlet telemetryId: string | null = null;\n\nexport function getTelemetryClient() {\n if (!client) {\n client = new TelemetryClient(\n EXPO_SANDBOX ? '24TKICqYKilXM480mA7ktgVDdea' : '24TKR7CQAaGgIrLTgu3Fp4OdOkI', // expo unified,\n 'https://cdp.expo.dev/v1/batch',\n {\n flushInterval: 300,\n }\n );\n\n // Empty the telemetry queue on exit\n process.on('SIGINT', () => client?.flush?.());\n process.on('SIGTERM', () => client?.flush?.());\n }\n\n return client;\n}\n\n/** Get the randomly generated anonymous ID from the persistent storage, see @expo/cli */\nasync function getTelemetryIdAsync() {\n const settings = new JsonFile<{ uuid?: string }>(getUserStatePath(), {\n ensureDir: true,\n jsonParseErrorDefault: {},\n cantReadFileDefault: {},\n });\n\n let id = await settings.getAsync('uuid', null);\n\n if (!id) {\n id = crypto.randomUUID();\n await settings.setAsync('uuid', id);\n }\n\n return id;\n}\n\nfunction getTelemetryContext() {\n const PLATFORM_NAMES: Partial<Record<NodeJS.Platform, string>> = {\n darwin: 'Mac',\n win32: 'Windows',\n linux: 'Linux',\n };\n\n return {\n os: { name: PLATFORM_NAMES[os.platform()] ?? os.platform(), version: os.release() },\n app: { name: 'create-expo-module', version: packageJson.version ?? undefined },\n };\n}\n\ntype Event = {\n event: 'create expo module';\n properties: Record<string, any>;\n};\n\nexport async function logEventAsync(event: Event) {\n if (EXPO_NO_TELEMETRY) {\n return;\n }\n\n if (!telemetryId) {\n telemetryId = await getTelemetryIdAsync();\n getTelemetryClient().identify({ anonymousId: telemetryId });\n }\n\n const commonProperties = {\n source: 'create-expo-module',\n source_version: packageJson.version ?? undefined,\n };\n\n getTelemetryClient().track({\n ...event,\n properties: { ...event.properties, ...commonProperties },\n anonymousId: telemetryId,\n context: getTelemetryContext(),\n });\n}\n\nexport function eventCreateExpoModule(packageManager: string, options: CommandOptions) {\n return {\n event: 'create expo module' as const, // DO NOT EDIT, unless knowing what you are doing\n properties: {\n nodeVersion: process.version,\n packageManager,\n withTemplate: !!options.source,\n withReadme: options.withReadme,\n withChangelog: options.withChangelog,\n withExample: options.example,\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-expo-module",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
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",
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/expo/expo/tree/main/packages/expo",
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@expo/config": "~7.0.2",
|
|
37
|
+
"@expo/json-file": "^8.2.37",
|
|
36
38
|
"@expo/spawn-async": "^1.5.0",
|
|
39
|
+
"@expo/rudder-sdk-node": "^1.1.1",
|
|
37
40
|
"chalk": "^4.1.2",
|
|
38
41
|
"commander": "^8.3.0",
|
|
39
42
|
"cross-spawn": "^7.0.3",
|
|
@@ -53,5 +56,5 @@
|
|
|
53
56
|
"@types/prompts": "^2.0.14",
|
|
54
57
|
"expo-module-scripts": "^3.0.0"
|
|
55
58
|
},
|
|
56
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "49fad2d7dd875e57bb35a3cc6f76609553596808"
|
|
57
60
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
PackageManagerName,
|
|
17
17
|
resolvePackageManager,
|
|
18
18
|
} from './resolvePackageManager';
|
|
19
|
+
import { eventCreateExpoModule, getTelemetryClient, logEventAsync } from './telemetry';
|
|
19
20
|
import { CommandOptions, SubstitutionData } from './types';
|
|
20
21
|
import { newStep } from './utils';
|
|
21
22
|
|
|
@@ -67,6 +68,8 @@ async function main(target: string | undefined, options: CommandOptions) {
|
|
|
67
68
|
? path.join(CWD, options.source)
|
|
68
69
|
: await downloadPackageAsync(targetDir);
|
|
69
70
|
|
|
71
|
+
logEventAsync(eventCreateExpoModule(packageManager, options));
|
|
72
|
+
|
|
70
73
|
await newStep('Creating the module from template files', async (step) => {
|
|
71
74
|
await createModuleFromTemplate(packagePath, targetDir, data);
|
|
72
75
|
step.succeed('Created the module from template files');
|
|
@@ -324,4 +327,8 @@ program
|
|
|
324
327
|
.option('--no-example', 'Whether to skip creating the example app.', false)
|
|
325
328
|
.action(main);
|
|
326
329
|
|
|
327
|
-
program
|
|
330
|
+
program
|
|
331
|
+
.hook('postAction', async () => {
|
|
332
|
+
await getTelemetryClient().flush?.();
|
|
333
|
+
})
|
|
334
|
+
.parse(process.argv);
|
package/src/telemetry.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { getUserStatePath } from '@expo/config/build/getUserState';
|
|
2
|
+
import JsonFile from '@expo/json-file';
|
|
3
|
+
import TelemetryClient from '@expo/rudder-sdk-node';
|
|
4
|
+
import crypto from 'crypto';
|
|
5
|
+
import { boolish } from 'getenv';
|
|
6
|
+
import os from 'os';
|
|
7
|
+
|
|
8
|
+
import { CommandOptions } from './types';
|
|
9
|
+
|
|
10
|
+
const packageJson = require('../package.json');
|
|
11
|
+
|
|
12
|
+
/** If telemetry is disabled by the user */
|
|
13
|
+
const EXPO_NO_TELEMETRY = boolish('EXPO_NO_TELEMETRY', false);
|
|
14
|
+
/** If the tool is running in a sanboxed environment, either staging or local envs */
|
|
15
|
+
const EXPO_SANDBOX = boolish('EXPO_STAGING', false) || boolish('EXPO_LOCAL', false);
|
|
16
|
+
|
|
17
|
+
/** The telemetry client instance to use */
|
|
18
|
+
let client: TelemetryClient | null = null;
|
|
19
|
+
/** The anonymous identity ID */
|
|
20
|
+
let telemetryId: string | null = null;
|
|
21
|
+
|
|
22
|
+
export function getTelemetryClient() {
|
|
23
|
+
if (!client) {
|
|
24
|
+
client = new TelemetryClient(
|
|
25
|
+
EXPO_SANDBOX ? '24TKICqYKilXM480mA7ktgVDdea' : '24TKR7CQAaGgIrLTgu3Fp4OdOkI', // expo unified,
|
|
26
|
+
'https://cdp.expo.dev/v1/batch',
|
|
27
|
+
{
|
|
28
|
+
flushInterval: 300,
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// Empty the telemetry queue on exit
|
|
33
|
+
process.on('SIGINT', () => client?.flush?.());
|
|
34
|
+
process.on('SIGTERM', () => client?.flush?.());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return client;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Get the randomly generated anonymous ID from the persistent storage, see @expo/cli */
|
|
41
|
+
async function getTelemetryIdAsync() {
|
|
42
|
+
const settings = new JsonFile<{ uuid?: string }>(getUserStatePath(), {
|
|
43
|
+
ensureDir: true,
|
|
44
|
+
jsonParseErrorDefault: {},
|
|
45
|
+
cantReadFileDefault: {},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
let id = await settings.getAsync('uuid', null);
|
|
49
|
+
|
|
50
|
+
if (!id) {
|
|
51
|
+
id = crypto.randomUUID();
|
|
52
|
+
await settings.setAsync('uuid', id);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return id;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getTelemetryContext() {
|
|
59
|
+
const PLATFORM_NAMES: Partial<Record<NodeJS.Platform, string>> = {
|
|
60
|
+
darwin: 'Mac',
|
|
61
|
+
win32: 'Windows',
|
|
62
|
+
linux: 'Linux',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
os: { name: PLATFORM_NAMES[os.platform()] ?? os.platform(), version: os.release() },
|
|
67
|
+
app: { name: 'create-expo-module', version: packageJson.version ?? undefined },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type Event = {
|
|
72
|
+
event: 'create expo module';
|
|
73
|
+
properties: Record<string, any>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export async function logEventAsync(event: Event) {
|
|
77
|
+
if (EXPO_NO_TELEMETRY) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!telemetryId) {
|
|
82
|
+
telemetryId = await getTelemetryIdAsync();
|
|
83
|
+
getTelemetryClient().identify({ anonymousId: telemetryId });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const commonProperties = {
|
|
87
|
+
source: 'create-expo-module',
|
|
88
|
+
source_version: packageJson.version ?? undefined,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
getTelemetryClient().track({
|
|
92
|
+
...event,
|
|
93
|
+
properties: { ...event.properties, ...commonProperties },
|
|
94
|
+
anonymousId: telemetryId,
|
|
95
|
+
context: getTelemetryContext(),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function eventCreateExpoModule(packageManager: string, options: CommandOptions) {
|
|
100
|
+
return {
|
|
101
|
+
event: 'create expo module' as const, // DO NOT EDIT, unless knowing what you are doing
|
|
102
|
+
properties: {
|
|
103
|
+
nodeVersion: process.version,
|
|
104
|
+
packageManager,
|
|
105
|
+
withTemplate: !!options.source,
|
|
106
|
+
withReadme: options.withReadme,
|
|
107
|
+
withChangelog: options.withChangelog,
|
|
108
|
+
withExample: options.example,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|