@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,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const constants_1 = require("../core/constants");
|
|
8
|
+
const errors_1 = require("../core/errors");
|
|
9
|
+
const BazelClient_1 = require("../utils/BazelClient");
|
|
10
|
+
const applicationUtils_1 = require("../utils/applicationUtils");
|
|
11
|
+
const errorUtils_1 = require("../utils/errorUtils");
|
|
12
|
+
const fileUtils_1 = require("../utils/fileUtils");
|
|
13
|
+
const logUtils_1 = require("../utils/logUtils");
|
|
14
|
+
const tempDir_1 = require("../utils/tempDir");
|
|
15
|
+
const zipUtils_1 = require("../utils/zipUtils");
|
|
16
|
+
async function decompressAndMoveXCFrameworkIntoDestination(bazelOutputFilePath, resolvedOutputPath) {
|
|
17
|
+
await (0, tempDir_1.withTempDir)(async (tempDir) => {
|
|
18
|
+
await (0, zipUtils_1.decompressTo)(bazelOutputFilePath, tempDir);
|
|
19
|
+
const decompressedOutputs = fs.readdirSync(tempDir);
|
|
20
|
+
if (decompressedOutputs.length !== 1) {
|
|
21
|
+
throw new Error(`Expected 1 unzipped output, got ${decompressedOutputs.length} (${decompressedOutputs.join(', ')})`);
|
|
22
|
+
}
|
|
23
|
+
const inputDir = path_1.default.join(tempDir, decompressedOutputs[0]);
|
|
24
|
+
await fs.promises.rename(inputDir, resolvedOutputPath);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function valdiExport(argv) {
|
|
28
|
+
const bazel = new BazelClient_1.BazelClient();
|
|
29
|
+
const platform = argv.getArgument('platform');
|
|
30
|
+
const bazelArgs = (0, applicationUtils_1.resolveBazelBuildArgs)(platform, argv.getArgument('build_config'), constants_1.ALL_ARCHITECTURES, false, argv.getArgument('enable_runtime_logs'), argv.getArgument('enable_runtime_traces'), argv.getArgument('bazel_args'));
|
|
31
|
+
const resolvedOutputPath = path_1.default.resolve(argv.getArgument('output_path'));
|
|
32
|
+
const expectedExtension = (0, applicationUtils_1.exportedLibraryExtensionForPlatform)(platform);
|
|
33
|
+
if (!resolvedOutputPath.endsWith(expectedExtension)) {
|
|
34
|
+
throw new errors_1.CliError(`Output path for platform '${platform}' must have ${expectedExtension} file extension`);
|
|
35
|
+
}
|
|
36
|
+
(0, fileUtils_1.removeFileOrDirAtPath)(resolvedOutputPath);
|
|
37
|
+
const directoryPath = path_1.default.dirname(resolvedOutputPath);
|
|
38
|
+
if (!fs.existsSync(directoryPath)) {
|
|
39
|
+
fs.mkdirSync(directoryPath, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
const library = await argv.getArgumentOrResolve('library', () => {
|
|
42
|
+
console.log('No library specified querying available targets...');
|
|
43
|
+
return (0, applicationUtils_1.selectBazelTarget)(bazel, (0, applicationUtils_1.getExportedLibraryTargetTagForPlatform)(platform), 'valdi_exported_library', 'Please select a library to export:');
|
|
44
|
+
});
|
|
45
|
+
console.log('Resolving output paths...');
|
|
46
|
+
const bazelOutputExtension = platform === constants_1.PLATFORM.IOS ? '.zip' : expectedExtension;
|
|
47
|
+
const bazelOutputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
|
|
48
|
+
console.log('Resolving output paths...');
|
|
49
|
+
return (0, applicationUtils_1.getOutputFilePath)(bazel, bazelOutputExtension, library, bazelArgs);
|
|
50
|
+
});
|
|
51
|
+
console.log(`Building: ${(0, logUtils_1.wrapInColor)(library, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
|
|
52
|
+
await bazel.buildTarget(library, bazelArgs);
|
|
53
|
+
console.log(`Copying built target to ${resolvedOutputPath}...`);
|
|
54
|
+
if (platform === constants_1.PLATFORM.IOS) {
|
|
55
|
+
await decompressAndMoveXCFrameworkIntoDestination(bazelOutputFilePath, resolvedOutputPath);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
await fs.promises.copyFile(bazelOutputFilePath, resolvedOutputPath);
|
|
59
|
+
}
|
|
60
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
61
|
+
console.log('All done!');
|
|
62
|
+
}
|
|
63
|
+
exports.command = 'export <platform>';
|
|
64
|
+
exports.describe = 'Build and export a Valdi library';
|
|
65
|
+
exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
|
|
66
|
+
yargs
|
|
67
|
+
.option('library', {
|
|
68
|
+
describe: 'Name of the library to build',
|
|
69
|
+
type: 'string',
|
|
70
|
+
requiresArg: true,
|
|
71
|
+
})
|
|
72
|
+
.option('target_output_path', {
|
|
73
|
+
describe: 'The output path for the Bazel target',
|
|
74
|
+
type: 'string',
|
|
75
|
+
requiresArg: true,
|
|
76
|
+
})
|
|
77
|
+
.option('output_path', {
|
|
78
|
+
describe: 'The path where to store the built application package',
|
|
79
|
+
type: 'string',
|
|
80
|
+
requiresArg: true,
|
|
81
|
+
})
|
|
82
|
+
.demandOption('output_path');
|
|
83
|
+
});
|
|
84
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiExport);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const constants_1 = require("../core/constants");
|
|
5
|
+
const errors_1 = require("../core/errors");
|
|
6
|
+
const BazelClient_1 = require("../utils/BazelClient");
|
|
7
|
+
const cliUtils_1 = require("../utils/cliUtils");
|
|
8
|
+
const errorUtils_1 = require("../utils/errorUtils");
|
|
9
|
+
const logUtils_1 = require("../utils/logUtils");
|
|
10
|
+
async function hotreloadResolvedTarget(client, resolvedTarget) {
|
|
11
|
+
await client.buildTarget(resolvedTarget);
|
|
12
|
+
const workspaceRoot = await client.getWorkspaceRoot();
|
|
13
|
+
const buildOutputs = await client.queryBuildOutputs([resolvedTarget]);
|
|
14
|
+
if (buildOutputs.length === 0) {
|
|
15
|
+
throw new errors_1.CliError(`No build outputs found for target: ${resolvedTarget}`);
|
|
16
|
+
}
|
|
17
|
+
const hotreloadCommand = buildOutputs[0] ?? '';
|
|
18
|
+
await (0, cliUtils_1.spawnCliCommand)(hotreloadCommand, workspaceRoot, 'inherit', true, false);
|
|
19
|
+
}
|
|
20
|
+
async function hotreloadTarget(client, target) {
|
|
21
|
+
const resolvedLabel = await client.resolveLabel(target);
|
|
22
|
+
let resolvedTarget;
|
|
23
|
+
if (resolvedLabel.name) {
|
|
24
|
+
resolvedTarget = resolvedLabel.toString();
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const targets = await client.query(`kind('valdi_hotreload', ${resolvedLabel.toString()}/...)`);
|
|
28
|
+
if (targets.length === 0) {
|
|
29
|
+
throw new Error(`Could not resolve hot reload target for label ${resolvedLabel.toString()}`);
|
|
30
|
+
}
|
|
31
|
+
if (targets.length !== 1) {
|
|
32
|
+
throw new Error(`Resolved more than 1 hot reload target for ${resolvedLabel.toString()}: ${targets.join(',')}`);
|
|
33
|
+
}
|
|
34
|
+
resolvedTarget = targets[0];
|
|
35
|
+
}
|
|
36
|
+
await hotreloadResolvedTarget(client, resolvedTarget);
|
|
37
|
+
}
|
|
38
|
+
async function getHotreloadTargetByModuleName(client, moduleName) {
|
|
39
|
+
const targets = await client.query(`filter(${moduleName}_hotreload, kind('valdi_hotreload rule', //...))`);
|
|
40
|
+
if (targets.length === 0) {
|
|
41
|
+
throw new errors_1.CliError(`No hotreload target found for module: ${moduleName}`);
|
|
42
|
+
}
|
|
43
|
+
return targets[0]?.trim() ?? '';
|
|
44
|
+
}
|
|
45
|
+
async function valdiHotreload(argv) {
|
|
46
|
+
const client = new BazelClient_1.BazelClient();
|
|
47
|
+
const target = await argv.getArgumentOrResolve('target', async () => {
|
|
48
|
+
const module = argv.getArgument('module');
|
|
49
|
+
if (module) {
|
|
50
|
+
console.log('Finding target for module:', (0, logUtils_1.wrapInColor)(module, constants_1.ANSI_COLORS.GREEN_COLOR));
|
|
51
|
+
const target = await getHotreloadTargetByModuleName(client, module);
|
|
52
|
+
console.log('Found target:', (0, logUtils_1.wrapInColor)(target, constants_1.ANSI_COLORS.GREEN_COLOR));
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
const targets = await client.query('attr("tags", "valdi_application", //...)');
|
|
56
|
+
if (targets.length === 0) {
|
|
57
|
+
throw new errors_1.CliError(`Could not resolve Valdi application Bazel target`);
|
|
58
|
+
}
|
|
59
|
+
if (targets.length === 1) {
|
|
60
|
+
return targets[0];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const choices = targets.map((target, index) => ({
|
|
64
|
+
name: `${index + 1}. ${target}`,
|
|
65
|
+
value: target,
|
|
66
|
+
}));
|
|
67
|
+
return await (0, cliUtils_1.getUserChoice)(choices, 'Please choose a target to hot reload:');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
71
|
+
await hotreloadResolvedTarget(client, target);
|
|
72
|
+
}
|
|
73
|
+
exports.command = 'hotreload [--module module_name] [--target target_name]';
|
|
74
|
+
exports.describe = 'Starts the hotreloader for the application';
|
|
75
|
+
const builder = (yargs) => {
|
|
76
|
+
yargs
|
|
77
|
+
.option('module', {
|
|
78
|
+
describe: 'Name of the module to hotreload',
|
|
79
|
+
type: 'string',
|
|
80
|
+
requiresArg: true,
|
|
81
|
+
})
|
|
82
|
+
.option('target', {
|
|
83
|
+
describe: 'Bazel target path to hotreload',
|
|
84
|
+
type: 'string',
|
|
85
|
+
requiresArg: true,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
exports.builder = builder;
|
|
89
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiHotreload);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const constants_1 = require("../core/constants");
|
|
5
|
+
const BazelClient_1 = require("../utils/BazelClient");
|
|
6
|
+
const applicationUtils_1 = require("../utils/applicationUtils");
|
|
7
|
+
const buildInfo_1 = require("../utils/buildInfo");
|
|
8
|
+
const deviceUtils_1 = require("../utils/deviceUtils");
|
|
9
|
+
const errorUtils_1 = require("../utils/errorUtils");
|
|
10
|
+
const logUtils_1 = require("../utils/logUtils");
|
|
11
|
+
async function valdiInstall(argv) {
|
|
12
|
+
const bazel = new BazelClient_1.BazelClient();
|
|
13
|
+
const buildInfo = await (0, buildInfo_1.getBuildInfo)(argv, bazel, true);
|
|
14
|
+
console.log(`Building: ${(0, logUtils_1.wrapInColor)(buildInfo.application, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
|
|
15
|
+
switch (buildInfo.platform) {
|
|
16
|
+
case constants_1.PLATFORM.ANDROID: {
|
|
17
|
+
const outputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
|
|
18
|
+
console.log('Resolving output paths...');
|
|
19
|
+
return (0, applicationUtils_1.getOutputFilePath)(bazel, (0, applicationUtils_1.applicationExtensionForPlatform)(buildInfo.platform), buildInfo.application, buildInfo.bazelArgs);
|
|
20
|
+
});
|
|
21
|
+
await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
22
|
+
console.log('Installing Android application...');
|
|
23
|
+
await (0, deviceUtils_1.installAndroidApk)(outputFilePath, buildInfo.selectedDevice);
|
|
24
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case constants_1.PLATFORM.IOS: {
|
|
28
|
+
console.log('Installing iOS application...');
|
|
29
|
+
await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
30
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case constants_1.PLATFORM.MACOS: {
|
|
34
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
35
|
+
console.log('Installing MacOS application...');
|
|
36
|
+
await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case constants_1.PLATFORM.CLI: {
|
|
40
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
41
|
+
console.log('Running CLI application...');
|
|
42
|
+
await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.command = 'install <platform>';
|
|
48
|
+
exports.describe = 'Build and install the application to the connected device';
|
|
49
|
+
exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
|
|
50
|
+
yargs
|
|
51
|
+
.option('application', {
|
|
52
|
+
describe: 'Name of the application to install',
|
|
53
|
+
type: 'string',
|
|
54
|
+
requiresArg: true,
|
|
55
|
+
})
|
|
56
|
+
.option('device_id', {
|
|
57
|
+
describe: 'Device ID that will receive the application',
|
|
58
|
+
type: 'string',
|
|
59
|
+
requiresArg: true,
|
|
60
|
+
})
|
|
61
|
+
.option('target_output_path', {
|
|
62
|
+
describe: 'The output path for the Bazel target',
|
|
63
|
+
type: 'string',
|
|
64
|
+
requiresArg: true,
|
|
65
|
+
})
|
|
66
|
+
.option('simulator', {
|
|
67
|
+
describe: 'Whether to build for simulator or for device',
|
|
68
|
+
type: 'boolean',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiInstall);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
exports.command = 'lint <command>';
|
|
5
|
+
exports.describe = 'Checks and formats the code';
|
|
6
|
+
const builder = (yargs) => {
|
|
7
|
+
return yargs
|
|
8
|
+
.commandDir('lint_commands', {
|
|
9
|
+
extensions: ['js', 'ts'],
|
|
10
|
+
})
|
|
11
|
+
.demandCommand(1, 'Use "check" or "format" to execute prettier')
|
|
12
|
+
.recommendCommands()
|
|
13
|
+
.wrap(yargs.terminalWidth())
|
|
14
|
+
.help();
|
|
15
|
+
};
|
|
16
|
+
exports.builder = builder;
|
|
17
|
+
const handler = () => { };
|
|
18
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const constants_1 = require("../../core/constants");
|
|
5
|
+
const errorUtils_1 = require("../../utils/errorUtils");
|
|
6
|
+
const lintUtils_1 = require("../../utils/lintUtils");
|
|
7
|
+
const logUtils_1 = require("../../utils/logUtils");
|
|
8
|
+
async function lintCheck(argv) {
|
|
9
|
+
const configPath = await (0, lintUtils_1.maybeSetupPrettier)();
|
|
10
|
+
const prettierConfig = await (0, lintUtils_1.getPrettierConfig)(configPath);
|
|
11
|
+
await (0, lintUtils_1.maybeSetupEslint)();
|
|
12
|
+
console.log(`Using config at: ${(0, logUtils_1.wrapInColor)(configPath, constants_1.ANSI_COLORS.GREEN_COLOR)}\n`);
|
|
13
|
+
const filePaths = argv.getArgument('files');
|
|
14
|
+
if (filePaths === undefined || prettierConfig === null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const results = await (0, lintUtils_1.checkAndFormatFiles)(filePaths, prettierConfig);
|
|
18
|
+
(0, lintUtils_1.printStatus)(results, argv.getArgument('showSkipped'));
|
|
19
|
+
}
|
|
20
|
+
exports.command = 'check [files..]';
|
|
21
|
+
exports.describe = 'Checks the file formatting and lint rules';
|
|
22
|
+
const builder = (yargs) => {
|
|
23
|
+
yargs.option('show-skipped', {
|
|
24
|
+
describe: 'Shows files skipped during linting (e.g. no format parsers)',
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
alias: 's',
|
|
27
|
+
default: false,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.builder = builder;
|
|
31
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(lintCheck);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const constants_1 = require("../../core/constants");
|
|
5
|
+
const errorUtils_1 = require("../../utils/errorUtils");
|
|
6
|
+
const lintUtils_1 = require("../../utils/lintUtils");
|
|
7
|
+
const logUtils_1 = require("../../utils/logUtils");
|
|
8
|
+
async function lintFormat(argv) {
|
|
9
|
+
const configPath = await (0, lintUtils_1.maybeSetupPrettier)();
|
|
10
|
+
const prettierConfig = await (0, lintUtils_1.getPrettierConfig)(configPath);
|
|
11
|
+
await (0, lintUtils_1.maybeSetupEslint)();
|
|
12
|
+
console.log(`Using config at: ${(0, logUtils_1.wrapInColor)(configPath, constants_1.ANSI_COLORS.GREEN_COLOR)}\n`);
|
|
13
|
+
const filePaths = argv.getArgument('files');
|
|
14
|
+
if (filePaths === undefined || prettierConfig === null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const results = await (0, lintUtils_1.checkAndFormatFiles)(filePaths, prettierConfig, true);
|
|
18
|
+
(0, lintUtils_1.printStatus)(results, argv.getArgument('showSkipped'));
|
|
19
|
+
}
|
|
20
|
+
exports.command = 'format [files..]';
|
|
21
|
+
exports.describe = 'Apply prettier formatting to files';
|
|
22
|
+
const builder = (yargs) => {
|
|
23
|
+
yargs.option('show-skipped', {
|
|
24
|
+
describe: 'Shows files skipped during linting (e.g. no format parsers)',
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
alias: 's',
|
|
27
|
+
default: false,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.builder = builder;
|
|
31
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(lintFormat);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const errors_1 = require("../core/errors");
|
|
8
|
+
const cliUtils_1 = require("../utils/cliUtils");
|
|
9
|
+
const errorUtils_1 = require("../utils/errorUtils");
|
|
10
|
+
const fileUtils = tslib_1.__importStar(require("../utils/fileUtils"));
|
|
11
|
+
function readAndWatchFile(filePath) {
|
|
12
|
+
filePath = fileUtils.resolveFilePath(filePath);
|
|
13
|
+
let fileSize = 0;
|
|
14
|
+
let isWatching = false;
|
|
15
|
+
const abortController = new AbortController();
|
|
16
|
+
const readInitialContent = () => {
|
|
17
|
+
const fileStream = fs_1.default.createReadStream(filePath, { encoding: 'utf8', start: 0 });
|
|
18
|
+
fileStream.on('data', chunk => {
|
|
19
|
+
process.stdout.write(chunk);
|
|
20
|
+
});
|
|
21
|
+
fileStream.on('end', () => {
|
|
22
|
+
fileSize = fs_1.default.statSync(filePath).size;
|
|
23
|
+
if (!isWatching) {
|
|
24
|
+
startWatching();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const startWatching = () => {
|
|
29
|
+
isWatching = true;
|
|
30
|
+
fs_1.default.watch(filePath, { signal: abortController.signal }, eventType => {
|
|
31
|
+
if (eventType === 'change') {
|
|
32
|
+
const newFileSize = fs_1.default.statSync(filePath).size;
|
|
33
|
+
if (newFileSize > fileSize) {
|
|
34
|
+
const readStream = fs_1.default.createReadStream(filePath, { encoding: 'utf8', start: fileSize });
|
|
35
|
+
readStream.on('data', chunk => {
|
|
36
|
+
process.stdout.write(chunk);
|
|
37
|
+
});
|
|
38
|
+
fileSize = newFileSize;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (eventType === 'rename') {
|
|
42
|
+
isWatching = false;
|
|
43
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
44
|
+
readInitialContent();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
readInitialContent();
|
|
50
|
+
process.stdin.on('end', () => {
|
|
51
|
+
abortController.abort();
|
|
52
|
+
});
|
|
53
|
+
process.stdin.resume();
|
|
54
|
+
}
|
|
55
|
+
async function showValdiLogs() {
|
|
56
|
+
const userConfig = fileUtils.getUserConfig();
|
|
57
|
+
if (userConfig.logs_output_dir === undefined) {
|
|
58
|
+
throw new errors_1.CliError("Missing 'logs_output_dir' config value in config.yaml");
|
|
59
|
+
}
|
|
60
|
+
const allFilePaths = fileUtils.getFilesSortedByUpdatedTime(userConfig.logs_output_dir).filter(path => {
|
|
61
|
+
return path.endsWith('.log');
|
|
62
|
+
});
|
|
63
|
+
if (allFilePaths.length <= 0) {
|
|
64
|
+
throw new errors_1.CliError('No logs available. Please start up hot reloader and the app first to make sure there are logs available');
|
|
65
|
+
}
|
|
66
|
+
let logPath = '';
|
|
67
|
+
if (allFilePaths.length === 1) {
|
|
68
|
+
logPath = allFilePaths[0];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const choices = allFilePaths.map((filePath, index) => ({
|
|
72
|
+
name: `${index + 1}. ${path_1.default.basename(filePath)}`,
|
|
73
|
+
value: filePath,
|
|
74
|
+
}));
|
|
75
|
+
logPath = await (0, cliUtils_1.getUserChoice)(choices, 'Please select the log file to use (this list is ordered by modification time, the most updated log will be displayed first):');
|
|
76
|
+
console.log(logPath);
|
|
77
|
+
}
|
|
78
|
+
readAndWatchFile(logPath);
|
|
79
|
+
}
|
|
80
|
+
exports.command = 'log';
|
|
81
|
+
exports.describe = 'Streams Valdi logs from the connected device to console';
|
|
82
|
+
const builder = () => { };
|
|
83
|
+
exports.builder = builder;
|
|
84
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(showValdiLogs);
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const constants_1 = require("../core/constants");
|
|
9
|
+
const errors_1 = require("../core/errors");
|
|
10
|
+
const BazelClient_1 = require("../utils/BazelClient");
|
|
11
|
+
const cliUtils_1 = require("../utils/cliUtils");
|
|
12
|
+
const copyBootstrapFiles_1 = require("../utils/copyBootstrapFiles");
|
|
13
|
+
const errorUtils_1 = require("../utils/errorUtils");
|
|
14
|
+
const fileUtils_1 = require("../utils/fileUtils");
|
|
15
|
+
const logUtils_1 = require("../utils/logUtils");
|
|
16
|
+
const stringUtils_1 = require("../utils/stringUtils");
|
|
17
|
+
const referenceString = `
|
|
18
|
+
******************************************
|
|
19
|
+
Valdi Module Creation Guide
|
|
20
|
+
******************************************
|
|
21
|
+
|
|
22
|
+
Requirements for Valdi module names:
|
|
23
|
+
- May contain: A-Z, a-z, 0-9, '-', '_', '.'
|
|
24
|
+
- Must start with a letter.
|
|
25
|
+
|
|
26
|
+
Recommended Directory Structure:
|
|
27
|
+
my_application/ # Root directory of your application
|
|
28
|
+
├── WORKSPACE # Bazel Workspace
|
|
29
|
+
├── BUILD.bazel # Bazel build
|
|
30
|
+
└── modules/
|
|
31
|
+
├── module_a/
|
|
32
|
+
│ ├── BUILD.bazel
|
|
33
|
+
│ ├── android/ # Native Android sources
|
|
34
|
+
│ ├── ios/ # Native iOS sources
|
|
35
|
+
│ ├── cpp/ # Native C++ sources
|
|
36
|
+
│ └── src/ # Valdi sources
|
|
37
|
+
│ └── ModuleAComponent.tsx
|
|
38
|
+
├── module_b/
|
|
39
|
+
├── BUILD.bazel
|
|
40
|
+
│ ├── res/ # Image and font resources
|
|
41
|
+
│ ├── strings/ # Localizable strings
|
|
42
|
+
└── src/
|
|
43
|
+
└── ModuleBComponent.tsx
|
|
44
|
+
|
|
45
|
+
For more comprehensive details, refer to the core-module documentation:
|
|
46
|
+
https://github.com/Snapchat/Valdi/blob/main/docs/docs/core-module.md
|
|
47
|
+
|
|
48
|
+
******************************************
|
|
49
|
+
`;
|
|
50
|
+
const ALL_MODULE_TEMPLATES = [
|
|
51
|
+
{
|
|
52
|
+
name: 'UI Component',
|
|
53
|
+
path: 'ui_component',
|
|
54
|
+
description: `Exports a Valdi component, which can render UI elements`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'iOS/Android Bridge module',
|
|
58
|
+
path: 'ios_android_bridge_module',
|
|
59
|
+
description: `Bridge module with a TypeScript API backed by Objective-C and Kotlin implementation`,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'C++ Bridge module',
|
|
63
|
+
path: 'cpp_bridge_module',
|
|
64
|
+
description: `Bridge module with a TypeScript API backed by a cross-platform C++ implementation`,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'iOS/Android View module',
|
|
68
|
+
path: 'ios_android_view_module',
|
|
69
|
+
description: `iOS and Android view exported to TypeScript, rendered through a Valdi component`,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
async function promptChecks() {
|
|
73
|
+
let answers = {};
|
|
74
|
+
const bazelWorkspacePath = await getBazelWorkspaceRoot();
|
|
75
|
+
answers = await inquirer_1.default.prompt([
|
|
76
|
+
{
|
|
77
|
+
type: 'confirm',
|
|
78
|
+
name: 'confirmBazelWorkspace',
|
|
79
|
+
message: 'Bazel WORKSPACE not found (did you run `valdi bootstrap` first?). Continue anyway?',
|
|
80
|
+
default: true,
|
|
81
|
+
when() {
|
|
82
|
+
return !bazelWorkspacePath;
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
], answers);
|
|
86
|
+
if (!bazelWorkspacePath && !answers.confirmBazelWorkspace) {
|
|
87
|
+
throw new errors_1.CliError('Aborting.');
|
|
88
|
+
}
|
|
89
|
+
answers = await inquirer_1.default.prompt({
|
|
90
|
+
type: 'confirm',
|
|
91
|
+
name: 'confirmValdiPath',
|
|
92
|
+
message: '/modules directory not found (did you run `valdi bootstrap` first?). Create module in current directory?',
|
|
93
|
+
default: true,
|
|
94
|
+
when(answers) {
|
|
95
|
+
const curDir = process.cwd();
|
|
96
|
+
const parsedPath = path_1.default.parse(curDir);
|
|
97
|
+
if (parsedPath.base === 'modules') {
|
|
98
|
+
answers.valdiModulePath = curDir;
|
|
99
|
+
}
|
|
100
|
+
else if (curDir === bazelWorkspacePath) {
|
|
101
|
+
const valdiPath = path_1.default.join(curDir, 'modules');
|
|
102
|
+
if (fs_1.default.existsSync(valdiPath)) {
|
|
103
|
+
answers.valdiModulePath = valdiPath;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return !answers.valdiModulePath;
|
|
107
|
+
},
|
|
108
|
+
}, answers);
|
|
109
|
+
if (!answers.valdiModulePath && !answers.confirmValdiPath) {
|
|
110
|
+
throw new errors_1.CliError('Aborting.');
|
|
111
|
+
}
|
|
112
|
+
return answers;
|
|
113
|
+
}
|
|
114
|
+
async function getModuleName(argv) {
|
|
115
|
+
return argv.getArgumentOrResolve('moduleName', async () => {
|
|
116
|
+
const result = await inquirer_1.default.prompt([
|
|
117
|
+
{
|
|
118
|
+
type: 'input',
|
|
119
|
+
name: 'moduleName',
|
|
120
|
+
message: 'Please provide a name for this module:',
|
|
121
|
+
validate: (input) => {
|
|
122
|
+
const isEmpty = input === '';
|
|
123
|
+
if (isEmpty) {
|
|
124
|
+
throw new errors_1.CliError('Module name cannot be empty.');
|
|
125
|
+
}
|
|
126
|
+
const snakeCaseName = (0, stringUtils_1.toSnakeCase)(input);
|
|
127
|
+
const isSnakeCase = snakeCaseName === input;
|
|
128
|
+
if (!isSnakeCase) {
|
|
129
|
+
throw new errors_1.CliError(`Valid names may contain only A-Z, a-z, 0-9, '-', '_', '.', and must start with a letter (ie: '${snakeCaseName}').`);
|
|
130
|
+
}
|
|
131
|
+
const destPath = path_1.default.join(process.cwd(), input);
|
|
132
|
+
if ((0, fileUtils_1.fileExists)(destPath)) {
|
|
133
|
+
throw new errors_1.CliError(`Path ${destPath} already exists. Choose a different name or delete the folder and try again.`);
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
], {});
|
|
139
|
+
return result.moduleName ?? '';
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async function finalConfirmation(destPath, argv) {
|
|
143
|
+
return argv.getArgumentOrResolve('skipChecks', async () => {
|
|
144
|
+
const confirmMessage = `
|
|
145
|
+
Create module?
|
|
146
|
+
Path: ${(0, logUtils_1.wrapInColor)(destPath, constants_1.ANSI_COLORS.GREEN_COLOR)}
|
|
147
|
+
`;
|
|
148
|
+
const answers = await inquirer_1.default.prompt([
|
|
149
|
+
{
|
|
150
|
+
type: 'confirm',
|
|
151
|
+
name: 'confirm',
|
|
152
|
+
message: confirmMessage,
|
|
153
|
+
default: true,
|
|
154
|
+
},
|
|
155
|
+
], {});
|
|
156
|
+
return answers.confirm ?? false;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function getBazelWorkspaceRoot() {
|
|
160
|
+
return new BazelClient_1.BazelClient().getWorkspaceRoot();
|
|
161
|
+
}
|
|
162
|
+
async function valdiNewModule(argv) {
|
|
163
|
+
console.log(referenceString);
|
|
164
|
+
const skipChecks = argv.getArgument('skipChecks');
|
|
165
|
+
const checks = skipChecks ? {} : await promptChecks();
|
|
166
|
+
const valdiModulePath = checks.valdiModulePath ?? path_1.default.join(await getBazelWorkspaceRoot(), 'modules');
|
|
167
|
+
const moduleName = await getModuleName(argv);
|
|
168
|
+
const destPath = path_1.default.join(valdiModulePath, moduleName);
|
|
169
|
+
const didConfirm = skipChecks || (await finalConfirmation(destPath, argv));
|
|
170
|
+
if (!didConfirm) {
|
|
171
|
+
throw new errors_1.CliError('Cancelled new module creation.');
|
|
172
|
+
}
|
|
173
|
+
if (fs_1.default.existsSync(destPath)) {
|
|
174
|
+
throw new errors_1.CliError(`Path already exists ${destPath}`);
|
|
175
|
+
}
|
|
176
|
+
const choices = ALL_MODULE_TEMPLATES.map(target => ({
|
|
177
|
+
name: `${(0, logUtils_1.wrapInColor)(target.name, constants_1.ANSI_COLORS.GREEN_COLOR)} . ${target.description}`,
|
|
178
|
+
value: target,
|
|
179
|
+
}));
|
|
180
|
+
const templateOption = argv.getArgument('template');
|
|
181
|
+
const template = templateOption ? ALL_MODULE_TEMPLATES.find(template => template.path === templateOption) : undefined;
|
|
182
|
+
const moduleTemplate = template ?? await (0, cliUtils_1.getUserChoice)(choices, `Please choose the module type:`);
|
|
183
|
+
const sourcePath = path_1.default.join(constants_1.BOOTSTRAP_DIR_PATH, 'modules', moduleTemplate.path);
|
|
184
|
+
const replacements = {
|
|
185
|
+
MODULE_NAME: moduleName,
|
|
186
|
+
MODULE_NAME_PASCAL_CASED: (0, stringUtils_1.toPascalCase)(moduleName),
|
|
187
|
+
};
|
|
188
|
+
(0, copyBootstrapFiles_1.copyBootstrapFiles)(sourcePath, destPath, replacements);
|
|
189
|
+
console.log(`Success! New module directory: ${(0, logUtils_1.wrapInColor)(destPath, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
|
|
190
|
+
}
|
|
191
|
+
exports.command = `new_module [module-name]`;
|
|
192
|
+
exports.describe = referenceString;
|
|
193
|
+
const builder = (yargs) => {
|
|
194
|
+
yargs
|
|
195
|
+
.positional('module-name', {
|
|
196
|
+
describe: 'Name of the Valdi module.',
|
|
197
|
+
})
|
|
198
|
+
.option('template', {
|
|
199
|
+
describe: 'module template to use, will skip the prompt',
|
|
200
|
+
choices: ALL_MODULE_TEMPLATES.map(template => template.path),
|
|
201
|
+
})
|
|
202
|
+
.option('skip-checks', {
|
|
203
|
+
describe: 'Skips confirmation prompts.',
|
|
204
|
+
type: 'boolean',
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
exports.builder = builder;
|
|
208
|
+
exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiNewModule);
|