@blocklet/pages-kit-block-studio 0.4.32 → 0.4.34

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