@betty-blocks/cli 26.0.0-beta.14 → 26.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bb-blocks-new.js +10 -15
- package/build/bb-blocks-new.js.map +1 -1
- package/build/bb-blocks-publish.js +41 -55
- package/build/bb-blocks-publish.js.map +1 -1
- package/build/bb-blocks-release.js +6 -20
- package/build/bb-blocks-release.js.map +1 -1
- package/build/bb-blocks.js +2 -4
- package/build/bb-blocks.js.map +1 -1
- package/build/bb-bundle-init.js +15 -29
- package/build/bb-bundle-init.js.map +1 -1
- package/build/bb-bundle.js +4 -9
- package/build/bb-bundle.js.map +1 -1
- package/build/bb-components-build.js +165 -198
- package/build/bb-components-build.js.map +1 -1
- package/build/bb-components-create.js +15 -29
- package/build/bb-components-create.js.map +1 -1
- package/build/bb-components-generate.js +26 -40
- package/build/bb-components-generate.js.map +1 -1
- package/build/bb-components-publish-bundle.js +20 -34
- package/build/bb-components-publish-bundle.js.map +1 -1
- package/build/bb-components-publish.js +21 -35
- package/build/bb-components-publish.js.map +1 -1
- package/build/bb-components-serve.js +9 -14
- package/build/bb-components-serve.js.map +1 -1
- package/build/bb-components.js +3 -4
- package/build/bb-components.js.map +1 -1
- package/build/bb-functions-build.js +31 -33
- package/build/bb-functions-build.js.map +1 -1
- package/build/bb-functions-bump.js +25 -39
- package/build/bb-functions-bump.js.map +1 -1
- package/build/bb-functions-init.js +14 -19
- package/build/bb-functions-init.js.map +1 -1
- package/build/bb-functions-login.js +9 -23
- package/build/bb-functions-login.js.map +1 -1
- package/build/bb-functions-logout.js +6 -11
- package/build/bb-functions-logout.js.map +1 -1
- package/build/bb-functions-new.js +8 -13
- package/build/bb-functions-new.js.map +1 -1
- package/build/bb-functions-publish.js +26 -40
- package/build/bb-functions-publish.js.map +1 -1
- package/build/bb-functions-validate.js +18 -32
- package/build/bb-functions-validate.js.map +1 -1
- package/build/bb-functions.js +2 -4
- package/build/bb-functions.js.map +1 -1
- package/build/bb.js +7 -11
- package/build/bb.js.map +1 -1
- package/build/blocks/blockDefinitions.js +12 -21
- package/build/blocks/blockDefinitions.js.map +1 -1
- package/build/blocks/publishBlocks.js +34 -48
- package/build/blocks/publishBlocks.js.map +1 -1
- package/build/blocks/releaseBlocks.js +27 -43
- package/build/blocks/releaseBlocks.js.map +1 -1
- package/build/components/comments.js +15 -18
- package/build/components/comments.js.map +1 -1
- package/build/components/compatibility.js +13 -15
- package/build/components/compatibility.js.map +1 -1
- package/build/components/transformers/index.js +8 -14
- package/build/components/transformers/index.js.map +1 -1
- package/build/components-build/index.js +2 -18
- package/build/components-build/index.js.map +1 -1
- package/build/components-build/reportDiagnostics.js +4 -12
- package/build/components-build/reportDiagnostics.js.map +1 -1
- package/build/components-build/styles.js +35 -92
- package/build/components-build/styles.js.map +1 -1
- package/build/functions/acquireAppFunctionsProject.js +5 -10
- package/build/functions/acquireAppFunctionsProject.js.map +1 -1
- package/build/functions/acquireCustomFunctionsProject.js +5 -10
- package/build/functions/acquireCustomFunctionsProject.js.map +1 -1
- package/build/functions/bb-components-functions.js +12 -30
- package/build/functions/bb-components-functions.js.map +1 -1
- package/build/functions/config.js +88 -91
- package/build/functions/config.js.map +1 -1
- package/build/functions/functionDefinitions.js +42 -56
- package/build/functions/functionDefinitions.js.map +1 -1
- package/build/functions/icons.js +10 -16
- package/build/functions/icons.js.map +1 -1
- package/build/functions/publishAppFunctions.js +47 -63
- package/build/functions/publishAppFunctions.js.map +1 -1
- package/build/functions/publishCustomFunctions.js +53 -69
- package/build/functions/publishCustomFunctions.js.map +1 -1
- package/build/functions/publishFunctions.js +18 -33
- package/build/functions/publishFunctions.js.map +1 -1
- package/build/functions/utils.js +9 -13
- package/build/functions/utils.js.map +1 -1
- package/build/functions/validations.js +41 -59
- package/build/functions/validations.js.map +1 -1
- package/build/functions/versions.js +21 -27
- package/build/functions/versions.js.map +1 -1
- package/build/interactions/compatibility.js +8 -45
- package/build/interactions/compatibility.js.map +1 -1
- package/build/interactions/diagnostics.js +7 -10
- package/build/interactions/diagnostics.js.map +1 -1
- package/build/types.js +9 -11
- package/build/types.js.map +1 -1
- package/build/utils/arguments.js +2 -7
- package/build/utils/arguments.js.map +1 -1
- package/build/utils/checkPackageVersion.js +6 -19
- package/build/utils/checkPackageVersion.js.map +1 -1
- package/build/utils/checkUpdateAvailable.js +31 -47
- package/build/utils/checkUpdateAvailable.js.map +1 -1
- package/build/utils/fusionAuth.js +84 -108
- package/build/utils/fusionAuth.js.map +1 -1
- package/build/utils/hash.js +2 -7
- package/build/utils/hash.js.map +1 -1
- package/build/utils/ide.js +111 -133
- package/build/utils/ide.js.map +1 -1
- package/build/utils/login.js +62 -78
- package/build/utils/login.js.map +1 -1
- package/build/utils/pick.js +1 -5
- package/build/utils/pick.js.map +1 -1
- package/build/utils/readFilesByType.js +13 -27
- package/build/utils/readFilesByType.js.map +1 -1
- package/build/utils/rootDir.js +3 -8
- package/build/utils/rootDir.js.map +1 -1
- package/build/utils/serveComponentSet.js +15 -29
- package/build/utils/serveComponentSet.js.map +1 -1
- package/build/utils/transpile.js +10 -15
- package/build/utils/transpile.js.map +1 -1
- package/build/utils/uploadBlob.js +22 -36
- package/build/utils/uploadBlob.js.map +1 -1
- package/build/utils/validation.js +9 -18
- package/build/utils/validation.js.map +1 -1
- package/build/validations/component.js +32 -37
- package/build/validations/component.js.map +1 -1
- package/build/validations/constants.js +16 -19
- package/build/validations/constants.js.map +1 -1
- package/build/validations/function-block-validations/index.js +27 -44
- package/build/validations/function-block-validations/index.js.map +1 -1
- package/build/validations/interaction.js +11 -16
- package/build/validations/interaction.js.map +1 -1
- package/build/validations/prefab/action.js +54 -60
- package/build/validations/prefab/action.js.map +1 -1
- package/build/validations/prefab/component.js +97 -102
- package/build/validations/prefab/component.js.map +1 -1
- package/build/validations/prefab/componentOption.js +125 -102
- package/build/validations/prefab/componentOption.js.map +1 -1
- package/build/validations/prefab/interaction.js +22 -28
- package/build/validations/prefab/interaction.js.map +1 -1
- package/build/validations/prefab/linkedOption.js +29 -35
- package/build/validations/prefab/linkedOption.js.map +1 -1
- package/build/validations/prefab/linkedPartial.js +21 -27
- package/build/validations/prefab/linkedPartial.js.map +1 -1
- package/build/validations/prefab/variable.js +20 -26
- package/build/validations/prefab/variable.js.map +1 -1
- package/build/validations/prefab.js +34 -39
- package/build/validations/prefab.js.map +1 -1
- package/build/validations/styles.js +31 -37
- package/build/validations/styles.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,85 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
45
|
-
var t = {};
|
|
46
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
47
|
-
t[p] = s[p];
|
|
48
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
49
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
50
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
51
|
-
t[p[i]] = s[p[i]];
|
|
52
|
-
}
|
|
53
|
-
return t;
|
|
54
|
-
};
|
|
55
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
56
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
|
-
};
|
|
58
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
60
|
-
const commander_1 = require("commander");
|
|
61
|
-
const fs_1 = __importDefault(require("fs"));
|
|
62
|
-
const fs_extra_1 = require("fs-extra");
|
|
63
|
-
const ora_1 = __importDefault(require("ora"));
|
|
64
|
-
const path_1 = __importDefault(require("path"));
|
|
65
|
-
const typescript_1 = __importStar(require("typescript"));
|
|
66
|
-
const compatibility_1 = __importDefault(require("./components/compatibility"));
|
|
67
|
-
const transformers_1 = require("./components/transformers");
|
|
68
|
-
const components_build_1 = require("./components-build");
|
|
69
|
-
const compatibility_2 = __importDefault(require("./interactions/compatibility"));
|
|
70
|
-
const diagnostics_1 = __importDefault(require("./interactions/diagnostics"));
|
|
71
|
-
const arguments_1 = require("./utils/arguments");
|
|
72
|
-
const checkPackageVersion_1 = require("./utils/checkPackageVersion");
|
|
73
|
-
const checkUpdateAvailable_1 = require("./utils/checkUpdateAvailable");
|
|
74
|
-
const hash_1 = __importDefault(require("./utils/hash"));
|
|
75
|
-
const readFilesByType_1 = __importDefault(require("./utils/readFilesByType"));
|
|
76
|
-
const transpile_1 = __importDefault(require("./utils/transpile"));
|
|
77
|
-
const validation_1 = require("./utils/validation");
|
|
78
|
-
const component_1 = __importDefault(require("./validations/component"));
|
|
79
|
-
const interaction_1 = __importDefault(require("./validations/interaction"));
|
|
80
|
-
const prefab_1 = __importDefault(require("./validations/prefab"));
|
|
81
|
-
const styles_1 = __importDefault(require("./validations/styles"));
|
|
82
|
-
const program = new commander_1.Command();
|
|
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();
|
|
83
25
|
program
|
|
84
26
|
.usage('[path]')
|
|
85
27
|
.name('bb components build')
|
|
@@ -89,7 +31,7 @@ program
|
|
|
89
31
|
.parse(process.argv);
|
|
90
32
|
const { args } = program;
|
|
91
33
|
const options = program.opts();
|
|
92
|
-
const rootDir =
|
|
34
|
+
const rootDir = parseDir(args);
|
|
93
35
|
const distDir = `${rootDir}/dist`;
|
|
94
36
|
const enableNewTranspile = !!options.transpile;
|
|
95
37
|
const arg = process.argv.slice(2);
|
|
@@ -97,104 +39,107 @@ const startTime = Date.now();
|
|
|
97
39
|
const buildAll = !arg.includes('--fast');
|
|
98
40
|
const hasOfflineFlag = arg.includes('--offline');
|
|
99
41
|
/* execute command */
|
|
100
|
-
const readComponents = () =>
|
|
42
|
+
const readComponents = async () => {
|
|
101
43
|
const srcDir = `${rootDir}/src/components`;
|
|
102
|
-
const exists =
|
|
44
|
+
const exists = await pathExists(srcDir);
|
|
103
45
|
if (!exists) {
|
|
104
|
-
throw new Error(
|
|
46
|
+
throw new Error(chalk.red('\nComponents folder not found\n'));
|
|
105
47
|
}
|
|
106
|
-
const componentFiles =
|
|
107
|
-
const components = componentFiles.map((file) =>
|
|
48
|
+
const componentFiles = await readFilesByType(srcDir, 'js', buildAll);
|
|
49
|
+
const components = componentFiles.map(async (file) => {
|
|
108
50
|
try {
|
|
109
|
-
const code =
|
|
110
|
-
const compatibility = (
|
|
111
|
-
const transpiledFunction = Function(`return ${(
|
|
51
|
+
const code = await readFile(`${srcDir}/${file}`, 'utf-8');
|
|
52
|
+
const compatibility = extractComponentCompatibility(code);
|
|
53
|
+
const transpiledFunction = Function(`return ${transpile(code, ['jsx', 'styles'])}`)();
|
|
112
54
|
if (!transpiledFunction) {
|
|
113
55
|
throw new Error("Component doesn't return anything");
|
|
114
56
|
}
|
|
115
57
|
if (enableNewTranspile) {
|
|
116
|
-
transpiledFunction.transpiledJsx =
|
|
117
|
-
transpiledFunction.transpiledStyles =
|
|
58
|
+
transpiledFunction.transpiledJsx = doTranspile(transpiledFunction.jsx);
|
|
59
|
+
transpiledFunction.transpiledStyles = doTranspile(transpiledFunction.styles);
|
|
118
60
|
}
|
|
119
61
|
if (transpiledFunction.dependencies && !hasOfflineFlag) {
|
|
120
62
|
const usedPackages = transpiledFunction.dependencies.map((usedDependency) => usedDependency.package);
|
|
121
|
-
const dependencyPromises = usedPackages.map((usedPackage) =>
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
-
|
|
63
|
+
const dependencyPromises = usedPackages.map(async (usedPackage) => {
|
|
64
|
+
await checkPackageVersion(usedPackage.replace(/^npm:/g, ''));
|
|
65
|
+
});
|
|
66
|
+
await Promise.all(dependencyPromises);
|
|
125
67
|
}
|
|
126
|
-
return
|
|
68
|
+
return {
|
|
69
|
+
...compatibility,
|
|
70
|
+
...transpiledFunction,
|
|
71
|
+
};
|
|
127
72
|
}
|
|
128
73
|
catch (error) {
|
|
129
74
|
throw new Error(`in ${file}: ${error}`);
|
|
130
75
|
}
|
|
131
|
-
})
|
|
76
|
+
});
|
|
132
77
|
return Promise.all(components);
|
|
133
|
-
}
|
|
134
|
-
const readtsPrefabs =
|
|
135
|
-
|
|
136
|
-
const absoluteRootDir = path_1.default.resolve(process.cwd(), rootDir);
|
|
78
|
+
};
|
|
79
|
+
const readtsPrefabs = async (isPartial = false) => {
|
|
80
|
+
const absoluteRootDir = path.resolve(process.cwd(), rootDir);
|
|
137
81
|
const srcDir = `${absoluteRootDir}/src/prefabs`;
|
|
138
82
|
const outDir = `${absoluteRootDir}/tmp/${Math.floor(Date.now() / 1000)}`;
|
|
139
|
-
const exists =
|
|
83
|
+
const exists = await pathExists(srcDir);
|
|
140
84
|
if (!exists) {
|
|
141
|
-
throw new Error(
|
|
85
|
+
throw new Error(chalk.red('\nPrefabs folder not found\n'));
|
|
142
86
|
}
|
|
143
87
|
let prefabTsFiles = [];
|
|
144
88
|
let prefabTsxFiles = [];
|
|
145
89
|
let partialTsxFiles = [];
|
|
146
90
|
if (isPartial) {
|
|
147
|
-
partialTsxFiles =
|
|
91
|
+
partialTsxFiles = await readFilesByType(`${srcDir}/partials`, 'tsx', buildAll);
|
|
148
92
|
}
|
|
149
93
|
else {
|
|
150
|
-
prefabTsFiles =
|
|
151
|
-
prefabTsxFiles =
|
|
94
|
+
prefabTsFiles = await readFilesByType(srcDir, 'ts', buildAll);
|
|
95
|
+
prefabTsxFiles = await readFilesByType(srcDir, 'tsx', buildAll);
|
|
152
96
|
}
|
|
153
97
|
const prefabFiles = [...prefabTsFiles, ...prefabTsxFiles];
|
|
154
98
|
const files = isPartial ? partialTsxFiles : prefabFiles;
|
|
155
99
|
const basePath = isPartial ? `${srcDir}/partials/` : `${srcDir}/`;
|
|
156
|
-
const prefabProgram =
|
|
100
|
+
const prefabProgram = ts.createProgram(files.map((file) => `${basePath}/${file}`), {
|
|
157
101
|
allowSyntheticDefaultImports: false,
|
|
158
102
|
esModuleInterop: true,
|
|
159
|
-
jsx:
|
|
103
|
+
jsx: JsxEmit.React,
|
|
160
104
|
listEmittedFiles: true,
|
|
161
|
-
module:
|
|
105
|
+
module: ModuleKind.CommonJS,
|
|
162
106
|
outDir,
|
|
163
|
-
target:
|
|
107
|
+
target: ScriptTarget.ESNext,
|
|
164
108
|
});
|
|
165
|
-
const diagnostics = [...
|
|
109
|
+
const diagnostics = [...ts.getPreEmitDiagnostics(prefabProgram)];
|
|
166
110
|
if (diagnostics.length > 0) {
|
|
167
|
-
|
|
111
|
+
reportDiagnostics(diagnostics);
|
|
168
112
|
process.exit(1);
|
|
169
113
|
}
|
|
170
114
|
const results = prefabProgram.emit();
|
|
171
115
|
if (results.diagnostics.length > 0) {
|
|
172
|
-
|
|
116
|
+
reportDiagnostics([...results.diagnostics]);
|
|
173
117
|
process.exit(1);
|
|
174
118
|
}
|
|
175
119
|
const globalDiagnostics = [...prefabProgram.getGlobalDiagnostics()];
|
|
176
120
|
if (globalDiagnostics.length > 0) {
|
|
177
|
-
|
|
121
|
+
reportDiagnostics(globalDiagnostics);
|
|
178
122
|
process.exit(1);
|
|
179
123
|
}
|
|
180
124
|
const declarationDiagnostics = [...prefabProgram.getDeclarationDiagnostics()];
|
|
181
125
|
if (declarationDiagnostics.length > 0) {
|
|
182
|
-
|
|
126
|
+
reportDiagnostics(declarationDiagnostics);
|
|
183
127
|
process.exit(1);
|
|
184
128
|
}
|
|
185
129
|
const configDiagnostics = [
|
|
186
130
|
...prefabProgram.getConfigFileParsingDiagnostics(),
|
|
187
131
|
];
|
|
188
132
|
if (configDiagnostics.length > 0) {
|
|
189
|
-
|
|
133
|
+
reportDiagnostics(configDiagnostics);
|
|
190
134
|
process.exit(1);
|
|
191
135
|
}
|
|
192
|
-
const prefabs = (
|
|
136
|
+
const prefabs = (results.emittedFiles ?? [])
|
|
193
137
|
.filter((filename) => isPartial
|
|
194
138
|
? /prefabs\/partials\/\w+\.js$/.test(filename)
|
|
195
139
|
: /prefabs\/\w+\.js$/.test(filename))
|
|
196
140
|
.map((filename) => new Promise((resolve) => {
|
|
197
|
-
|
|
141
|
+
import(filename)
|
|
142
|
+
.then((prefab) => {
|
|
198
143
|
// JSON schema validation
|
|
199
144
|
resolve(prefab.default);
|
|
200
145
|
})
|
|
@@ -203,18 +148,18 @@ const readtsPrefabs = (...args_1) => __awaiter(void 0, [...args_1], void 0, func
|
|
|
203
148
|
});
|
|
204
149
|
}));
|
|
205
150
|
return Promise.all(prefabs);
|
|
206
|
-
}
|
|
207
|
-
const readPrefabs = () =>
|
|
151
|
+
};
|
|
152
|
+
const readPrefabs = async () => {
|
|
208
153
|
const srcDir = `${rootDir}/src/prefabs`;
|
|
209
|
-
const exists =
|
|
154
|
+
const exists = await pathExists(srcDir);
|
|
210
155
|
if (!exists) {
|
|
211
|
-
throw new Error(
|
|
156
|
+
throw new Error(chalk.red('\nPrefabs folder not found\n'));
|
|
212
157
|
}
|
|
213
|
-
const prefabFiles =
|
|
214
|
-
const prefabs = prefabFiles.map((file) =>
|
|
158
|
+
const prefabFiles = await readFilesByType(srcDir, 'js', buildAll);
|
|
159
|
+
const prefabs = prefabFiles.map(async (file) => {
|
|
215
160
|
try {
|
|
216
|
-
const code =
|
|
217
|
-
const transpiledFunction = Function(`return ${(
|
|
161
|
+
const code = await readFile(`${srcDir}/${file}`, 'utf-8');
|
|
162
|
+
const transpiledFunction = Function(`return ${transpile(code, ['beforeCreate'])}`)();
|
|
218
163
|
if (!transpiledFunction) {
|
|
219
164
|
throw new Error("Prefab doesn't return anything");
|
|
220
165
|
}
|
|
@@ -223,20 +168,20 @@ const readPrefabs = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
223
168
|
catch (error) {
|
|
224
169
|
throw new Error(`in ${file}: ${error}`);
|
|
225
170
|
}
|
|
226
|
-
})
|
|
171
|
+
});
|
|
227
172
|
return Promise.all(prefabs);
|
|
228
|
-
}
|
|
229
|
-
const readPartialPrefabs = () =>
|
|
173
|
+
};
|
|
174
|
+
const readPartialPrefabs = async () => {
|
|
230
175
|
const srcDir = `${rootDir}/src/prefabs/partials`;
|
|
231
|
-
const exists =
|
|
176
|
+
const exists = await pathExists(srcDir);
|
|
232
177
|
if (!exists) {
|
|
233
|
-
|
|
178
|
+
await ensureDir(srcDir);
|
|
234
179
|
}
|
|
235
|
-
const partialPrefabFiles =
|
|
236
|
-
const partialPrefabs = partialPrefabFiles.map((file) =>
|
|
180
|
+
const partialPrefabFiles = await readFilesByType(srcDir, 'js', buildAll);
|
|
181
|
+
const partialPrefabs = partialPrefabFiles.map(async (file) => {
|
|
237
182
|
try {
|
|
238
|
-
const code =
|
|
239
|
-
const transpiledFunction = Function(`return ${(
|
|
183
|
+
const code = await readFile(`${srcDir}/${file}`, 'utf-8');
|
|
184
|
+
const transpiledFunction = Function(`return ${transpile(code, ['beforeCreate'])}`)();
|
|
240
185
|
if (!transpiledFunction) {
|
|
241
186
|
throw new Error("Prefab doesn't return anything");
|
|
242
187
|
}
|
|
@@ -245,36 +190,38 @@ const readPartialPrefabs = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
245
190
|
catch (error) {
|
|
246
191
|
throw new Error(`in ${file}: ${error}`);
|
|
247
192
|
}
|
|
248
|
-
})
|
|
193
|
+
});
|
|
249
194
|
return Promise.all(partialPrefabs);
|
|
250
|
-
}
|
|
251
|
-
const readInteractions = () =>
|
|
195
|
+
};
|
|
196
|
+
const readInteractions = async () => {
|
|
252
197
|
const srcDir = `${rootDir}/src/interactions`;
|
|
253
|
-
const exists =
|
|
198
|
+
const exists = await pathExists(srcDir);
|
|
254
199
|
if (!exists) {
|
|
255
200
|
return new Promise((resolve) => {
|
|
256
201
|
resolve([]);
|
|
257
202
|
});
|
|
258
203
|
}
|
|
259
|
-
const interactionFiles =
|
|
260
|
-
return Promise.all(interactionFiles.map((file) =>
|
|
204
|
+
const interactionFiles = await readFilesByType(srcDir, 'ts', buildAll);
|
|
205
|
+
return Promise.all(interactionFiles.map(async (file) => {
|
|
261
206
|
try {
|
|
262
|
-
(
|
|
263
|
-
return
|
|
207
|
+
getDiagnostics(`${srcDir}/${file}`);
|
|
208
|
+
return {
|
|
209
|
+
...extractInteractionCompatibility(`${srcDir}/${file}`),
|
|
210
|
+
};
|
|
264
211
|
}
|
|
265
212
|
catch (error) {
|
|
266
213
|
throw new Error(`in ${file}: ${error}`);
|
|
267
214
|
}
|
|
268
|
-
}))
|
|
269
|
-
}
|
|
270
|
-
void (() =>
|
|
215
|
+
}));
|
|
216
|
+
};
|
|
217
|
+
void (async () => {
|
|
271
218
|
if (!hasOfflineFlag) {
|
|
272
|
-
|
|
219
|
+
await checkUpdateAvailableCLI();
|
|
273
220
|
}
|
|
274
|
-
const buildStart = (
|
|
221
|
+
const buildStart = ora(`Building component set...`).start();
|
|
275
222
|
try {
|
|
276
|
-
const [styles, tsxPrefabs, jsPrefabs, components, interactions, tsxPartialPrefabs, partialprefabs,] =
|
|
277
|
-
|
|
223
|
+
const [styles, tsxPrefabs, jsPrefabs, components, interactions, tsxPartialPrefabs, partialprefabs,] = await Promise.all([
|
|
224
|
+
readStyles(rootDir),
|
|
278
225
|
readtsPrefabs(),
|
|
279
226
|
readPrefabs(),
|
|
280
227
|
readComponents(),
|
|
@@ -282,10 +229,10 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
282
229
|
readPartialPrefabs(),
|
|
283
230
|
readtsPrefabs(true),
|
|
284
231
|
]);
|
|
285
|
-
const templatesPath =
|
|
232
|
+
const templatesPath = path.join(distDir, 'templates.json');
|
|
286
233
|
let existingComponents = [];
|
|
287
|
-
if (
|
|
288
|
-
const templatesData =
|
|
234
|
+
if (fs.existsSync(templatesPath)) {
|
|
235
|
+
const templatesData = fs.readFileSync(templatesPath, 'utf8');
|
|
289
236
|
existingComponents = JSON.parse(templatesData);
|
|
290
237
|
}
|
|
291
238
|
else {
|
|
@@ -302,11 +249,17 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
302
249
|
const stylesGroupedByTypeAndName = styles.reduce((object, e) => {
|
|
303
250
|
const { name, type } = e;
|
|
304
251
|
const byType = object[type] || {};
|
|
305
|
-
return
|
|
252
|
+
return {
|
|
253
|
+
...object,
|
|
254
|
+
[type]: {
|
|
255
|
+
...byType,
|
|
256
|
+
[name]: e,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
306
259
|
}, {});
|
|
307
260
|
let finalComponents;
|
|
308
|
-
if (
|
|
309
|
-
const templatesData =
|
|
261
|
+
if (fs.existsSync(templatesPath)) {
|
|
262
|
+
const templatesData = fs.readFileSync(templatesPath, 'utf8');
|
|
310
263
|
finalComponents = JSON.parse(templatesData);
|
|
311
264
|
}
|
|
312
265
|
else {
|
|
@@ -314,7 +267,7 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
314
267
|
finalComponents = components;
|
|
315
268
|
}
|
|
316
269
|
const componentNames = finalComponents.map(({ name }) => name);
|
|
317
|
-
|
|
270
|
+
checkNameReferences(prefabs, finalComponents);
|
|
318
271
|
const { availableNames: availableComponentNames, styleMap: componentStyleMap, } = components.reduce(({ availableNames, styleMap }, component) => {
|
|
319
272
|
const newNames = availableNames.includes(component.name)
|
|
320
273
|
? availableNames
|
|
@@ -326,71 +279,85 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
326
279
|
: styleMap;
|
|
327
280
|
return { availableNames: newNames, styleMap: newStyleMap };
|
|
328
281
|
}, { availableNames: [], styleMap: {} });
|
|
329
|
-
|
|
330
|
-
(
|
|
331
|
-
(
|
|
332
|
-
(
|
|
282
|
+
await Promise.all([
|
|
283
|
+
validateStyles(styles, componentNames),
|
|
284
|
+
validateComponents(components, validStyleTypes),
|
|
285
|
+
validatePrefabs({
|
|
333
286
|
availableComponentNames,
|
|
334
287
|
componentStyleMap,
|
|
335
288
|
prefabs,
|
|
336
289
|
styles: stylesGroupedByTypeAndName,
|
|
337
290
|
}),
|
|
338
|
-
(
|
|
291
|
+
validatePrefabs({
|
|
339
292
|
availableComponentNames,
|
|
340
293
|
componentStyleMap,
|
|
341
294
|
prefabType: 'partial',
|
|
342
295
|
prefabs: allPartialPrefabs,
|
|
343
296
|
styles: stylesGroupedByTypeAndName,
|
|
344
297
|
}),
|
|
345
|
-
interactions && (
|
|
298
|
+
interactions && validateInteractions(interactions),
|
|
346
299
|
]);
|
|
347
|
-
|
|
348
|
-
const componentsWithHash = components.map((component) => (
|
|
300
|
+
checkOptionCategoryReferences(prefabs);
|
|
301
|
+
const componentsWithHash = components.map((component) => ({
|
|
302
|
+
...component,
|
|
303
|
+
componentHash: hash(component),
|
|
304
|
+
}));
|
|
349
305
|
const buildPrefab = (prefab) => {
|
|
350
306
|
const buildStructure = (structure) => {
|
|
351
307
|
if (structure.type === 'PARTIAL') {
|
|
352
308
|
return structure;
|
|
353
309
|
}
|
|
354
310
|
if (structure.type === 'WRAPPER') {
|
|
355
|
-
const { descendants = []
|
|
356
|
-
const wrapperStructure =
|
|
311
|
+
const { descendants = [], ...rest } = structure;
|
|
312
|
+
const wrapperStructure = {
|
|
313
|
+
...rest,
|
|
314
|
+
descendants: descendants.map(buildStructure),
|
|
315
|
+
};
|
|
357
316
|
return wrapperStructure;
|
|
358
317
|
}
|
|
359
|
-
const { style, descendants
|
|
360
|
-
const styleReference =
|
|
361
|
-
const newStructure =
|
|
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
|
+
};
|
|
362
326
|
return newStructure;
|
|
363
327
|
};
|
|
364
|
-
return
|
|
328
|
+
return {
|
|
329
|
+
...prefab,
|
|
330
|
+
structure: prefab.structure.map(buildStructure),
|
|
331
|
+
};
|
|
365
332
|
};
|
|
366
|
-
const buildStyles = styles.map(
|
|
333
|
+
const buildStyles = styles.map(buildStyle);
|
|
367
334
|
const buildPrefabs = prefabs.map(buildPrefab);
|
|
368
335
|
const buildPartialprefabs = allPartialPrefabs.map(buildPrefab);
|
|
369
|
-
|
|
336
|
+
await ensureDir(distDir);
|
|
370
337
|
const defaultPrefabs = buildPrefabs.filter((prefab) => prefab.type !== 'page');
|
|
371
338
|
const pagePrefabs = prefabs.filter((prefab) => prefab.type === 'page');
|
|
372
|
-
const existingPath =
|
|
373
|
-
const existingPartialPath =
|
|
339
|
+
const existingPath = await pathExists(`${distDir}/pagePrefabs.json`);
|
|
340
|
+
const existingPartialPath = await pathExists(`${distDir}/partials.json`);
|
|
374
341
|
if (buildAll) {
|
|
375
342
|
const outputPromises = [
|
|
376
|
-
|
|
377
|
-
|
|
343
|
+
outputJson(`${distDir}/prefabs.json`, defaultPrefabs),
|
|
344
|
+
outputJson(`${distDir}/templates.json`, componentsWithHash),
|
|
378
345
|
interactions &&
|
|
379
|
-
|
|
346
|
+
outputJson(`${distDir}/interactions.json`, interactions),
|
|
380
347
|
];
|
|
381
348
|
if (buildStyles.length > 0) {
|
|
382
|
-
outputPromises.push(
|
|
349
|
+
outputPromises.push(outputJson(`${distDir}/styles.json`, buildStyles));
|
|
383
350
|
}
|
|
384
351
|
if (pagePrefabs.length > 0) {
|
|
385
|
-
outputPromises.push(
|
|
352
|
+
outputPromises.push(outputJson(`${distDir}/pagePrefabs.json`, pagePrefabs));
|
|
386
353
|
}
|
|
387
354
|
if (buildPartialprefabs.length > 0) {
|
|
388
|
-
outputPromises.push(
|
|
355
|
+
outputPromises.push(outputJson(`${distDir}/partials.json`, buildPartialprefabs));
|
|
389
356
|
}
|
|
390
|
-
|
|
357
|
+
await Promise.all(outputPromises);
|
|
391
358
|
}
|
|
392
359
|
else {
|
|
393
|
-
const existingPrefabs = JSON.parse(
|
|
360
|
+
const existingPrefabs = JSON.parse(readFileSync(`${distDir}/prefabs.json`, 'utf8'));
|
|
394
361
|
const replaceInSet = (existingElements, newElements) => existingElements.map((existingElement) => {
|
|
395
362
|
if (newElements.length > 0 &&
|
|
396
363
|
existingElement.name === newElements[0].name) {
|
|
@@ -400,34 +367,34 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
400
367
|
});
|
|
401
368
|
const updatedPrefabs = replaceInSet(existingPrefabs, prefabs);
|
|
402
369
|
const updatedComponents = replaceInSet(existingComponents, componentsWithHash);
|
|
403
|
-
const existingInteractions = JSON.parse(
|
|
370
|
+
const existingInteractions = JSON.parse(readFileSync(`${distDir}/interactions.json`, 'utf8'));
|
|
404
371
|
const updatedInteractions = replaceInSet(existingInteractions, interactions);
|
|
405
372
|
const newOutputPromises = [
|
|
406
|
-
|
|
407
|
-
|
|
373
|
+
outputJson(`${distDir}/prefabs.json`, updatedPrefabs),
|
|
374
|
+
outputJson(`${distDir}/templates.json`, updatedComponents),
|
|
408
375
|
interactions &&
|
|
409
|
-
|
|
376
|
+
outputJson(`${distDir}/interactions.json`, updatedInteractions),
|
|
410
377
|
];
|
|
411
|
-
const existingPagePrefabs = JSON.parse(
|
|
378
|
+
const existingPagePrefabs = JSON.parse(readFileSync(`${distDir}/pagePrefabs.json`, 'utf8'));
|
|
412
379
|
const updatedPagePrefabs = replaceInSet(existingPagePrefabs, pagePrefabs);
|
|
413
380
|
if (existingPath && pagePrefabs.length > 0) {
|
|
414
|
-
newOutputPromises.push(
|
|
381
|
+
newOutputPromises.push(outputJson(`${distDir}/pagePrefabs.json`, updatedPagePrefabs));
|
|
415
382
|
}
|
|
416
|
-
const existingPartials = JSON.parse(
|
|
383
|
+
const existingPartials = JSON.parse(readFileSync(`${distDir}/partials.json`, 'utf8'));
|
|
417
384
|
const updatedPartials = replaceInSet(existingPartials, buildPartialprefabs);
|
|
418
385
|
if (existingPartialPath && buildPartialprefabs.length > 0) {
|
|
419
|
-
newOutputPromises.push(
|
|
386
|
+
newOutputPromises.push(outputJson(`${distDir}/partials.json`, updatedPartials));
|
|
420
387
|
}
|
|
421
|
-
|
|
388
|
+
await Promise.all(newOutputPromises);
|
|
422
389
|
}
|
|
423
390
|
if (buildPartialprefabs.length === 0 && existingPartialPath && buildAll) {
|
|
424
|
-
|
|
391
|
+
await remove(`${distDir}/partials.json`);
|
|
425
392
|
}
|
|
426
393
|
if (pagePrefabs.length === 0 && existingPath && buildAll) {
|
|
427
|
-
|
|
394
|
+
await remove(`${distDir}/pagePrefabs.json`);
|
|
428
395
|
}
|
|
429
396
|
buildStart.succeed();
|
|
430
|
-
console.info(
|
|
397
|
+
console.info(chalk.green('Success, the component set has been built'));
|
|
431
398
|
}
|
|
432
399
|
catch (error) {
|
|
433
400
|
// Handle both Error objects and custom error objects
|
|
@@ -445,5 +412,5 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
445
412
|
throw new Error(`An unknown error occurred: ${error}`);
|
|
446
413
|
}
|
|
447
414
|
console.info(`Total time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
448
|
-
})
|
|
415
|
+
})();
|
|
449
416
|
//# sourceMappingURL=bb-components-build.js.map
|