@betty-blocks/cli 26.0.0-beta.9 → 26.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/README.md +2 -16
- package/assets/app-functions/wasm-template/.wasm-functions +0 -0
- package/assets/app-functions/wasm-template/functions/say-hello/1.0/Cargo.lock +449 -0
- package/assets/app-functions/wasm-template/functions/say-hello/1.0/Cargo.toml +10 -0
- package/assets/app-functions/wasm-template/functions/say-hello/1.0/Justfile +12 -0
- package/assets/app-functions/wasm-template/functions/say-hello/1.0/function.json +35 -0
- package/assets/app-functions/wasm-template/functions/say-hello/1.0/src/lib.rs +19 -0
- package/assets/app-functions/wasm-template/functions/say-hello/1.0/wit/world.wit +13 -0
- package/build/bb-blocks-new.d.ts +1 -0
- package/build/bb-blocks-new.js +26 -0
- package/build/bb-blocks-new.js.map +1 -0
- package/build/bb-blocks-publish.d.ts +1 -0
- package/build/bb-blocks-publish.js +98 -0
- package/build/bb-blocks-publish.js.map +1 -0
- package/build/bb-blocks-release.d.ts +1 -0
- package/build/bb-blocks-release.js +18 -0
- package/build/bb-blocks-release.js.map +1 -0
- package/build/bb-blocks.d.ts +1 -0
- package/build/bb-blocks.js +17 -0
- package/build/bb-blocks.js.map +1 -0
- package/build/bb-bundle-init.d.ts +1 -0
- package/build/bb-bundle-init.js +33 -0
- package/build/bb-bundle-init.js.map +1 -0
- package/build/bb-bundle.d.ts +1 -0
- package/build/bb-bundle.js +17 -0
- package/build/bb-bundle.js.map +1 -0
- package/build/bb-components-build.d.ts +1 -0
- package/build/bb-components-build.js +416 -0
- package/build/bb-components-build.js.map +1 -0
- package/build/bb-components-create.d.ts +1 -0
- package/build/bb-components-create.js +41 -0
- package/build/bb-components-create.js.map +1 -0
- package/build/bb-components-generate.d.ts +1 -0
- package/build/bb-components-generate.js +168 -0
- package/build/bb-components-generate.js.map +1 -0
- package/build/bb-components-publish-bundle.d.ts +1 -0
- package/build/bb-components-publish-bundle.js +50 -0
- package/build/bb-components-publish-bundle.js.map +1 -0
- package/build/bb-components-publish.d.ts +1 -0
- package/build/bb-components-publish.js +57 -0
- package/build/bb-components-publish.js.map +1 -0
- package/build/bb-components-serve.d.ts +1 -0
- package/build/bb-components-serve.js +35 -0
- package/build/bb-components-serve.js.map +1 -0
- package/build/bb-components.d.ts +1 -0
- package/build/bb-components.js +29 -0
- package/build/bb-components.js.map +1 -0
- package/build/bb-functions-bump.d.ts +1 -0
- package/build/bb-functions-bump.js +37 -0
- package/build/bb-functions-bump.js.map +1 -0
- package/build/bb-functions-init.d.ts +1 -0
- package/build/bb-functions-init.js +31 -0
- package/build/bb-functions-init.js.map +1 -0
- package/build/bb-functions-login.d.ts +1 -0
- package/build/bb-functions-login.js +17 -0
- package/build/bb-functions-login.js.map +1 -0
- package/build/bb-functions-logout.d.ts +1 -0
- package/build/bb-functions-logout.js +10 -0
- package/build/bb-functions-logout.js.map +1 -0
- package/build/bb-functions-new.d.ts +1 -0
- package/build/bb-functions-new.js +25 -0
- package/build/bb-functions-new.js.map +1 -0
- package/build/bb-functions-publish.d.ts +1 -0
- package/build/bb-functions-publish.js +52 -0
- package/build/bb-functions-publish.js.map +1 -0
- package/build/bb-functions-validate.d.ts +1 -0
- package/build/bb-functions-validate.js +17 -0
- package/build/bb-functions-validate.js.map +1 -0
- package/build/bb-functions.d.ts +1 -0
- package/build/bb-functions.js +29 -0
- package/build/bb-functions.js.map +1 -0
- package/build/bb.d.ts +2 -0
- package/build/bb.js +27 -0
- package/build/bb.js.map +1 -0
- package/build/blocks/blockDefinitions.d.ts +10 -0
- package/build/blocks/blockDefinitions.js +62 -0
- package/build/blocks/blockDefinitions.js.map +1 -0
- package/build/blocks/publishBlocks.d.ts +2 -0
- package/build/blocks/publishBlocks.js +54 -0
- package/build/blocks/publishBlocks.js.map +1 -0
- package/build/blocks/releaseBlocks.d.ts +5 -0
- package/build/blocks/releaseBlocks.js +78 -0
- package/build/blocks/releaseBlocks.js.map +1 -0
- package/build/components/bb-components-functions.d.ts +10 -0
- package/build/components/bb-components-functions.js +40 -0
- package/build/components/bb-components-functions.js.map +1 -0
- package/build/components/comments.d.ts +3 -0
- package/build/components/comments.js +78 -0
- package/build/components/comments.js.map +1 -0
- package/build/components/compatibility.d.ts +7 -0
- package/build/components/compatibility.js +60 -0
- package/build/components/compatibility.js.map +1 -0
- package/build/components/transformers/index.d.ts +3 -0
- package/build/components/transformers/index.js +36 -0
- package/build/components/transformers/index.js.map +1 -0
- package/build/components-build/index.d.ts +2 -0
- package/build/components-build/index.js +3 -0
- package/build/components-build/index.js.map +1 -0
- package/build/components-build/reportDiagnostics.d.ts +2 -0
- package/build/components-build/reportDiagnostics.js +13 -0
- package/build/components-build/reportDiagnostics.js.map +1 -0
- package/build/components-build/styles.d.ts +4 -0
- package/build/components-build/styles.js +87 -0
- package/build/components-build/styles.js.map +1 -0
- package/build/functions/config.d.ts +67 -0
- package/build/functions/config.js +190 -0
- package/build/functions/config.js.map +1 -0
- package/build/functions/createWasmDefinitionFiles.d.ts +4 -0
- package/build/functions/createWasmDefinitionFiles.js +61 -0
- package/build/functions/createWasmDefinitionFiles.js.map +1 -0
- package/build/functions/functionDefinitions.d.ts +23 -0
- package/build/functions/functionDefinitions.js +229 -0
- package/build/functions/functionDefinitions.js.map +1 -0
- package/build/functions/functionVersionBump.d.ts +19 -0
- package/build/functions/functionVersionBump.js +62 -0
- package/build/functions/functionVersionBump.js.map +1 -0
- package/build/functions/publishAppFunctions.d.ts +13 -0
- package/build/functions/publishAppFunctions.js +90 -0
- package/build/functions/publishAppFunctions.js.map +1 -0
- package/build/functions/publishWasmBlockStoreFunctions.d.ts +1 -0
- package/build/functions/publishWasmBlockStoreFunctions.js +100 -0
- package/build/functions/publishWasmBlockStoreFunctions.js.map +1 -0
- package/build/functions/utils.d.ts +2 -0
- package/build/functions/utils.js +20 -0
- package/build/functions/utils.js.map +1 -0
- package/build/functions/validateFunctions.d.ts +3 -0
- package/build/functions/validateFunctions.js +23 -0
- package/build/functions/validateFunctions.js.map +1 -0
- package/build/functions/validations.d.ts +31 -0
- package/build/functions/validations.js +140 -0
- package/build/functions/validations.js.map +1 -0
- package/build/interactions/compatibility.d.ts +3 -0
- package/build/interactions/compatibility.js +84 -0
- package/build/interactions/compatibility.js.map +1 -0
- package/build/interactions/diagnostics.d.ts +2 -0
- package/build/interactions/diagnostics.js +23 -0
- package/build/interactions/diagnostics.js.map +1 -0
- package/build/types.d.ts +377 -0
- package/build/types.js +40 -0
- package/build/types.js.map +1 -0
- package/build/utils/arguments.d.ts +2 -0
- package/build/utils/arguments.js +6 -0
- package/build/utils/arguments.js.map +1 -0
- package/build/utils/checkPackageVersion.d.ts +1 -0
- package/build/utils/checkPackageVersion.js +10 -0
- package/build/utils/checkPackageVersion.js.map +1 -0
- package/build/utils/checkUpdateAvailable.d.ts +1 -0
- package/build/utils/checkUpdateAvailable.js +65 -0
- package/build/utils/checkUpdateAvailable.js.map +1 -0
- package/build/utils/fusionAuth.d.ts +21 -0
- package/build/utils/fusionAuth.js +108 -0
- package/build/utils/fusionAuth.js.map +1 -0
- package/build/utils/hash.d.ts +2 -0
- package/build/utils/hash.js +3 -0
- package/build/utils/hash.js.map +1 -0
- package/build/utils/login.d.ts +15 -0
- package/build/utils/login.js +116 -0
- package/build/utils/login.js.map +1 -0
- package/build/utils/pick.d.ts +7 -0
- package/build/utils/pick.js +16 -0
- package/build/utils/pick.js.map +1 -0
- package/build/utils/readFilesByType.d.ts +2 -0
- package/build/utils/readFilesByType.js +23 -0
- package/build/utils/readFilesByType.js.map +1 -0
- package/build/utils/rootDir.d.ts +2 -0
- package/build/utils/rootDir.js +4 -0
- package/build/utils/rootDir.js.map +1 -0
- package/build/utils/serveComponentSet.d.ts +3 -0
- package/build/utils/serveComponentSet.js +52 -0
- package/build/utils/serveComponentSet.js.map +1 -0
- package/build/utils/transpile.d.ts +2 -0
- package/build/utils/transpile.js +25 -0
- package/build/utils/transpile.js.map +1 -0
- package/build/utils/uploadBlob.d.ts +24 -0
- package/build/utils/uploadBlob.js +56 -0
- package/build/utils/uploadBlob.js.map +1 -0
- package/build/utils/validation.d.ts +4 -0
- package/build/utils/validation.js +74 -0
- package/build/utils/validation.js.map +1 -0
- package/build/validations/component.d.ts +3 -0
- package/build/validations/component.js +56 -0
- package/build/validations/component.js.map +1 -0
- package/build/validations/constants.d.ts +16 -0
- package/build/validations/constants.js +208 -0
- package/build/validations/constants.js.map +1 -0
- package/build/validations/function-block-validations/index.d.ts +22 -0
- package/build/validations/function-block-validations/index.js +72 -0
- package/build/validations/function-block-validations/index.js.map +1 -0
- package/build/validations/interaction.d.ts +3 -0
- package/build/validations/interaction.js +22 -0
- package/build/validations/interaction.js.map +1 -0
- package/build/validations/prefab/action.d.ts +2 -0
- package/build/validations/prefab/action.js +99 -0
- package/build/validations/prefab/action.js.map +1 -0
- package/build/validations/prefab/component.d.ts +10 -0
- package/build/validations/prefab/component.js +290 -0
- package/build/validations/prefab/component.js.map +1 -0
- package/build/validations/prefab/componentOption.d.ts +3 -0
- package/build/validations/prefab/componentOption.js +176 -0
- package/build/validations/prefab/componentOption.js.map +1 -0
- package/build/validations/prefab/interaction.d.ts +2 -0
- package/build/validations/prefab/interaction.js +38 -0
- package/build/validations/prefab/interaction.js.map +1 -0
- package/build/validations/prefab/linkedOption.d.ts +3 -0
- package/build/validations/prefab/linkedOption.js +39 -0
- package/build/validations/prefab/linkedOption.js.map +1 -0
- package/build/validations/prefab/linkedPartial.d.ts +3 -0
- package/build/validations/prefab/linkedPartial.js +30 -0
- package/build/validations/prefab/linkedPartial.js.map +1 -0
- package/build/validations/prefab/variable.d.ts +3 -0
- package/build/validations/prefab/variable.js +36 -0
- package/build/validations/prefab/variable.js.map +1 -0
- package/build/validations/prefab.d.ts +17 -0
- package/build/validations/prefab.js +66 -0
- package/build/validations/prefab.js.map +1 -0
- package/build/validations/styles.d.ts +6 -0
- package/build/validations/styles.js +103 -0
- package/build/validations/styles.js.map +1 -0
- package/package.json +38 -40
- package/assets/app-functions/templates/test/helpers.js +0 -3
- package/assets/app-functions/templates/test/say-hello.test.js +0 -4
- package/assets/functions/packer/package.json +0 -9
- package/assets/functions/packer/webpack.config.js +0 -12
- package/assets/functions/templates/functions.json +0 -14
- package/assets/functions/templates/package.json +0 -11
- package/assets/functions/templates/src/all-users.js +0 -14
- package/assets/functions/templates/src/get-json.js +0 -9
- package/assets/functions/templates/src/index.js +0 -5
- package/assets/functions/templates/src/say-hello.js +0 -13
- package/build/src/bb-blocks-new.js +0 -6789
- package/build/src/bb-blocks-publish.js +0 -32641
- package/build/src/bb-blocks-release.js +0 -15528
- package/build/src/bb-blocks.js +0 -2149
- package/build/src/bb-bundle-init.js +0 -6034
- package/build/src/bb-bundle.js +0 -2636
- package/build/src/bb-components-build.js +0 -240546
- package/build/src/bb-components-create.js +0 -6045
- package/build/src/bb-components-generate.js +0 -6173
- package/build/src/bb-components-publish-bundle.js +0 -43346
- package/build/src/bb-components-publish.js +0 -43353
- package/build/src/bb-components-serve.js +0 -15326
- package/build/src/bb-components.js +0 -2157
- package/build/src/bb-functions-build.js +0 -4284
- package/build/src/bb-functions-bump.js +0 -14582
- package/build/src/bb-functions-init.js +0 -4749
- package/build/src/bb-functions-login.js +0 -15440
- package/build/src/bb-functions-logout.js +0 -15434
- package/build/src/bb-functions-new.js +0 -9144
- package/build/src/bb-functions-publish.js +0 -86693
- package/build/src/bb-functions-validate.js +0 -22160
- package/build/src/bb-functions.js +0 -2159
- package/build/src/bb.js +0 -2740
- /package/assets/app-functions/{templates → js-template}/.app-functions +0 -0
- /package/assets/app-functions/{templates → js-template}/functions/say-hello/1.0/function.json +0 -0
- /package/assets/app-functions/{templates → js-template}/functions/say-hello/1.0/index.js +0 -0
- /package/assets/app-functions/{templates → js-template}/package.json +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import AdmZip from 'adm-zip';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import prompts from 'prompts';
|
|
7
|
+
import { blockDefinitions, createPackageJson, } from './blocks/blockDefinitions';
|
|
8
|
+
import publishBlocks from './blocks/publishBlocks';
|
|
9
|
+
import { functionDefinitions, generateIndex, whitelistedFunctions, } from './functions/functionDefinitions';
|
|
10
|
+
import { validateBlock, validateBlockConfig, } from './validations/function-block-validations';
|
|
11
|
+
const program = new Command();
|
|
12
|
+
program.option('--all').name('bb blocks publish').parse(process.argv);
|
|
13
|
+
const workingDir = process.cwd();
|
|
14
|
+
const baseBlocksPath = path.join(workingDir, 'blocks');
|
|
15
|
+
const blocks = await blockDefinitions(baseBlocksPath);
|
|
16
|
+
const createBlockZip = async (name, { functions, includes, dependencies }) => {
|
|
17
|
+
const zip = new AdmZip();
|
|
18
|
+
const tmpDir = '.tmp';
|
|
19
|
+
const zipFilePath = path.join(tmpDir, `${name}.zip`);
|
|
20
|
+
fs.ensureDirSync(tmpDir);
|
|
21
|
+
try {
|
|
22
|
+
const functionsDir = path.join(workingDir, 'functions');
|
|
23
|
+
const blocksDir = path.join(workingDir, 'blocks');
|
|
24
|
+
const rootPackageJson = path.join(path.dirname(blocksDir), 'package.json');
|
|
25
|
+
zip.addFile('package.json', Buffer.from(createPackageJson(name, rootPackageJson, dependencies)));
|
|
26
|
+
zip.addFile('index.js', Buffer.from(await generateIndex(functionsDir, functions)));
|
|
27
|
+
const funcDefinitions = await functionDefinitions(functionsDir);
|
|
28
|
+
const blockFunctions = whitelistedFunctions(funcDefinitions, functions);
|
|
29
|
+
blockFunctions.forEach((blockFunction) => {
|
|
30
|
+
const functionDir = path.dirname(blockFunction.path);
|
|
31
|
+
zip.addLocalFolder(functionDir, functionDir.replace(workingDir, ''));
|
|
32
|
+
});
|
|
33
|
+
includes.forEach((include) => {
|
|
34
|
+
zip.addLocalFolder(path.join(workingDir, include), include);
|
|
35
|
+
});
|
|
36
|
+
zip.writeZip(zipFilePath);
|
|
37
|
+
return zipFilePath;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`in ${name}: ${error}`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
void (async () => {
|
|
44
|
+
const choices = blocks.map((block) => ({
|
|
45
|
+
title: path.basename(block, '.json'),
|
|
46
|
+
value: block,
|
|
47
|
+
}));
|
|
48
|
+
const { all } = program.opts();
|
|
49
|
+
let selected = [];
|
|
50
|
+
if (all) {
|
|
51
|
+
selected = blocks;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const results = (await prompts([
|
|
55
|
+
{
|
|
56
|
+
choices,
|
|
57
|
+
instructions: false,
|
|
58
|
+
message: 'Which blocks do you want to publish?',
|
|
59
|
+
name: 'selected',
|
|
60
|
+
type: 'multiselect',
|
|
61
|
+
},
|
|
62
|
+
]));
|
|
63
|
+
({ selected } = results);
|
|
64
|
+
}
|
|
65
|
+
selected.forEach((jsonFile) => {
|
|
66
|
+
void (async () => {
|
|
67
|
+
const block = fs.readJsonSync(jsonFile);
|
|
68
|
+
const name = path.basename(jsonFile, '.json');
|
|
69
|
+
if (validateBlockConfig(block)) {
|
|
70
|
+
try {
|
|
71
|
+
const functionsDir = path.join(workingDir, 'functions');
|
|
72
|
+
const funcDefinitions = await functionDefinitions(functionsDir);
|
|
73
|
+
const blockFunctions = whitelistedFunctions(funcDefinitions, block.functions);
|
|
74
|
+
const { valid, errorMessage } = await validateBlock({
|
|
75
|
+
block,
|
|
76
|
+
blockFunctions,
|
|
77
|
+
blockName: name,
|
|
78
|
+
});
|
|
79
|
+
if (valid) {
|
|
80
|
+
const zip = await createBlockZip(name, block);
|
|
81
|
+
if (zip)
|
|
82
|
+
await publishBlocks(block.functions, zip);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw Error(chalk.red(`\n${errorMessage}\n`));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new Error(`in ${name}: ${error}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.error(chalk.red(`\nFunctions can not be empty\n`));
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
});
|
|
97
|
+
})();
|
|
98
|
+
//# sourceMappingURL=bb-blocks-publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bb-blocks-publish.js","sourceRoot":"","sources":["../src/bb-blocks-publish.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAEL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,aAAa,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0CAA0C,CAAC;AAElD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AACjC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACvD,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAEtD,MAAM,cAAc,GAAG,KAAK,EAC1B,IAAY,EACZ,EAAE,SAAS,EAAE,QAAQ,EA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|
|
2
|
+
import releaseBlocks from './blocks/releaseBlocks';
|
|
3
|
+
const program = new Command();
|
|
4
|
+
program
|
|
5
|
+
.usage('[options] [blockIds...]')
|
|
6
|
+
.option('-a, --all', 'release all dev blocks that are attached to your account')
|
|
7
|
+
.name('bb blocks release')
|
|
8
|
+
.parse(process.argv);
|
|
9
|
+
const { all } = program.opts();
|
|
10
|
+
const blockIds = program.args;
|
|
11
|
+
if (!all && !blockIds.length) {
|
|
12
|
+
console.error('No block IDs provided');
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
void (async () => {
|
|
16
|
+
await releaseBlocks({ all, blockIds });
|
|
17
|
+
})();
|
|
18
|
+
//# sourceMappingURL=bb-blocks-release.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bb-blocks-release.js","sourceRoot":"","sources":["../src/bb-blocks-release.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,aAAa,MAAM,wBAAwB,CAAC;AAEnD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,KAAK,CAAC,yBAAyB,CAAC;KAChC,MAAM,CACL,WAAW,EACX,0DAA0D,CAC3D;KACA,IAAI,CAAC,mBAAmB,CAAC;KACzB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,MAAM,EAAE,GAAG,EAAE,GAAsB,OAAO,CAAC,IAAI,EAAE,CAAC;AAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;AAE9B,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC7B,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,KAAK,CAAC,KAAK,IAAmB,EAAE;IAC9B,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;AACzC,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
const availableCommands = ['publish', 'release', 'new'];
|
|
3
|
+
const program = new Command();
|
|
4
|
+
program
|
|
5
|
+
.usage(`<${availableCommands.join('|')}>`)
|
|
6
|
+
.name('bb blocks')
|
|
7
|
+
.command('new [blocks-name]', 'Initialize a new block')
|
|
8
|
+
.command('publish', 'publish blocks of current working directory')
|
|
9
|
+
.command('release', 'release dev blocks')
|
|
10
|
+
.on('command:*', ([command]) => {
|
|
11
|
+
if (!availableCommands.includes(command)) {
|
|
12
|
+
console.error('Invalid command: %s\n', command);
|
|
13
|
+
program.outputHelp();
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
.parse(process.argv);
|
|
17
|
+
//# sourceMappingURL=bb-blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bb-blocks.js","sourceRoot":"","sources":["../src/bb-blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,MAAM,iBAAiB,GAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAEzE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,KAAK,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;KACzC,IAAI,CAAC,WAAW,CAAC;KACjB,OAAO,CAAC,mBAAmB,EAAE,wBAAwB,CAAC;KACtD,OAAO,CAAC,SAAS,EAAE,6CAA6C,CAAC;KACjE,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC;KACxC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAW,EAAQ,EAAE;IAC7C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAwB,CAAC,EAAE,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;QAChD,OAAO,CAAC,UAAU,EAAE,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;KACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* npm dependencies */
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { copy, existsSync, moveSync } from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { checkUpdateAvailableCLI } from './utils/checkUpdateAvailable';
|
|
7
|
+
const program = new Command();
|
|
8
|
+
program
|
|
9
|
+
.argument('<path>', 'path where to initialize the bundle')
|
|
10
|
+
.name('bb bundle init')
|
|
11
|
+
.parse(process.argv);
|
|
12
|
+
const { args } = program;
|
|
13
|
+
if (args.length === 0) {
|
|
14
|
+
program.help();
|
|
15
|
+
}
|
|
16
|
+
const dest = args[0];
|
|
17
|
+
if (existsSync(dest)) {
|
|
18
|
+
throw Error(chalk.red(`\nCould not initialize bundle: directory (${dest}) already exists.\n`));
|
|
19
|
+
}
|
|
20
|
+
void (async () => {
|
|
21
|
+
await checkUpdateAvailableCLI();
|
|
22
|
+
try {
|
|
23
|
+
await copy(path.join(__dirname, '../assets/bundle'), dest);
|
|
24
|
+
moveSync(`${dest}/__package.json`, `${dest}/package.json`);
|
|
25
|
+
console.log(chalk.green(`Bundle succesfully initialized in directory '${dest}'.`));
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error instanceof Error) {
|
|
29
|
+
throw Error(chalk.red(`\nCould not initialize bundle in directory ${dest}: ${error.message}.\n`));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
//# source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AK,CAAC,KAAK,CAAC,gDAAgD,IAAI,IAAI,CAAC,CACtE,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,KAAK,CACT,KAAK,CAAC,GAAG,CACP,8CAA8C,IAAI,KAAK,KAAK,CAAC,OAAO,KAAK,CAC1E,CACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* npm dependencies */
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
const availableCommands = ['init'];
|
|
5
|
+
const program = new Command();
|
|
6
|
+
program
|
|
7
|
+
.usage(`<${availableCommands.join('|')}>`)
|
|
8
|
+
.name('bb bundle')
|
|
9
|
+
.command('init <path>', 'create a new vendor bundle')
|
|
10
|
+
.on('command:*', ([command]) => {
|
|
11
|
+
if (!availableCommands.includes(command)) {
|
|
12
|
+
console.error(chalk.red('\nInvalid command: %s\n'), command);
|
|
13
|
+
program.outputHelp();
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
.parse(process.argv);
|
|
17
|
+
//# sourceMappingURL=bb-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bb-bundle.js","sourceRoot":"","sources":["../src/bb-bundle.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,MAAM,iBAAiB,GAAoB,CAAC,MAAM,CAAC,CAAC;AAEpD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,KAAK,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;KACzC,IAAI,CAAC,WAAW,CAAC;KACjB,OAAO,CAAC,aAAa,EAAE,4BAA4B,CAAC;KACpD,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAW,EAAQ,EAAE;IAC7C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAwB,CAAC,EAAE,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7D,OAAO,CAAC,UAAU,EAAE,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;KACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { ensureDir, outputJson, pathExists, readFile, readFileSync, remove, } from 'fs-extra';
|
|
5
|
+
import ora from 'ora';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import ts, { JsxEmit, ModuleKind, ScriptTarget } from 'typescript';
|
|
8
|
+
import extractComponentCompatibility from './components/compatibility';
|
|
9
|
+
import { doTranspile } from './components/transformers';
|
|
10
|
+
import { buildReferenceStyle, buildStyle, readStyles, reportDiagnostics, } from './components-build';
|
|
11
|
+
import extractInteractionCompatibility from './interactions/compatibility';
|
|
12
|
+
import getDiagnostics from './interactions/diagnostics';
|
|
13
|
+
import { parseDir } from './utils/arguments';
|
|
14
|
+
import { checkPackageVersion } from './utils/checkPackageVersion';
|
|
15
|
+
import { checkUpdateAvailableCLI } from './utils/checkUpdateAvailable';
|
|
16
|
+
import hash from './utils/hash';
|
|
17
|
+
import readFilesByType from './utils/readFilesByType';
|
|
18
|
+
import transpile from './utils/transpile';
|
|
19
|
+
import { checkNameReferences, checkOptionCategoryReferences, } from './utils/validation';
|
|
20
|
+
import validateComponents from './validations/component';
|
|
21
|
+
import validateInteractions from './validations/interaction';
|
|
22
|
+
import validatePrefabs from './validations/prefab';
|
|
23
|
+
import validateStyles from './validations/styles';
|
|
24
|
+
const program = new Command();
|
|
25
|
+
program
|
|
26
|
+
.usage('[path]')
|
|
27
|
+
.name('bb components build')
|
|
28
|
+
.option('-t, --transpile', 'enable new transpilation')
|
|
29
|
+
.option('--offline', 'skip update check')
|
|
30
|
+
.option('--fast', 'Build the last edited component.')
|
|
31
|
+
.parse(process.argv);
|
|
32
|
+
const { args } = program;
|
|
33
|
+
const options = program.opts();
|
|
34
|
+
const rootDir = parseDir(args);
|
|
35
|
+
const distDir = `${rootDir}/dist`;
|
|
36
|
+
const enableNewTranspile = !!options.transpile;
|
|
37
|
+
const arg = process.argv.slice(2);
|
|
38
|
+
const startTime = Date.now();
|
|
39
|
+
const buildAll = !arg.includes('--fast');
|
|
40
|
+
const hasOfflineFlag = arg.includes('--offline');
|
|
41
|
+
/* execute command */
|
|
42
|
+
const readComponents = async () => {
|
|
43
|
+
const srcDir = `${rootDir}/src/components`;
|
|
44
|
+
const exists = await pathExists(srcDir);
|
|
45
|
+
if (!exists) {
|
|
46
|
+
throw new Error(chalk.red('\nComponents folder not found\n'));
|
|
47
|
+
}
|
|
48
|
+
const componentFiles = await readFilesByType(srcDir, 'js', buildAll);
|
|
49
|
+
const components = componentFiles.map(async (file) => {
|
|
50
|
+
try {
|
|
51
|
+
const code = await readFile(`${srcDir}/${file}`, 'utf-8');
|
|
52
|
+
const compatibility = extractComponentCompatibility(code);
|
|
53
|
+
const transpiledFunction = Function(`return ${transpile(code, ['jsx', 'styles'])}`)();
|
|
54
|
+
if (!transpiledFunction) {
|
|
55
|
+
throw new Error("Component doesn't return anything");
|
|
56
|
+
}
|
|
57
|
+
if (enableNewTranspile) {
|
|
58
|
+
transpiledFunction.transpiledJsx = doTranspile(transpiledFunction.jsx);
|
|
59
|
+
transpiledFunction.transpiledStyles = doTranspile(transpiledFunction.styles);
|
|
60
|
+
}
|
|
61
|
+
if (transpiledFunction.dependencies && !hasOfflineFlag) {
|
|
62
|
+
const usedPackages = transpiledFunction.dependencies.map((usedDependency) => usedDependency.package);
|
|
63
|
+
const dependencyPromises = usedPackages.map(async (usedPackage) => {
|
|
64
|
+
await checkPackageVersion(usedPackage.replace(/^npm:/g, ''));
|
|
65
|
+
});
|
|
66
|
+
await Promise.all(dependencyPromises);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...compatibility,
|
|
70
|
+
...transpiledFunction,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`in ${file}: ${error}`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return Promise.all(components);
|
|
78
|
+
};
|
|
79
|
+
const readtsPrefabs = async (isPartial = false) => {
|
|
80
|
+
const absoluteRootDir = path.resolve(process.cwd(), rootDir);
|
|
81
|
+
const srcDir = `${absoluteRootDir}/src/prefabs`;
|
|
82
|
+
const outDir = `${absoluteRootDir}/tmp/${Math.floor(Date.now() / 1000)}`;
|
|
83
|
+
const exists = await pathExists(srcDir);
|
|
84
|
+
if (!exists) {
|
|
85
|
+
throw new Error(chalk.red('\nPrefabs folder not found\n'));
|
|
86
|
+
}
|
|
87
|
+
let prefabTsFiles = [];
|
|
88
|
+
let prefabTsxFiles = [];
|
|
89
|
+
let partialTsxFiles = [];
|
|
90
|
+
if (isPartial) {
|
|
91
|
+
partialTsxFiles = await readFilesByType(`${srcDir}/partials`, 'tsx', buildAll);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
prefabTsFiles = await readFilesByType(srcDir, 'ts', buildAll);
|
|
95
|
+
prefabTsxFiles = await readFilesByType(srcDir, 'tsx', buildAll);
|
|
96
|
+
}
|
|
97
|
+
const prefabFiles = [...prefabTsFiles, ...prefabTsxFiles];
|
|
98
|
+
const files = isPartial ? partialTsxFiles : prefabFiles;
|
|
99
|
+
const basePath = isPartial ? `${srcDir}/partials/` : `${srcDir}/`;
|
|
100
|
+
const prefabProgram = ts.createProgram(files.map((file) => `${basePath}/${file}`), {
|
|
101
|
+
allowSyntheticDefaultImports: false,
|
|
102
|
+
esModuleInterop: true,
|
|
103
|
+
jsx: JsxEmit.React,
|
|
104
|
+
listEmittedFiles: true,
|
|
105
|
+
module: ModuleKind.CommonJS,
|
|
106
|
+
outDir,
|
|
107
|
+
target: ScriptTarget.ESNext,
|
|
108
|
+
});
|
|
109
|
+
const diagnostics = [...ts.getPreEmitDiagnostics(prefabProgram)];
|
|
110
|
+
if (diagnostics.length > 0) {
|
|
111
|
+
reportDiagnostics(diagnostics);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
const results = prefabProgram.emit();
|
|
115
|
+
if (results.diagnostics.length > 0) {
|
|
116
|
+
reportDiagnostics([...results.diagnostics]);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
const globalDiagnostics = [...prefabProgram.getGlobalDiagnostics()];
|
|
120
|
+
if (globalDiagnostics.length > 0) {
|
|
121
|
+
reportDiagnostics(globalDiagnostics);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
const declarationDiagnostics = [...prefabProgram.getDeclarationDiagnostics()];
|
|
125
|
+
if (declarationDiagnostics.length > 0) {
|
|
126
|
+
reportDiagnostics(declarationDiagnostics);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
const configDiagnostics = [
|
|
130
|
+
...prefabProgram.getConfigFileParsingDiagnostics(),
|
|
131
|
+
];
|
|
132
|
+
if (configDiagnostics.length > 0) {
|
|
133
|
+
reportDiagnostics(configDiagnostics);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
const prefabs = (results.emittedFiles ?? [])
|
|
137
|
+
.filter((filename) => isPartial
|
|
138
|
+
? /prefabs\/partials\/\w+\.js$/.test(filename)
|
|
139
|
+
: /prefabs\/\w+\.js$/.test(filename))
|
|
140
|
+
.map((filename) => new Promise((resolve) => {
|
|
141
|
+
import(filename)
|
|
142
|
+
.then((prefab) => {
|
|
143
|
+
// JSON schema validation
|
|
144
|
+
resolve(prefab.default);
|
|
145
|
+
})
|
|
146
|
+
.catch((error) => {
|
|
147
|
+
throw new Error(`in ${filename}: ${error}`);
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
return Promise.all(prefabs);
|
|
151
|
+
};
|
|
152
|
+
const readPrefabs = async () => {
|
|
153
|
+
const srcDir = `${rootDir}/src/prefabs`;
|
|
154
|
+
const exists = await pathExists(srcDir);
|
|
155
|
+
if (!exists) {
|
|
156
|
+
throw new Error(chalk.red('\nPrefabs folder not found\n'));
|
|
157
|
+
}
|
|
158
|
+
const prefabFiles = await readFilesByType(srcDir, 'js', buildAll);
|
|
159
|
+
const prefabs = prefabFiles.map(async (file) => {
|
|
160
|
+
try {
|
|
161
|
+
const code = await readFile(`${srcDir}/${file}`, 'utf-8');
|
|
162
|
+
const transpiledFunction = Function(`return ${transpile(code, ['beforeCreate'])}`)();
|
|
163
|
+
if (!transpiledFunction) {
|
|
164
|
+
throw new Error("Prefab doesn't return anything");
|
|
165
|
+
}
|
|
166
|
+
return transpiledFunction;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new Error(`in ${file}: ${error}`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return Promise.all(prefabs);
|
|
173
|
+
};
|
|
174
|
+
const readPartialPrefabs = async () => {
|
|
175
|
+
const srcDir = `${rootDir}/src/prefabs/partials`;
|
|
176
|
+
const exists = await pathExists(srcDir);
|
|
177
|
+
if (!exists) {
|
|
178
|
+
await ensureDir(srcDir);
|
|
179
|
+
}
|
|
180
|
+
const partialPrefabFiles = await readFilesByType(srcDir, 'js', buildAll);
|
|
181
|
+
const partialPrefabs = partialPrefabFiles.map(async (file) => {
|
|
182
|
+
try {
|
|
183
|
+
const code = await readFile(`${srcDir}/${file}`, 'utf-8');
|
|
184
|
+
const transpiledFunction = Function(`return ${transpile(code, ['beforeCreate'])}`)();
|
|
185
|
+
if (!transpiledFunction) {
|
|
186
|
+
throw new Error("Prefab doesn't return anything");
|
|
187
|
+
}
|
|
188
|
+
return transpiledFunction;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw new Error(`in ${file}: ${error}`);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return Promise.all(partialPrefabs);
|
|
195
|
+
};
|
|
196
|
+
const readInteractions = async () => {
|
|
197
|
+
const srcDir = `${rootDir}/src/interactions`;
|
|
198
|
+
const exists = await pathExists(srcDir);
|
|
199
|
+
if (!exists) {
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
resolve([]);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const interactionFiles = await readFilesByType(srcDir, 'ts', buildAll);
|
|
205
|
+
return Promise.all(interactionFiles.map(async (file) => {
|
|
206
|
+
try {
|
|
207
|
+
getDiagnostics(`${srcDir}/${file}`);
|
|
208
|
+
return {
|
|
209
|
+
...extractInteractionCompatibility(`${srcDir}/${file}`),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
throw new Error(`in ${file}: ${error}`);
|
|
214
|
+
}
|
|
215
|
+
}));
|
|
216
|
+
};
|
|
217
|
+
void (async () => {
|
|
218
|
+
if (!hasOfflineFlag) {
|
|
219
|
+
await checkUpdateAvailableCLI();
|
|
220
|
+
}
|
|
221
|
+
const buildStart = ora(`Building component set...`).start();
|
|
222
|
+
try {
|
|
223
|
+
const [styles, tsxPrefabs, jsPrefabs, components, interactions, tsxPartialPrefabs, partialprefabs,] = await Promise.all([
|
|
224
|
+
readStyles(rootDir),
|
|
225
|
+
readtsPrefabs(),
|
|
226
|
+
readPrefabs(),
|
|
227
|
+
readComponents(),
|
|
228
|
+
readInteractions(),
|
|
229
|
+
readPartialPrefabs(),
|
|
230
|
+
readtsPrefabs(true),
|
|
231
|
+
]);
|
|
232
|
+
const templatesPath = path.join(distDir, 'templates.json');
|
|
233
|
+
let existingComponents = [];
|
|
234
|
+
if (fs.existsSync(templatesPath)) {
|
|
235
|
+
const templatesData = fs.readFileSync(templatesPath, 'utf8');
|
|
236
|
+
existingComponents = JSON.parse(templatesData);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
console.warn('templates.json file not found: building template.json');
|
|
240
|
+
}
|
|
241
|
+
const validStyleTypes = styles.map(({ type }) => type);
|
|
242
|
+
const prefabs = jsPrefabs
|
|
243
|
+
.concat(tsxPrefabs)
|
|
244
|
+
.filter((prefab) => !!prefab)
|
|
245
|
+
.filter((prefab) => prefab.name);
|
|
246
|
+
const allPartialPrefabs = partialprefabs
|
|
247
|
+
.concat(tsxPartialPrefabs)
|
|
248
|
+
.filter((prefab) => !!prefab);
|
|
249
|
+
const stylesGroupedByTypeAndName = styles.reduce((object, e) => {
|
|
250
|
+
const { name, type } = e;
|
|
251
|
+
const byType = object[type] || {};
|
|
252
|
+
return {
|
|
253
|
+
...object,
|
|
254
|
+
[type]: {
|
|
255
|
+
...byType,
|
|
256
|
+
[name]: e,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}, {});
|
|
260
|
+
let finalComponents;
|
|
261
|
+
if (fs.existsSync(templatesPath)) {
|
|
262
|
+
const templatesData = fs.readFileSync(templatesPath, 'utf8');
|
|
263
|
+
finalComponents = JSON.parse(templatesData);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// Here we have to build templates
|
|
267
|
+
finalComponents = components;
|
|
268
|
+
}
|
|
269
|
+
const componentNames = finalComponents.map(({ name }) => name);
|
|
270
|
+
checkNameReferences(prefabs, finalComponents);
|
|
271
|
+
const { availableNames: availableComponentNames, styleMap: componentStyleMap, } = components.reduce(({ availableNames, styleMap }, component) => {
|
|
272
|
+
const newNames = availableNames.includes(component.name)
|
|
273
|
+
? availableNames
|
|
274
|
+
: [...availableNames, component.name];
|
|
275
|
+
const newStyleMap = component.styleType
|
|
276
|
+
? Object.assign(styleMap, {
|
|
277
|
+
[component.name]: { styleType: component.styleType },
|
|
278
|
+
})
|
|
279
|
+
: styleMap;
|
|
280
|
+
return { availableNames: newNames, styleMap: newStyleMap };
|
|
281
|
+
}, { availableNames: [], styleMap: {} });
|
|
282
|
+
await Promise.all([
|
|
283
|
+
validateStyles(styles, componentNames),
|
|
284
|
+
validateComponents(components, validStyleTypes),
|
|
285
|
+
validatePrefabs({
|
|
286
|
+
availableComponentNames,
|
|
287
|
+
componentStyleMap,
|
|
288
|
+
prefabs,
|
|
289
|
+
styles: stylesGroupedByTypeAndName,
|
|
290
|
+
}),
|
|
291
|
+
validatePrefabs({
|
|
292
|
+
availableComponentNames,
|
|
293
|
+
componentStyleMap,
|
|
294
|
+
prefabType: 'partial',
|
|
295
|
+
prefabs: allPartialPrefabs,
|
|
296
|
+
styles: stylesGroupedByTypeAndName,
|
|
297
|
+
}),
|
|
298
|
+
interactions && validateInteractions(interactions),
|
|
299
|
+
]);
|
|
300
|
+
checkOptionCategoryReferences(prefabs);
|
|
301
|
+
const componentsWithHash = components.map((component) => ({
|
|
302
|
+
...component,
|
|
303
|
+
componentHash: hash(component),
|
|
304
|
+
}));
|
|
305
|
+
const buildPrefab = (prefab) => {
|
|
306
|
+
const buildStructure = (structure) => {
|
|
307
|
+
if (structure.type === 'PARTIAL') {
|
|
308
|
+
return structure;
|
|
309
|
+
}
|
|
310
|
+
if (structure.type === 'WRAPPER') {
|
|
311
|
+
const { descendants = [], ...rest } = structure;
|
|
312
|
+
const wrapperStructure = {
|
|
313
|
+
...rest,
|
|
314
|
+
descendants: descendants.map(buildStructure),
|
|
315
|
+
};
|
|
316
|
+
return wrapperStructure;
|
|
317
|
+
}
|
|
318
|
+
const { style, descendants, ...rest } = structure;
|
|
319
|
+
const styleReference = buildReferenceStyle(style);
|
|
320
|
+
const newStructure = {
|
|
321
|
+
...rest,
|
|
322
|
+
...(styleReference ? { style: styleReference } : {}),
|
|
323
|
+
descendants: descendants.map(buildStructure),
|
|
324
|
+
hash: hash(structure.options),
|
|
325
|
+
};
|
|
326
|
+
return newStructure;
|
|
327
|
+
};
|
|
328
|
+
return {
|
|
329
|
+
...prefab,
|
|
330
|
+
structure: prefab.structure.map(buildStructure),
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
const buildStyles = styles.map(buildStyle);
|
|
334
|
+
const buildPrefabs = prefabs.map(buildPrefab);
|
|
335
|
+
const buildPartialprefabs = allPartialPrefabs.map(buildPrefab);
|
|
336
|
+
await ensureDir(distDir);
|
|
337
|
+
const defaultPrefabs = buildPrefabs.filter((prefab) => prefab.type !== 'page');
|
|
338
|
+
const pagePrefabs = prefabs.filter((prefab) => prefab.type === 'page');
|
|
339
|
+
const existingPath = await pathExists(`${distDir}/pagePrefabs.json`);
|
|
340
|
+
const existingPartialPath = await pathExists(`${distDir}/partials.json`);
|
|
341
|
+
if (buildAll) {
|
|
342
|
+
const outputPromises = [
|
|
343
|
+
outputJson(`${distDir}/prefabs.json`, defaultPrefabs),
|
|
344
|
+
outputJson(`${distDir}/templates.json`, componentsWithHash),
|
|
345
|
+
interactions &&
|
|
346
|
+
outputJson(`${distDir}/interactions.json`, interactions),
|
|
347
|
+
];
|
|
348
|
+
if (buildStyles.length > 0) {
|
|
349
|
+
outputPromises.push(outputJson(`${distDir}/styles.json`, buildStyles));
|
|
350
|
+
}
|
|
351
|
+
if (pagePrefabs.length > 0) {
|
|
352
|
+
outputPromises.push(outputJson(`${distDir}/pagePrefabs.json`, pagePrefabs));
|
|
353
|
+
}
|
|
354
|
+
if (buildPartialprefabs.length > 0) {
|
|
355
|
+
outputPromises.push(outputJson(`${distDir}/partials.json`, buildPartialprefabs));
|
|
356
|
+
}
|
|
357
|
+
await Promise.all(outputPromises);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
const existingPrefabs = JSON.parse(readFileSync(`${distDir}/prefabs.json`, 'utf8'));
|
|
361
|
+
const replaceInSet = (existingElements, newElements) => existingElements.map((existingElement) => {
|
|
362
|
+
if (newElements.length > 0 &&
|
|
363
|
+
existingElement.name === newElements[0].name) {
|
|
364
|
+
return newElements[0];
|
|
365
|
+
}
|
|
366
|
+
return existingElement;
|
|
367
|
+
});
|
|
368
|
+
const updatedPrefabs = replaceInSet(existingPrefabs, prefabs);
|
|
369
|
+
const updatedComponents = replaceInSet(existingComponents, componentsWithHash);
|
|
370
|
+
const existingInteractions = JSON.parse(readFileSync(`${distDir}/interactions.json`, 'utf8'));
|
|
371
|
+
const updatedInteractions = replaceInSet(existingInteractions, interactions);
|
|
372
|
+
const newOutputPromises = [
|
|
373
|
+
outputJson(`${distDir}/prefabs.json`, updatedPrefabs),
|
|
374
|
+
outputJson(`${distDir}/templates.json`, updatedComponents),
|
|
375
|
+
interactions &&
|
|
376
|
+
outputJson(`${distDir}/interactions.json`, updatedInteractions),
|
|
377
|
+
];
|
|
378
|
+
const existingPagePrefabs = JSON.parse(readFileSync(`${distDir}/pagePrefabs.json`, 'utf8'));
|
|
379
|
+
const updatedPagePrefabs = replaceInSet(existingPagePrefabs, pagePrefabs);
|
|
380
|
+
if (existingPath && pagePrefabs.length > 0) {
|
|
381
|
+
newOutputPromises.push(outputJson(`${distDir}/pagePrefabs.json`, updatedPagePrefabs));
|
|
382
|
+
}
|
|
383
|
+
const existingPartials = JSON.parse(readFileSync(`${distDir}/partials.json`, 'utf8'));
|
|
384
|
+
const updatedPartials = replaceInSet(existingPartials, buildPartialprefabs);
|
|
385
|
+
if (existingPartialPath && buildPartialprefabs.length > 0) {
|
|
386
|
+
newOutputPromises.push(outputJson(`${distDir}/partials.json`, updatedPartials));
|
|
387
|
+
}
|
|
388
|
+
await Promise.all(newOutputPromises);
|
|
389
|
+
}
|
|
390
|
+
if (buildPartialprefabs.length === 0 && existingPartialPath && buildAll) {
|
|
391
|
+
await remove(`${distDir}/partials.json`);
|
|
392
|
+
}
|
|
393
|
+
if (pagePrefabs.length === 0 && existingPath && buildAll) {
|
|
394
|
+
await remove(`${distDir}/pagePrefabs.json`);
|
|
395
|
+
}
|
|
396
|
+
buildStart.succeed();
|
|
397
|
+
console.info(chalk.green('Success, the component set has been built'));
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
// Handle both Error objects and custom error objects
|
|
401
|
+
if (error &&
|
|
402
|
+
typeof error === 'object' &&
|
|
403
|
+
'name' in error &&
|
|
404
|
+
'file' in error &&
|
|
405
|
+
'message' in error) {
|
|
406
|
+
const { name, file, message } = error;
|
|
407
|
+
throw new Error(`${name} in ${file}: ${message}`);
|
|
408
|
+
}
|
|
409
|
+
if (error instanceof Error) {
|
|
410
|
+
throw new Error(`Error: ${error.message}`);
|
|
411
|
+
}
|
|
412
|
+
throw new Error(`An unknown error occurred: ${error}`);
|
|
413
|
+
}
|
|
414
|
+
console.info(`Total time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
415
|
+
})();
|
|
416
|
+
//# sourceMappingURL=bb-components-build.js.map
|