@blocklet/pages-kit-block-studio 0.4.31 → 0.4.33
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/lib/cjs/components/create-resource.js +2 -2
- package/lib/cjs/constants/new-block-template/index.js +2 -14
- package/lib/cjs/middlewares/init-block-studio-router.js +15 -21
- package/lib/cjs/middlewares/init-resource-router.js +34 -42
- package/lib/cjs/plugins/vite-plugin-block-studio.js +107 -86
- package/lib/cjs/plugins/vite-plugin-html-transform.js +13 -24
- package/lib/cjs/plugins/vite-plugin-remote-script-localizer.js +87 -103
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/build-lib.js +62 -74
- package/lib/cjs/utils/generate-wrapper-code.js +366 -120
- package/lib/cjs/utils/helper.js +9 -19
- package/lib/esm/components/create-resource.js +2 -2
- package/lib/esm/constants/new-block-template/index.js +2 -14
- package/lib/esm/middlewares/init-block-studio-router.js +15 -21
- package/lib/esm/middlewares/init-resource-router.js +34 -42
- package/lib/esm/plugins/vite-plugin-block-studio.js +107 -86
- package/lib/esm/plugins/vite-plugin-html-transform.js +13 -24
- package/lib/esm/plugins/vite-plugin-remote-script-localizer.js +87 -103
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/build-lib.js +62 -74
- package/lib/esm/utils/generate-wrapper-code.js +366 -120
- package/lib/esm/utils/helper.js +9 -19
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -18,72 +9,69 @@ exports.buildLib = buildLib;
|
|
|
18
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
19
10
|
const child_process_1 = require("child_process");
|
|
20
11
|
const helper_1 = require("./helper");
|
|
21
|
-
function buildLib(options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const allBlocks = (0, helper_1.findComponentFiles)({ cwd: workingDir }).map((entry) => {
|
|
27
|
-
return entry.blockName;
|
|
28
|
-
});
|
|
29
|
-
const filterModules = process.argv.includes('--filter')
|
|
30
|
-
? (_a = process.argv[process.argv.indexOf('--filter') + 1]) === null || _a === void 0 ? void 0 : _a.split(',')
|
|
31
|
-
: ((_b = process.env.BLOCK_FILTER) === null || _b === void 0 ? void 0 : _b.split(',')) || null;
|
|
32
|
-
const ignoreViteLog = process.argv.includes('--log') ? false : process.env.BLOCK_LOG !== 'true';
|
|
33
|
-
const multiMode = process.argv.includes('--multi') || process.env.BLOCK_MULTI === 'true';
|
|
34
|
-
const blocks = allBlocks.filter((name) => !filterModules || filterModules.includes(name || ''));
|
|
35
|
-
if (!blocks.length) {
|
|
36
|
-
console.log(chalk_1.default.yellow('No blocks founds'));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
// Clean up the lib directory
|
|
40
|
-
yield (0, child_process_1.execSync)(`rm -rf ${helper_1.libDir}`, { cwd: workingDir });
|
|
41
|
-
console.log(chalk_1.default.gray('Clean up the lib directory'));
|
|
42
|
-
// Start to build
|
|
43
|
-
console.log(chalk_1.default.cyan(`Start to build ${blocks.length} blocks in parallel\n`));
|
|
44
|
-
const canBuildBlocks = multiMode ? blocks : [blocks.join(',')];
|
|
45
|
-
const configFile = 'vite-lib.config';
|
|
46
|
-
const hasConfig = (0, child_process_1.execSync)(`ls ${configFile}.* 2>/dev/null || true`, {
|
|
47
|
-
cwd: workingDir,
|
|
48
|
-
encoding: 'utf-8',
|
|
49
|
-
}).trim() !== '';
|
|
50
|
-
try {
|
|
51
|
-
yield Promise.all(canBuildBlocks.map((blockName) => {
|
|
52
|
-
console.log(chalk_1.default.blue(`Building ${blockName} Block...`));
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
const build = (0, child_process_1.spawn)('vite', [
|
|
55
|
-
'build',
|
|
56
|
-
'--filter',
|
|
57
|
-
`"${blockName}"`,
|
|
58
|
-
'--outDir',
|
|
59
|
-
helper_1.libDir,
|
|
60
|
-
'--emptyOutDir=false',
|
|
61
|
-
hasConfig ? `--config ${configFile}.*` : '',
|
|
62
|
-
], {
|
|
63
|
-
stdio: ignoreViteLog ? ['inherit', 'ignore', 'ignore'] : 'inherit',
|
|
64
|
-
shell: true,
|
|
65
|
-
cwd: workingDir,
|
|
66
|
-
});
|
|
67
|
-
build.on('close', (code) => {
|
|
68
|
-
if (code === 0) {
|
|
69
|
-
console.log(chalk_1.default.green(`Build ${blockName} successfully`));
|
|
70
|
-
resolve();
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
reject(new Error(`Build failed with code ${code}`));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}));
|
|
78
|
-
console.log(chalk_1.default.green(`\nBuild ${blocks.length} blocks successfully`));
|
|
79
|
-
console.log(chalk_1.default.gray(`Generate the ${helper_1.libDir} directory successfully`));
|
|
80
|
-
process.exit(0);
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
console.error(chalk_1.default.red('Build failed:'), err);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
12
|
+
async function buildLib(options) {
|
|
13
|
+
const workingDir = options?.cwd || process.cwd();
|
|
14
|
+
// Scan for all index files
|
|
15
|
+
const allBlocks = (0, helper_1.findComponentFiles)({ cwd: workingDir }).map((entry) => {
|
|
16
|
+
return entry.blockName;
|
|
86
17
|
});
|
|
18
|
+
const filterModules = process.argv.includes('--filter')
|
|
19
|
+
? process.argv[process.argv.indexOf('--filter') + 1]?.split(',')
|
|
20
|
+
: process.env.BLOCK_FILTER?.split(',') || null;
|
|
21
|
+
const ignoreViteLog = process.argv.includes('--log') ? false : process.env.BLOCK_LOG !== 'true';
|
|
22
|
+
const multiMode = process.argv.includes('--multi') || process.env.BLOCK_MULTI === 'true';
|
|
23
|
+
const blocks = allBlocks.filter((name) => !filterModules || filterModules.includes(name || ''));
|
|
24
|
+
if (!blocks.length) {
|
|
25
|
+
console.log(chalk_1.default.yellow('No blocks founds'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Clean up the lib directory
|
|
29
|
+
await (0, child_process_1.execSync)(`rm -rf ${helper_1.libDir}`, { cwd: workingDir });
|
|
30
|
+
console.log(chalk_1.default.gray('Clean up the lib directory'));
|
|
31
|
+
// Start to build
|
|
32
|
+
console.log(chalk_1.default.cyan(`Start to build ${blocks.length} blocks in parallel\n`));
|
|
33
|
+
const canBuildBlocks = multiMode ? blocks : [blocks.join(',')];
|
|
34
|
+
const configFile = 'vite-lib.config';
|
|
35
|
+
const hasConfig = (0, child_process_1.execSync)(`ls ${configFile}.* 2>/dev/null || true`, {
|
|
36
|
+
cwd: workingDir,
|
|
37
|
+
encoding: 'utf-8',
|
|
38
|
+
}).trim() !== '';
|
|
39
|
+
try {
|
|
40
|
+
await Promise.all(canBuildBlocks.map((blockName) => {
|
|
41
|
+
console.log(chalk_1.default.blue(`Building ${blockName} Block...`));
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const build = (0, child_process_1.spawn)('vite', [
|
|
44
|
+
'build',
|
|
45
|
+
'--filter',
|
|
46
|
+
`"${blockName}"`,
|
|
47
|
+
'--outDir',
|
|
48
|
+
helper_1.libDir,
|
|
49
|
+
'--emptyOutDir=false',
|
|
50
|
+
hasConfig ? `--config ${configFile}.*` : '',
|
|
51
|
+
], {
|
|
52
|
+
stdio: ignoreViteLog ? ['inherit', 'ignore', 'ignore'] : 'inherit',
|
|
53
|
+
shell: true,
|
|
54
|
+
cwd: workingDir,
|
|
55
|
+
});
|
|
56
|
+
build.on('close', (code) => {
|
|
57
|
+
if (code === 0) {
|
|
58
|
+
console.log(chalk_1.default.green(`Build ${blockName} successfully`));
|
|
59
|
+
resolve();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
reject(new Error(`Build failed with code ${code}`));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}));
|
|
67
|
+
console.log(chalk_1.default.green(`\nBuild ${blocks.length} blocks successfully`));
|
|
68
|
+
console.log(chalk_1.default.gray(`Generate the ${helper_1.libDir} directory successfully`));
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
console.error(chalk_1.default.red('Build failed:'), err);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
87
75
|
}
|
|
88
76
|
const cwdArg = process.argv.indexOf('--cwd');
|
|
89
77
|
const cwd = cwdArg !== -1 ? process.argv[cwdArg + 1] : undefined;
|