@snap/valdi 1.0.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/.bazelignore +2 -0
- package/.bootstrap/apps/cli_application/AGENTS.md.template +215 -0
- package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
- package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
- package/.bootstrap/apps/ui_application/AGENTS.md.template +202 -0
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
- package/.bootstrap/apps/ui_application/package.json +24 -0
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +21 -0
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +29 -0
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +1 -0
- package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +39 -0
- package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +41 -0
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +42 -0
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +60 -0
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +6 -0
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +82 -0
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +15 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.config/copyconfig.json +10 -0
- package/.editorconfig +21 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +72 -0
- package/.metadata/.bazelrc.template +91 -0
- package/.metadata/.bazelversion.template +1 -0
- package/.metadata/.eslintrc.js.template +27 -0
- package/.metadata/.gitignore.template +4 -0
- package/.metadata/.prettierrc.json.template +7 -0
- package/.metadata/.watchmanconfig.template +8 -0
- package/.metadata/README.md.template +31 -0
- package/.metadata/WORKSPACE.template +57 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +7 -0
- package/README.md +123 -0
- package/dist/commands/bootstrap.js +233 -0
- package/dist/commands/build.js +67 -0
- package/dist/commands/devSetup.js +18 -0
- package/dist/commands/doctor.js +892 -0
- package/dist/commands/export.js +84 -0
- package/dist/commands/hotreload.js +89 -0
- package/dist/commands/install.js +71 -0
- package/dist/commands/lint.js +18 -0
- package/dist/commands/lint_commands/lintCheck.js +31 -0
- package/dist/commands/lint_commands/lintFormat.js +31 -0
- package/dist/commands/log.js +84 -0
- package/dist/commands/newModule.js +208 -0
- package/dist/commands/package.js +66 -0
- package/dist/commands/projectsync.js +316 -0
- package/dist/commands/test.js +54 -0
- package/dist/core/constants.js +76 -0
- package/dist/core/errors.js +12 -0
- package/dist/index.js +22 -0
- package/dist/setup/DevSetupHelper.js +146 -0
- package/dist/setup/linuxSetup.js +31 -0
- package/dist/setup/macOSSetup.js +35 -0
- package/dist/setup/setupEntryPoint.js +56 -0
- package/dist/setup/versions.js +8 -0
- package/dist/utils/ArgumentsResolver.js +23 -0
- package/dist/utils/BazelClient.js +219 -0
- package/dist/utils/Digraph.js +71 -0
- package/dist/utils/LoadingIndicator.js +38 -0
- package/dist/utils/applicationUtils.js +201 -0
- package/dist/utils/buildInfo.js +60 -0
- package/dist/utils/byString.js +6 -0
- package/dist/utils/cliUtils.js +93 -0
- package/dist/utils/copyBootstrapFiles.js +26 -0
- package/dist/utils/deviceUtils.js +72 -0
- package/dist/utils/errorUtils.js +55 -0
- package/dist/utils/fileUtils.js +204 -0
- package/dist/utils/githubUtils.js +8 -0
- package/dist/utils/jsonUtils.js +28 -0
- package/dist/utils/lintUtils.js +149 -0
- package/dist/utils/logUtils.js +8 -0
- package/dist/utils/pathUtils.js +12 -0
- package/dist/utils/stringUtils.js +17 -0
- package/dist/utils/stringUtils.spec.js +18 -0
- package/dist/utils/tempDir.js +26 -0
- package/dist/utils/zipUtils.js +16 -0
- package/package.json +51 -0
- package/prettier.config.js +4 -0
- package/spec/support/jasmine.json +6 -0
- package/src/commands/bootstrap.ts +317 -0
- package/src/commands/build.ts +89 -0
- package/src/commands/devSetup.ts +17 -0
- package/src/commands/doctor.ts +1422 -0
- package/src/commands/export.ts +131 -0
- package/src/commands/hotreload.ts +108 -0
- package/src/commands/install.ts +93 -0
- package/src/commands/lint.ts +15 -0
- package/src/commands/lint_commands/lintCheck.ts +53 -0
- package/src/commands/lint_commands/lintFormat.ts +49 -0
- package/src/commands/log.ts +108 -0
- package/src/commands/newModule.ts +287 -0
- package/src/commands/package.ts +102 -0
- package/src/commands/projectsync.ts +488 -0
- package/src/commands/test.ts +68 -0
- package/src/core/constants.ts +95 -0
- package/src/core/errors.ts +10 -0
- package/src/index.ts +22 -0
- package/src/setup/DevSetupHelper.ts +188 -0
- package/src/setup/linuxSetup.ts +38 -0
- package/src/setup/macOSSetup.ts +42 -0
- package/src/setup/setupEntryPoint.ts +64 -0
- package/src/setup/versions.ts +8 -0
- package/src/utils/ArgumentsResolver.ts +23 -0
- package/src/utils/BazelClient.ts +285 -0
- package/src/utils/Digraph.ts +81 -0
- package/src/utils/LoadingIndicator.ts +43 -0
- package/src/utils/applicationUtils.ts +276 -0
- package/src/utils/buildInfo.ts +99 -0
- package/src/utils/byString.ts +3 -0
- package/src/utils/cliUtils.ts +112 -0
- package/src/utils/copyBootstrapFiles.ts +30 -0
- package/src/utils/deviceUtils.ts +76 -0
- package/src/utils/errorUtils.ts +63 -0
- package/src/utils/fileUtils.ts +257 -0
- package/src/utils/githubUtils.ts +6 -0
- package/src/utils/jsonUtils.ts +30 -0
- package/src/utils/lintUtils.ts +190 -0
- package/src/utils/logUtils.ts +9 -0
- package/src/utils/pathUtils.ts +12 -0
- package/src/utils/stringUtils.spec.ts +19 -0
- package/src/utils/stringUtils.ts +15 -0
- package/src/utils/tempDir.ts +24 -0
- package/src/utils/zipUtils.ts +14 -0
- package/test/ValdiSmokeTest.ts +278 -0
- package/test/helpers/AsyncHelpers.ts +113 -0
- package/test/helpers/CommandHelpers.ts +37 -0
- package/test/helpers/ProjectHelpers.ts +153 -0
- package/test/helpers/StreamHelpers.ts +37 -0
- package/test/helpers/TypeScriptClient.ts +217 -0
- package/tsconfig.dist.json +8 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import type { Argv } from 'yargs';
|
|
5
|
+
import { ANSI_COLORS, BOOTSTRAP_DIR_PATH } from '../core/constants';
|
|
6
|
+
import { CliError } from '../core/errors';
|
|
7
|
+
import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
|
|
8
|
+
import { BazelClient } from '../utils/BazelClient';
|
|
9
|
+
import type { CliChoice } from '../utils/cliUtils';
|
|
10
|
+
import { getUserChoice } from '../utils/cliUtils';
|
|
11
|
+
import { copyBootstrapFiles } from '../utils/copyBootstrapFiles';
|
|
12
|
+
import { makeCommandHandler } from '../utils/errorUtils';
|
|
13
|
+
import type { Replacements } from '../utils/fileUtils';
|
|
14
|
+
import { fileExists } from '../utils/fileUtils';
|
|
15
|
+
import { wrapInColor } from '../utils/logUtils';
|
|
16
|
+
import { toPascalCase, toSnakeCase } from '../utils/stringUtils';
|
|
17
|
+
|
|
18
|
+
const referenceString = `
|
|
19
|
+
******************************************
|
|
20
|
+
Valdi Module Creation Guide
|
|
21
|
+
******************************************
|
|
22
|
+
|
|
23
|
+
Requirements for Valdi module names:
|
|
24
|
+
- May contain: A-Z, a-z, 0-9, '-', '_', '.'
|
|
25
|
+
- Must start with a letter.
|
|
26
|
+
|
|
27
|
+
Recommended Directory Structure:
|
|
28
|
+
my_application/ # Root directory of your application
|
|
29
|
+
├── WORKSPACE # Bazel Workspace
|
|
30
|
+
├── BUILD.bazel # Bazel build
|
|
31
|
+
└── modules/
|
|
32
|
+
├── module_a/
|
|
33
|
+
│ ├── BUILD.bazel
|
|
34
|
+
│ ├── android/ # Native Android sources
|
|
35
|
+
│ ├── ios/ # Native iOS sources
|
|
36
|
+
│ ├── cpp/ # Native C++ sources
|
|
37
|
+
│ └── src/ # Valdi sources
|
|
38
|
+
│ └── ModuleAComponent.tsx
|
|
39
|
+
├── module_b/
|
|
40
|
+
├── BUILD.bazel
|
|
41
|
+
│ ├── res/ # Image and font resources
|
|
42
|
+
│ ├── strings/ # Localizable strings
|
|
43
|
+
└── src/
|
|
44
|
+
└── ModuleBComponent.tsx
|
|
45
|
+
|
|
46
|
+
For more comprehensive details, refer to the core-module documentation:
|
|
47
|
+
https://github.com/Snapchat/Valdi/blob/main/docs/docs/core-module.md
|
|
48
|
+
|
|
49
|
+
******************************************
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const ALL_MODULE_TEMPLATES: readonly ModuleTemplate[] = [
|
|
53
|
+
{
|
|
54
|
+
name: 'UI Component',
|
|
55
|
+
path: 'ui_component',
|
|
56
|
+
description: `Exports a Valdi component, which can render UI elements`,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'iOS/Android Bridge module',
|
|
60
|
+
path: 'ios_android_bridge_module',
|
|
61
|
+
description: `Bridge module with a TypeScript API backed by Objective-C and Kotlin implementation`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'C++ Bridge module',
|
|
65
|
+
path: 'cpp_bridge_module',
|
|
66
|
+
description: `Bridge module with a TypeScript API backed by a cross-platform C++ implementation`,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'iOS/Android View module',
|
|
70
|
+
path: 'ios_android_view_module',
|
|
71
|
+
description: `iOS and Android view exported to TypeScript, rendered through a Valdi component`,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
interface CommandParameters {
|
|
76
|
+
debug: boolean;
|
|
77
|
+
skipChecks: boolean;
|
|
78
|
+
moduleName: string;
|
|
79
|
+
template?: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface Checks {
|
|
83
|
+
confirmBazelWorkspace?: boolean;
|
|
84
|
+
confirmValdiPath?: boolean;
|
|
85
|
+
valdiModulePath?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface ModuleTemplate {
|
|
89
|
+
name: string;
|
|
90
|
+
path: string;
|
|
91
|
+
description: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function promptChecks(): Promise<Checks> {
|
|
95
|
+
let answers: Checks = {};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Verify Bazel Workspace
|
|
99
|
+
*/
|
|
100
|
+
const bazelWorkspacePath = await getBazelWorkspaceRoot();
|
|
101
|
+
|
|
102
|
+
answers = await inquirer.prompt<Checks>(
|
|
103
|
+
[
|
|
104
|
+
{
|
|
105
|
+
type: 'confirm',
|
|
106
|
+
name: 'confirmBazelWorkspace',
|
|
107
|
+
message: 'Bazel WORKSPACE not found (did you run `valdi bootstrap` first?). Continue anyway?',
|
|
108
|
+
default: true,
|
|
109
|
+
when() {
|
|
110
|
+
return !bazelWorkspacePath;
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
answers,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (!bazelWorkspacePath && !answers.confirmBazelWorkspace) {
|
|
118
|
+
throw new CliError('Aborting.');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Verify directory structure
|
|
123
|
+
*/
|
|
124
|
+
answers = await inquirer.prompt<Checks>(
|
|
125
|
+
{
|
|
126
|
+
type: 'confirm',
|
|
127
|
+
name: 'confirmValdiPath',
|
|
128
|
+
message:
|
|
129
|
+
'/modules directory not found (did you run `valdi bootstrap` first?). Create module in current directory?',
|
|
130
|
+
default: true,
|
|
131
|
+
when(answers) {
|
|
132
|
+
const curDir = process.cwd();
|
|
133
|
+
const parsedPath = path.parse(curDir);
|
|
134
|
+
if (parsedPath.base === 'modules') {
|
|
135
|
+
// Create the new module in the current directory
|
|
136
|
+
answers.valdiModulePath = curDir;
|
|
137
|
+
} else if (curDir === bazelWorkspacePath) {
|
|
138
|
+
// Create the new module in ./modules
|
|
139
|
+
const valdiPath = path.join(curDir, 'modules');
|
|
140
|
+
if (fs.existsSync(valdiPath)) {
|
|
141
|
+
answers.valdiModulePath = valdiPath;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return !answers.valdiModulePath;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
answers,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (!answers.valdiModulePath && !answers.confirmValdiPath) {
|
|
152
|
+
throw new CliError('Aborting.');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return answers;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function getModuleName(argv: ArgumentsResolver<CommandParameters>): Promise<string> {
|
|
159
|
+
return argv.getArgumentOrResolve('moduleName', async () => {
|
|
160
|
+
const result = await inquirer.prompt<{ moduleName?: string }>(
|
|
161
|
+
[
|
|
162
|
+
{
|
|
163
|
+
type: 'input',
|
|
164
|
+
name: 'moduleName',
|
|
165
|
+
message: 'Please provide a name for this module:',
|
|
166
|
+
validate: (input: string) => {
|
|
167
|
+
const isEmpty = input === '';
|
|
168
|
+
if (isEmpty) {
|
|
169
|
+
throw new CliError('Module name cannot be empty.');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// TODO: need to change validation logic to match bazel names
|
|
173
|
+
const snakeCaseName = toSnakeCase(input);
|
|
174
|
+
const isSnakeCase = snakeCaseName === input;
|
|
175
|
+
if (!isSnakeCase) {
|
|
176
|
+
throw new CliError(
|
|
177
|
+
`Valid names may contain only A-Z, a-z, 0-9, '-', '_', '.', and must start with a letter (ie: '${snakeCaseName}').`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const destPath = path.join(process.cwd(), input);
|
|
182
|
+
if (fileExists(destPath)) {
|
|
183
|
+
throw new CliError(
|
|
184
|
+
`Path ${destPath} already exists. Choose a different name or delete the folder and try again.`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return true;
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
{},
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return result.moduleName ?? '';
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function finalConfirmation(destPath: string, argv: ArgumentsResolver<CommandParameters>): Promise<boolean> {
|
|
200
|
+
return argv.getArgumentOrResolve('skipChecks', async () => {
|
|
201
|
+
const confirmMessage = `
|
|
202
|
+
Create module?
|
|
203
|
+
Path: ${wrapInColor(destPath, ANSI_COLORS.GREEN_COLOR)}
|
|
204
|
+
`;
|
|
205
|
+
const answers = await inquirer.prompt<{ confirm?: boolean }>(
|
|
206
|
+
[
|
|
207
|
+
{
|
|
208
|
+
type: 'confirm',
|
|
209
|
+
name: 'confirm',
|
|
210
|
+
message: confirmMessage,
|
|
211
|
+
default: true,
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
{},
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return answers.confirm ?? false;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function getBazelWorkspaceRoot() {
|
|
222
|
+
return new BazelClient().getWorkspaceRoot();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function valdiNewModule(argv: ArgumentsResolver<CommandParameters>) {
|
|
226
|
+
console.log(referenceString);
|
|
227
|
+
const skipChecks = argv.getArgument('skipChecks');
|
|
228
|
+
|
|
229
|
+
const checks: Checks = skipChecks ? {} : await promptChecks();
|
|
230
|
+
const valdiModulePath = checks.valdiModulePath ?? path.join(await getBazelWorkspaceRoot(), 'modules');
|
|
231
|
+
|
|
232
|
+
const moduleName = await getModuleName(argv);
|
|
233
|
+
|
|
234
|
+
const destPath = path.join(valdiModulePath, moduleName);
|
|
235
|
+
const didConfirm = skipChecks || (await finalConfirmation(destPath, argv));
|
|
236
|
+
if (!didConfirm) {
|
|
237
|
+
throw new CliError('Cancelled new module creation.');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Do not overwrite existing files
|
|
242
|
+
*/
|
|
243
|
+
if (fs.existsSync(destPath)) {
|
|
244
|
+
throw new CliError(`Path already exists ${destPath}`);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const choices: CliChoice<ModuleTemplate>[] = ALL_MODULE_TEMPLATES.map(target => ({
|
|
248
|
+
name: `${wrapInColor(target.name, ANSI_COLORS.GREEN_COLOR)} . ${target.description}`,
|
|
249
|
+
value: target,
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
const templateOption = argv.getArgument('template');
|
|
253
|
+
const template = templateOption ? ALL_MODULE_TEMPLATES.find(template => template.path === templateOption) : undefined;
|
|
254
|
+
const moduleTemplate = template ?? await getUserChoice(choices, `Please choose the module type:`);
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Copy bootstrap files
|
|
258
|
+
*/
|
|
259
|
+
const sourcePath = path.join(BOOTSTRAP_DIR_PATH, 'modules', moduleTemplate.path);
|
|
260
|
+
const replacements: Replacements = {
|
|
261
|
+
MODULE_NAME: moduleName,
|
|
262
|
+
MODULE_NAME_PASCAL_CASED: toPascalCase(moduleName),
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
copyBootstrapFiles(sourcePath, destPath, replacements);
|
|
266
|
+
|
|
267
|
+
// Finalize message
|
|
268
|
+
console.log(`Success! New module directory: ${wrapInColor(destPath, ANSI_COLORS.GREEN_COLOR)}`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export const command = `new_module [module-name]`;
|
|
272
|
+
export const describe = referenceString;
|
|
273
|
+
export const builder = (yargs: Argv<CommandParameters>) => {
|
|
274
|
+
yargs
|
|
275
|
+
.positional('module-name', {
|
|
276
|
+
describe: 'Name of the Valdi module.',
|
|
277
|
+
})
|
|
278
|
+
.option('template', {
|
|
279
|
+
describe: 'module template to use, will skip the prompt',
|
|
280
|
+
choices: ALL_MODULE_TEMPLATES.map(template => template.path),
|
|
281
|
+
})
|
|
282
|
+
.option('skip-checks', {
|
|
283
|
+
describe: 'Skips confirmation prompts.',
|
|
284
|
+
type: 'boolean',
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
export const handler = makeCommandHandler(valdiNewModule);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import type { Argv } from 'yargs';
|
|
4
|
+
import type { PLATFORM } from '../core/constants';
|
|
5
|
+
import { ALL_ARCHITECTURES, ANSI_COLORS } from '../core/constants';
|
|
6
|
+
import { CliError } from '../core/errors';
|
|
7
|
+
import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
|
|
8
|
+
import { BazelClient } from '../utils/BazelClient';
|
|
9
|
+
import type { SharedCommandParameters } from '../utils/applicationUtils';
|
|
10
|
+
import {
|
|
11
|
+
applicationExtensionForPlatform,
|
|
12
|
+
getApplicationTargetTagForPlatform,
|
|
13
|
+
getOutputFilePath,
|
|
14
|
+
makeArgsBuilder,
|
|
15
|
+
resolveBazelBuildArgs,
|
|
16
|
+
selectBazelTarget,
|
|
17
|
+
} from '../utils/applicationUtils';
|
|
18
|
+
import { logReproduceThisCommandIfNeeded, makeCommandHandler } from '../utils/errorUtils';
|
|
19
|
+
import { wrapInColor } from '../utils/logUtils';
|
|
20
|
+
|
|
21
|
+
interface CommandParameters extends SharedCommandParameters {
|
|
22
|
+
application: string | undefined;
|
|
23
|
+
target_output_path: string | undefined;
|
|
24
|
+
output_path: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function valdiPackage(argv: ArgumentsResolver<CommandParameters>): Promise<void> {
|
|
28
|
+
const bazel = new BazelClient();
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
30
|
+
const platform = argv.getArgument('platform') as PLATFORM;
|
|
31
|
+
const bazelArgs = resolveBazelBuildArgs(
|
|
32
|
+
platform,
|
|
33
|
+
argv.getArgument('build_config'),
|
|
34
|
+
ALL_ARCHITECTURES,
|
|
35
|
+
/* forDevice */ true,
|
|
36
|
+
argv.getArgument('enable_runtime_logs'),
|
|
37
|
+
argv.getArgument('enable_runtime_traces'),
|
|
38
|
+
argv.getArgument('bazel_args'),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const resolvedOutputPath = path.resolve(argv.getArgument('output_path'));
|
|
42
|
+
const expectedExtension = applicationExtensionForPlatform(platform);
|
|
43
|
+
if (expectedExtension.length > 0 && !resolvedOutputPath.endsWith(expectedExtension)) {
|
|
44
|
+
throw new CliError(`Output path for platform '${platform}' must have ${expectedExtension} file extension`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (fs.existsSync(resolvedOutputPath)) {
|
|
48
|
+
fs.rmSync(resolvedOutputPath);
|
|
49
|
+
}
|
|
50
|
+
const directoryPath = path.dirname(resolvedOutputPath);
|
|
51
|
+
if (!fs.existsSync(directoryPath)) {
|
|
52
|
+
fs.mkdirSync(directoryPath, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const application = await argv.getArgumentOrResolve('application', () => {
|
|
56
|
+
console.log('No application specified querying available targets...');
|
|
57
|
+
return selectBazelTarget(
|
|
58
|
+
bazel,
|
|
59
|
+
getApplicationTargetTagForPlatform(platform),
|
|
60
|
+
'valdi_application',
|
|
61
|
+
'Please select an application target to package:',
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
console.log('Resolving output paths...');
|
|
65
|
+
|
|
66
|
+
const bazelOutputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
|
|
67
|
+
console.log('Resolving output paths...');
|
|
68
|
+
return getOutputFilePath(bazel, expectedExtension, application, bazelArgs);
|
|
69
|
+
});
|
|
70
|
+
console.log(`Building: ${wrapInColor(application, ANSI_COLORS.GREEN_COLOR)}`);
|
|
71
|
+
|
|
72
|
+
await bazel.buildTarget(application, bazelArgs);
|
|
73
|
+
|
|
74
|
+
console.log(`Copying built target to ${resolvedOutputPath}...`);
|
|
75
|
+
await fs.promises.copyFile(bazelOutputFilePath, resolvedOutputPath);
|
|
76
|
+
|
|
77
|
+
logReproduceThisCommandIfNeeded(argv);
|
|
78
|
+
console.log('All done!');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const command = 'package <platform>';
|
|
82
|
+
export const describe = 'Build and package a Valdi application';
|
|
83
|
+
export const builder = makeArgsBuilder((yargs: Argv<CommandParameters>) => {
|
|
84
|
+
yargs
|
|
85
|
+
.option('application', {
|
|
86
|
+
describe: 'Name of the application to build',
|
|
87
|
+
type: 'string',
|
|
88
|
+
requiresArg: true,
|
|
89
|
+
})
|
|
90
|
+
.option('target_output_path', {
|
|
91
|
+
describe: 'The output path for the Bazel target',
|
|
92
|
+
type: 'string',
|
|
93
|
+
requiresArg: true,
|
|
94
|
+
})
|
|
95
|
+
.option('output_path', {
|
|
96
|
+
describe: 'The path where to store the built application package',
|
|
97
|
+
type: 'string',
|
|
98
|
+
requiresArg: true,
|
|
99
|
+
})
|
|
100
|
+
.demandOption('output_path');
|
|
101
|
+
});
|
|
102
|
+
export const handler = makeCommandHandler(valdiPackage);
|