create-expo-module 0.3.0 → 0.4.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.
- package/build/create-expo-module.js +55 -109
- package/build/create-expo-module.js.map +1 -1
- package/build/createExampleApp.d.ts +6 -0
- package/build/createExampleApp.js +130 -0
- package/build/createExampleApp.js.map +1 -0
- package/build/packageManager.d.ts +2 -0
- package/build/packageManager.js +15 -0
- package/build/packageManager.js.map +1 -0
- package/build/prompts.d.ts +2 -0
- package/build/prompts.js +80 -0
- package/build/prompts.js.map +1 -0
- package/build/types.d.ts +31 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/utils.d.ts +19 -0
- package/build/utils.js +79 -0
- package/build/utils.js.map +1 -0
- package/package.json +7 -3
- package/src/create-expo-module.ts +77 -156
- package/src/createExampleApp.ts +159 -0
- package/src/packageManager.ts +14 -0
- package/src/prompts.ts +80 -0
- package/src/types.ts +35 -0
- package/src/utils.ts +75 -0
|
@@ -11,7 +11,11 @@ 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 createExampleApp_1 = require("./createExampleApp");
|
|
15
|
+
const packageManager_1 = require("./packageManager");
|
|
16
|
+
const prompts_2 = __importDefault(require("./prompts"));
|
|
14
17
|
const resolvePackageManager_1 = require("./resolvePackageManager");
|
|
18
|
+
const utils_1 = require("./utils");
|
|
15
19
|
const packageJson = require('../package.json');
|
|
16
20
|
// `yarn run` may change the current working dir, then we should use `INIT_CWD` env.
|
|
17
21
|
const CWD = process.env.INIT_CWD || process.cwd();
|
|
@@ -26,29 +30,31 @@ const IGNORES_PATHS = ['.DS_Store', 'build', 'node_modules', 'package.json'];
|
|
|
26
30
|
*/
|
|
27
31
|
async function main(target, options) {
|
|
28
32
|
const targetDir = target ? path_1.default.join(CWD, target) : CWD;
|
|
33
|
+
await fs_extra_1.default.ensureDir(targetDir);
|
|
29
34
|
await confirmTargetDirAsync(targetDir);
|
|
30
35
|
options.target = targetDir;
|
|
31
|
-
await
|
|
32
|
-
|
|
36
|
+
const data = await askForSubstitutionDataAsync(targetDir);
|
|
37
|
+
// Make one line break between prompts and progress logs
|
|
38
|
+
console.log();
|
|
33
39
|
const packageManager = await (0, resolvePackageManager_1.resolvePackageManager)();
|
|
34
40
|
const packagePath = options.source
|
|
35
41
|
? path_1.default.join(CWD, options.source)
|
|
36
42
|
: await downloadPackageAsync(targetDir);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
await (0, utils_1.newStep)('Creating the module from template files', async (step) => {
|
|
44
|
+
await createModuleFromTemplate(packagePath, targetDir, data);
|
|
45
|
+
step.succeed('Created the module from template files');
|
|
46
|
+
});
|
|
47
|
+
await (0, utils_1.newStep)('Installing module dependencies', async (step) => {
|
|
48
|
+
await (0, packageManager_1.installDependencies)(packageManager, targetDir);
|
|
49
|
+
step.succeed('Installed module dependencies');
|
|
50
|
+
});
|
|
51
|
+
await (0, utils_1.newStep)('Compiling TypeScript files', async (step) => {
|
|
52
|
+
await (0, spawn_async_1.default)(packageManager, ['run', 'build'], {
|
|
53
|
+
cwd: targetDir,
|
|
54
|
+
stdio: 'ignore',
|
|
45
55
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const template = await fs_extra_1.default.readFile(fromPath, { encoding: 'utf8' });
|
|
49
|
-
const renderedContent = ejs_1.default.render(template, data);
|
|
50
|
-
await fs_extra_1.default.outputFile(toPath, renderedContent, { encoding: 'utf8' });
|
|
51
|
-
}
|
|
56
|
+
step.succeed('Compiled TypeScript files');
|
|
57
|
+
});
|
|
52
58
|
if (!options.source) {
|
|
53
59
|
// Files in the downloaded tarball are wrapped in `package` dir.
|
|
54
60
|
// We should remove it after all.
|
|
@@ -60,8 +66,11 @@ async function main(target, options) {
|
|
|
60
66
|
if (!options.withChangelog) {
|
|
61
67
|
await fs_extra_1.default.remove(path_1.default.join(targetDir, 'CHANGELOG.md'));
|
|
62
68
|
}
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
if (options.example) {
|
|
70
|
+
// Create "example" folder
|
|
71
|
+
await (0, createExampleApp_1.createExampleApp)(data, targetDir, packageManager);
|
|
72
|
+
}
|
|
73
|
+
console.log();
|
|
65
74
|
console.log('✅ Successfully created Expo module');
|
|
66
75
|
}
|
|
67
76
|
/**
|
|
@@ -93,108 +102,50 @@ async function getNpmTarballUrl(packageName, version = 'latest') {
|
|
|
93
102
|
const { stdout } = await (0, spawn_async_1.default)('npm', ['view', `${packageName}@${version}`, 'dist.tarball']);
|
|
94
103
|
return stdout.trim();
|
|
95
104
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets the username of currently logged in user. Used as a default in the prompt asking for the module author.
|
|
98
|
-
*/
|
|
99
|
-
async function npmWhoamiAsync(targetDir) {
|
|
100
|
-
try {
|
|
101
|
-
const { stdout } = await (0, spawn_async_1.default)('npm', ['whoami'], { cwd: targetDir });
|
|
102
|
-
return stdout.trim();
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
105
|
/**
|
|
109
106
|
* Downloads the template from NPM registry.
|
|
110
107
|
*/
|
|
111
108
|
async function downloadPackageAsync(targetDir) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
return await (0, utils_1.newStep)('Downloading module template from npm', async (step) => {
|
|
110
|
+
const tarballUrl = await getNpmTarballUrl('expo-module-template');
|
|
111
|
+
await (0, download_tarball_1.default)({
|
|
112
|
+
url: tarballUrl,
|
|
113
|
+
dir: targetDir,
|
|
114
|
+
});
|
|
115
|
+
step.succeed('Downloaded module template from npm');
|
|
116
|
+
return path_1.default.join(targetDir, 'package');
|
|
117
117
|
});
|
|
118
|
-
return path_1.default.join(targetDir, 'package');
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
121
|
-
*
|
|
120
|
+
* Creates the module based on the `ejs` template (e.g. `expo-module-template` package).
|
|
122
121
|
*/
|
|
123
|
-
async function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
async function createModuleFromTemplate(templatePath, targetPath, data) {
|
|
123
|
+
const files = await getFilesAsync(templatePath);
|
|
124
|
+
// Iterate through all template files.
|
|
125
|
+
for (const file of files) {
|
|
126
|
+
const renderedRelativePath = ejs_1.default.render(file.replace(/^\$/, ''), data, {
|
|
127
|
+
openDelimiter: '{',
|
|
128
|
+
closeDelimiter: '}',
|
|
129
|
+
escape: (value) => value.replace('.', path_1.default.sep),
|
|
128
130
|
});
|
|
131
|
+
const fromPath = path_1.default.join(templatePath, file);
|
|
132
|
+
const toPath = path_1.default.join(targetPath, renderedRelativePath);
|
|
133
|
+
const template = await fs_extra_1.default.readFile(fromPath, { encoding: 'utf8' });
|
|
134
|
+
const renderedContent = ejs_1.default.render(template, data);
|
|
135
|
+
await fs_extra_1.default.outputFile(toPath, renderedContent, { encoding: 'utf8' });
|
|
129
136
|
}
|
|
130
|
-
console.log('📦 Installing dependencies...');
|
|
131
|
-
await run('install');
|
|
132
|
-
console.log('🛠 Compiling TypeScript files...');
|
|
133
|
-
await run('run', 'build');
|
|
134
137
|
}
|
|
135
138
|
/**
|
|
136
139
|
* Asks the user for some data necessary to render the template.
|
|
137
140
|
* Some values may already be provided by command options, the prompt is skipped in that case.
|
|
138
141
|
*/
|
|
139
|
-
async function askForSubstitutionDataAsync(targetDir
|
|
140
|
-
|
|
141
|
-
const defaultPackageSlug = path_1.default.basename(targetDir);
|
|
142
|
-
const defaultProjectName = defaultPackageSlug
|
|
143
|
-
.replace(/^./, (match) => match.toUpperCase())
|
|
144
|
-
.replace(/\W+(\w)/g, (_, p1) => p1.toUpperCase());
|
|
145
|
-
const promptQueries = [
|
|
146
|
-
{
|
|
147
|
-
type: 'text',
|
|
148
|
-
name: 'slug',
|
|
149
|
-
message: 'What is the package slug?',
|
|
150
|
-
initial: defaultPackageSlug,
|
|
151
|
-
resolvedValue: options.target ? defaultPackageSlug : null,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
type: 'text',
|
|
155
|
-
name: 'name',
|
|
156
|
-
message: 'What is the project name?',
|
|
157
|
-
initial: defaultProjectName,
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
type: 'text',
|
|
161
|
-
name: 'description',
|
|
162
|
-
message: 'How would you describe the module?',
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
type: 'text',
|
|
166
|
-
name: 'package',
|
|
167
|
-
message: 'What is the Android package name?',
|
|
168
|
-
initial: `expo.modules.${defaultPackageSlug.replace(/\W/g, '').toLowerCase()}`,
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
type: 'text',
|
|
172
|
-
name: 'author',
|
|
173
|
-
message: 'Who is the author?',
|
|
174
|
-
initial: (_a = (await npmWhoamiAsync(targetDir))) !== null && _a !== void 0 ? _a : '',
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
type: 'text',
|
|
178
|
-
name: 'license',
|
|
179
|
-
message: 'What is the license?',
|
|
180
|
-
initial: 'MIT',
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
type: 'text',
|
|
184
|
-
name: 'repo',
|
|
185
|
-
message: 'What is the repository URL?',
|
|
186
|
-
},
|
|
187
|
-
];
|
|
142
|
+
async function askForSubstitutionDataAsync(targetDir) {
|
|
143
|
+
const promptQueries = await (0, prompts_2.default)(targetDir);
|
|
188
144
|
// Stop the process when the user cancels/exits the prompt.
|
|
189
145
|
const onCancel = () => {
|
|
190
146
|
process.exit(0);
|
|
191
147
|
};
|
|
192
|
-
const
|
|
193
|
-
for (const query of promptQueries) {
|
|
194
|
-
const { name, resolvedValue } = query;
|
|
195
|
-
answers[name] = (_b = resolvedValue !== null && resolvedValue !== void 0 ? resolvedValue : options[name]) !== null && _b !== void 0 ? _b : (await (0, prompts_1.default)(query, { onCancel }))[name];
|
|
196
|
-
}
|
|
197
|
-
const { slug, name, description, package: projectPackage, author, license, repo } = answers;
|
|
148
|
+
const { slug, name, description, package: projectPackage, authorName, authorEmail, authorUrl, repo, } = await (0, prompts_1.default)(promptQueries, { onCancel });
|
|
198
149
|
return {
|
|
199
150
|
project: {
|
|
200
151
|
slug,
|
|
@@ -203,8 +154,8 @@ async function askForSubstitutionDataAsync(targetDir, options) {
|
|
|
203
154
|
description,
|
|
204
155
|
package: projectPackage,
|
|
205
156
|
},
|
|
206
|
-
author
|
|
207
|
-
license,
|
|
157
|
+
author: `${authorName} <${authorEmail}> (${authorUrl})`,
|
|
158
|
+
license: 'MIT',
|
|
208
159
|
repo,
|
|
209
160
|
};
|
|
210
161
|
}
|
|
@@ -235,14 +186,9 @@ program
|
|
|
235
186
|
.description(packageJson.description)
|
|
236
187
|
.arguments('[target_dir]')
|
|
237
188
|
.option('-s, --source <source_dir>', 'Local path to the template. By default it downloads `expo-module-template` from NPM.')
|
|
238
|
-
.option('-n, --name <module_name>', 'Name of the native module.')
|
|
239
|
-
.option('-d, --description <description>', 'Description of the module.')
|
|
240
|
-
.option('-p, --package <package>', 'The Android package name.')
|
|
241
|
-
.option('-a, --author <author>', 'The author name.')
|
|
242
|
-
.option('-l, --license <license>', 'The license that the module is distributed with.')
|
|
243
|
-
.option('-r, --repo <repo_url>', 'The URL to the repository.')
|
|
244
189
|
.option('--with-readme', 'Whether to include README.md file.', false)
|
|
245
190
|
.option('--with-changelog', 'Whether to include CHANGELOG.md file.', false)
|
|
191
|
+
.option('--no-example', 'Whether to skip creating the example app.', false)
|
|
246
192
|
.action(main);
|
|
247
193
|
program.parse(process.argv);
|
|
248
194
|
//# sourceMappingURL=create-expo-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-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CAAC,OAAO,CAC5C,SAAS,CACV,iDAAiD;QAClD,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,cAAc,CAAC;KACzB,MAAM,CACL,2BAA2B,EAC3B,sFAAsF,CACvF;KACA,MAAM,CAAC,0BAA0B,EAAE,4BAA4B,CAAC;KAChE,MAAM,CAAC,iCAAiC,EAAE,4BAA4B,CAAC;KACvE,MAAM,CAAC,yBAAyB,EAAE,2BAA2B,CAAC;KAC9D,MAAM,CAAC,uBAAuB,EAAE,kBAAkB,CAAC;KACnD,MAAM,CAAC,yBAAyB,EAAE,kDAAkD,CAAC;KACrF,MAAM,CAAC,uBAAuB,EAAE,4BAA4B,CAAC;KAC7D,MAAM,CAAC,eAAe,EAAE,oCAAoC,EAAE,KAAK,CAAC;KACpE,MAAM,CAAC,kBAAkB,EAAE,uCAAuC,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, { PromptObject } from 'prompts';\n\nimport { PackageManagerName, resolvePackageManager } from './resolvePackageManager';\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 * Possible command options.\n */\ntype 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};\n\n/**\n * Represents an object that is passed to `ejs` when rendering the template.\n */\ntype 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\ntype CustomPromptObject = PromptObject & {\n name: string;\n resolvedValue?: string | null;\n};\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 confirmTargetDirAsync(targetDir);\n\n options.target = targetDir;\n await fs.ensureDir(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 const files = await getFilesAsync(packagePath);\n\n console.log('🎨 Creating Expo module from the template files...');\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(packagePath, file);\n const toPath = path.join(targetDir, 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 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\n // Install dependencies and build\n await postActionsAsync(packageManager, targetDir);\n\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 const tarballUrl = await getNpmTarballUrl('expo-module-template');\n\n console.log('⬇️ Downloading module template from npm...');\n\n await downloadTarball({\n url: tarballUrl,\n dir: targetDir,\n });\n return path.join(targetDir, 'package');\n}\n\n/**\n * Installs dependencies and builds TypeScript files.\n */\nasync function postActionsAsync(packageManager: PackageManagerName, targetDir: string) {\n async function run(...args: string[]) {\n await spawnAsync(packageManager, args, {\n cwd: targetDir,\n stdio: 'ignore',\n });\n }\n\n console.log('📦 Installing dependencies...');\n await run('install');\n\n console.log('🛠 Compiling TypeScript files...');\n await run('run', 'build');\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 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: options.target ? defaultPackageSlug : null,\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 },\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 },\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 .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,gDAAwB;AACxB,sDAA8B;AAE9B,yDAAsD;AACtD,qDAAuD;AACvD,wDAAmC;AACnC,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,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,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 getPrompts 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 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);\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 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(targetDir: string): Promise<SubstitutionData> {\n const promptQueries = await getPrompts(targetDir);\n\n // Stop the process when the user cancels/exits the prompt.\n const onCancel = () => {\n process.exit(0);\n };\n\n const {\n slug,\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.\\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('--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"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PackageManagerName } from './resolvePackageManager';
|
|
2
|
+
import { SubstitutionData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Initializes a new Expo project as an example app.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createExampleApp(data: SubstitutionData, targetDir: string, packageManager: PackageManagerName): Promise<void>;
|
|
@@ -0,0 +1,130 @@
|
|
|
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.createExampleApp = void 0;
|
|
7
|
+
const spawn_async_1 = __importDefault(require("@expo/spawn-async"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const packageManager_1 = require("./packageManager");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
// These dependencies will be removed from the example app (`expo init` adds them)
|
|
13
|
+
const DEPENDENCIES_TO_REMOVE = ['expo-status-bar', 'expo-splash-screen'];
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new Expo project as an example app.
|
|
16
|
+
*/
|
|
17
|
+
async function createExampleApp(data, targetDir, packageManager) {
|
|
18
|
+
// Package name for the example app
|
|
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
|
+
}
|
|
28
|
+
await (0, utils_1.newStep)('Initializing the example app', async (step) => {
|
|
29
|
+
await (0, spawn_async_1.default)('expo', ['init', exampleProjectSlug, '--template', 'expo-template-blank-typescript'], {
|
|
30
|
+
cwd: targetDir,
|
|
31
|
+
stdio: ['ignore', 'ignore', 'inherit'],
|
|
32
|
+
});
|
|
33
|
+
step.succeed('Initialized the example app');
|
|
34
|
+
});
|
|
35
|
+
await (0, utils_1.newStep)('Configuring the example app', async (step) => {
|
|
36
|
+
// "example" folder already exists and contains template files,
|
|
37
|
+
// that should replace these created by `expo init`.
|
|
38
|
+
await moveFiles(appTargetPath, appTmpPath);
|
|
39
|
+
// Cleanup the "example" dir
|
|
40
|
+
await fs_extra_1.default.rmdir(appTargetPath);
|
|
41
|
+
// Move the temporary example app to "example" dir
|
|
42
|
+
await fs_extra_1.default.rename(appTmpPath, appTargetPath);
|
|
43
|
+
await addMissingAppConfigFields(appTargetPath, data);
|
|
44
|
+
step.succeed('Configured the example app');
|
|
45
|
+
});
|
|
46
|
+
await prebuildExampleApp(appTargetPath);
|
|
47
|
+
await modifyPackageJson(appTargetPath);
|
|
48
|
+
await (0, utils_1.newStep)('Installing dependencies in the example app', async (step) => {
|
|
49
|
+
await (0, packageManager_1.installDependencies)(packageManager, appTargetPath);
|
|
50
|
+
await podInstall(appTargetPath);
|
|
51
|
+
step.succeed('Installed dependencies in the example app');
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.createExampleApp = createExampleApp;
|
|
55
|
+
/**
|
|
56
|
+
* Copies files from one directory to another.
|
|
57
|
+
*/
|
|
58
|
+
async function moveFiles(fromPath, toPath) {
|
|
59
|
+
for (const file of await fs_extra_1.default.readdir(fromPath)) {
|
|
60
|
+
await fs_extra_1.default.move(path_1.default.join(fromPath, file), path_1.default.join(toPath, file), {
|
|
61
|
+
overwrite: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Adds missing configuration that are required to run `expo prebuild`.
|
|
67
|
+
*/
|
|
68
|
+
async function addMissingAppConfigFields(appPath, data) {
|
|
69
|
+
const appConfigPath = path_1.default.join(appPath, 'app.json');
|
|
70
|
+
const appConfig = await fs_extra_1.default.readJson(appConfigPath);
|
|
71
|
+
const appId = `${data.project.package}.example`;
|
|
72
|
+
// Android package name needs to be added to app.json
|
|
73
|
+
if (!appConfig.expo.android) {
|
|
74
|
+
appConfig.expo.android = {};
|
|
75
|
+
}
|
|
76
|
+
appConfig.expo.android.package = appId;
|
|
77
|
+
// Specify iOS bundle identifier
|
|
78
|
+
if (!appConfig.expo.ios) {
|
|
79
|
+
appConfig.expo.ios = {};
|
|
80
|
+
}
|
|
81
|
+
appConfig.expo.ios.bundleIdentifier = appId;
|
|
82
|
+
await fs_extra_1.default.writeJson(appConfigPath, appConfig, {
|
|
83
|
+
spaces: 2,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Applies necessary changes to **package.json** of the example app.
|
|
88
|
+
* It means setting the autolinking config and removing unnecessary dependencies.
|
|
89
|
+
*/
|
|
90
|
+
async function modifyPackageJson(appPath) {
|
|
91
|
+
const packageJsonPath = path_1.default.join(appPath, 'package.json');
|
|
92
|
+
const packageJson = await fs_extra_1.default.readJson(packageJsonPath);
|
|
93
|
+
if (!packageJson.expo) {
|
|
94
|
+
packageJson.expo = {};
|
|
95
|
+
}
|
|
96
|
+
// Set the native modules dir to the root folder,
|
|
97
|
+
// so that the autolinking can detect and link the module.
|
|
98
|
+
packageJson.expo.autolinking = {
|
|
99
|
+
nativeModulesDir: '..',
|
|
100
|
+
};
|
|
101
|
+
// Remove unnecessary dependencies
|
|
102
|
+
for (const dependencyToRemove of DEPENDENCIES_TO_REMOVE) {
|
|
103
|
+
delete packageJson.dependencies[dependencyToRemove];
|
|
104
|
+
}
|
|
105
|
+
await fs_extra_1.default.writeJson(packageJsonPath, packageJson, {
|
|
106
|
+
spaces: 2,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Runs `expo prebuild` in the example app.
|
|
111
|
+
*/
|
|
112
|
+
async function prebuildExampleApp(exampleAppPath) {
|
|
113
|
+
await (0, utils_1.newStep)('Prebuilding the example app', async (step) => {
|
|
114
|
+
await (0, spawn_async_1.default)('expo', ['prebuild', '--no-install'], {
|
|
115
|
+
cwd: exampleAppPath,
|
|
116
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
117
|
+
});
|
|
118
|
+
step.succeed('Prebuilt the example app');
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Runs `pod install` in the iOS project at the given path.
|
|
123
|
+
*/
|
|
124
|
+
async function podInstall(appPath) {
|
|
125
|
+
await (0, spawn_async_1.default)('pod', ['install'], {
|
|
126
|
+
cwd: path_1.default.join(appPath, 'ios'),
|
|
127
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=createExampleApp.js.map
|
|
@@ -0,0 +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,mCAAmC;IACnC,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC;IAE1D,0EAA0E;IAC1E,MAAM,UAA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AAA,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 '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 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,15 @@
|
|
|
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.installDependencies = void 0;
|
|
7
|
+
const spawn_async_1 = __importDefault(require("@expo/spawn-async"));
|
|
8
|
+
async function installDependencies(packageManager, appPath, ...args) {
|
|
9
|
+
await (0, spawn_async_1.default)(packageManager, ['install', ...args], {
|
|
10
|
+
cwd: appPath,
|
|
11
|
+
stdio: 'ignore',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.installDependencies = installDependencies;
|
|
15
|
+
//# sourceMappingURL=packageManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageManager.js","sourceRoot":"","sources":["../src/packageManager.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA2C;AAIpC,KAAK,UAAU,mBAAmB,CACvC,cAAkC,EAClC,OAAe,EACf,GAAG,IAAc;IAEjB,MAAM,IAAA,qBAAU,EAAC,cAAc,EAAE,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,EAAE;QACrD,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,QAAQ;KAChB,CAAC,CAAC;AACL,CAAC;AATD,kDASC","sourcesContent":["import spawnAsync from '@expo/spawn-async';\n\nimport { PackageManagerName } from './resolvePackageManager';\n\nexport async function installDependencies(\n packageManager: PackageManagerName,\n appPath: string,\n ...args: string[]\n) {\n await spawnAsync(packageManager, ['install', ...args], {\n cwd: appPath,\n stdio: 'ignore',\n });\n}\n"]}
|
package/build/prompts.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
async function getPrompts(targetDir) {
|
|
10
|
+
const targetBasename = path_1.default.basename(targetDir);
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
type: 'text',
|
|
14
|
+
name: 'slug',
|
|
15
|
+
message: 'What is the name of the npm package?',
|
|
16
|
+
initial: (0, validate_npm_package_name_1.default)(targetBasename).validForNewPackages ? targetBasename : undefined,
|
|
17
|
+
validate: (input) => (0, validate_npm_package_name_1.default)(input).validForNewPackages || 'Must be a valid npm package name',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'text',
|
|
21
|
+
name: 'name',
|
|
22
|
+
message: 'What is the native module name?',
|
|
23
|
+
initial: (_, answers) => {
|
|
24
|
+
return answers.slug
|
|
25
|
+
.replace(/^@/, '')
|
|
26
|
+
.replace(/^./, (match) => match.toUpperCase())
|
|
27
|
+
.replace(/\W+(\w)/g, (_, p1) => p1.toUpperCase());
|
|
28
|
+
},
|
|
29
|
+
validate: (input) => !!input || 'The native module name cannot be empty',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
name: 'description',
|
|
34
|
+
message: 'How would you describe the module?',
|
|
35
|
+
initial: 'My new module',
|
|
36
|
+
validate: (input) => !!input || 'The description cannot be empty',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: 'text',
|
|
40
|
+
name: 'package',
|
|
41
|
+
message: 'What is the Android package name?',
|
|
42
|
+
initial: (_, answers) => {
|
|
43
|
+
const namespace = answers.slug
|
|
44
|
+
.replace(/\W/g, '')
|
|
45
|
+
.replace(/^(expo|reactnative)/, '')
|
|
46
|
+
.toLowerCase();
|
|
47
|
+
return `expo.modules.${namespace}`;
|
|
48
|
+
},
|
|
49
|
+
validate: (input) => !!input || 'The Android package name cannot be empty',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'text',
|
|
53
|
+
name: 'authorName',
|
|
54
|
+
message: 'What is the name of the package author?',
|
|
55
|
+
initial: await (0, utils_1.findMyName)(),
|
|
56
|
+
validate: (input) => !!input || 'Cannot be empty',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
name: 'authorEmail',
|
|
61
|
+
message: 'What is the email address of the author?',
|
|
62
|
+
initial: await (0, utils_1.findGitHubEmail)(),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'text',
|
|
66
|
+
name: 'authorUrl',
|
|
67
|
+
message: "What is the URL to the author's GitHub profile?",
|
|
68
|
+
initial: async (_, answers) => await (0, utils_1.findGitHubProfileUrl)(answers.authorEmail),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: 'text',
|
|
72
|
+
name: 'repo',
|
|
73
|
+
message: 'What is the URL for the repository?',
|
|
74
|
+
initial: async (_, answers) => await (0, utils_1.guessRepoUrl)(answers.authorUrl, answers.slug),
|
|
75
|
+
validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
exports.default = getPrompts;
|
|
80
|
+
//# 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;AAE3E,KAA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Content":["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 default async function getPrompts(targetDir: string): Promise<PromptObject<string>[]> {\n const targetBasename = path.basename(targetDir);\n\n return [\n {\n type: 'text',\n name: 'slug',\n message: 'What is the name of the npm package?',\n initial: validateNpmPackage(targetBasename).validForNewPackages ? targetBasename : undefined,\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 native module name?',\n initial: (_, answers: Answers<string>) => {\n return answers.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: (_, answers: Answers<string>) => {\n const namespace = answers.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>) =>\n await guessRepoUrl(answers.authorUrl, answers.slug),\n validate: (input) => /^https?:\\/\\//.test(input) || 'Must be a valid URL',\n },\n ];\n}\n"]}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PromptObject } from 'prompts';
|
|
2
|
+
/**
|
|
3
|
+
* Possible command options.
|
|
4
|
+
*/
|
|
5
|
+
export declare type CommandOptions = {
|
|
6
|
+
target: string;
|
|
7
|
+
source?: string;
|
|
8
|
+
withReadme: boolean;
|
|
9
|
+
withChangelog: boolean;
|
|
10
|
+
example: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Represents an object that is passed to `ejs` when rendering the template.
|
|
14
|
+
*/
|
|
15
|
+
export declare type SubstitutionData = {
|
|
16
|
+
project: {
|
|
17
|
+
slug: string;
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
description: string;
|
|
21
|
+
package: string;
|
|
22
|
+
};
|
|
23
|
+
author: string;
|
|
24
|
+
license: string;
|
|
25
|
+
repo: string;
|
|
26
|
+
};
|
|
27
|
+
export declare type CustomPromptObject = PromptObject & {
|
|
28
|
+
name: string;
|
|
29
|
+
resolvedValue?: string | null;
|
|
30
|
+
};
|
|
31
|
+
export declare type Answers = Record<string, string>;
|
package/build/types.js
ADDED
|
@@ -0,0 +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 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"]}
|