@blocklet/component-studio-cli 0.5.12 → 0.5.14
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.
|
@@ -59,7 +59,13 @@ export function createComponentStudioCommand() {
|
|
|
59
59
|
.addCommand(createAddCommand()) // 添加组件
|
|
60
60
|
.addCommand(createMigrateCommand()) // 迁移组件
|
|
61
61
|
.showHelpAfterError(true)
|
|
62
|
-
.showSuggestionAfterError(true)
|
|
62
|
+
.showSuggestionAfterError(true)
|
|
63
|
+
.action(() => {
|
|
64
|
+
program.outputHelp();
|
|
65
|
+
});
|
|
66
|
+
program.on('command:*', () => {
|
|
67
|
+
program.outputHelp();
|
|
68
|
+
});
|
|
63
69
|
// 添加依赖检查逻辑
|
|
64
70
|
const originalParse = program.parseAsync;
|
|
65
71
|
program.parseAsync = async (argv) => {
|
package/dist/commands/dev.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spawn } from 'child_process';
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
|
-
import { join } from 'node:path';
|
|
6
|
+
import { join, dirname } from 'node:path';
|
|
7
7
|
import ora from 'ora';
|
|
8
8
|
import { getWorkspaceTemplatePath, installDependencies, getWorkspacePath, getProjectPath, replaceInDirectoryFileNameWithExample, checkShouldInstallDependencies, } from '../utils/helper.js';
|
|
9
9
|
async function createDevServer(projectPath, _options) {
|
|
@@ -14,6 +14,12 @@ async function createDevServer(projectPath, _options) {
|
|
|
14
14
|
// 2. 准备基础环境
|
|
15
15
|
if (!existsSync(workspacePath)) {
|
|
16
16
|
const workspaceTemplatePath = getWorkspaceTemplatePath();
|
|
17
|
+
const workspaceParentDir = dirname(workspacePath);
|
|
18
|
+
// 删除 workspace parent 目录(清空历史的 component studio 项目,节省用户磁盘空间)
|
|
19
|
+
await fs.remove(workspaceParentDir);
|
|
20
|
+
// 创建 workspace parent 目录
|
|
21
|
+
await fs.ensureDir(workspaceParentDir);
|
|
22
|
+
// 复制 workspace 模板
|
|
17
23
|
await fs.copy(workspaceTemplatePath, workspacePath);
|
|
18
24
|
// 修改 workspace 目录中,_example 后缀的文件名,删除 _example 后缀
|
|
19
25
|
await replaceInDirectoryFileNameWithExample(workspacePath);
|
package/dist/utils/helper.js
CHANGED
|
@@ -3,13 +3,14 @@ import { execSync, exec } from 'child_process';
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { glob } from 'glob';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
|
-
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
7
7
|
import { cp } from 'node:fs/promises';
|
|
8
8
|
import { readdir, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
9
9
|
import { join, resolve, dirname, basename, relative } from 'node:path';
|
|
10
10
|
import ora from 'ora';
|
|
11
11
|
import os from 'os';
|
|
12
|
-
|
|
12
|
+
import path from 'path';
|
|
13
|
+
const workspaceVersion = '0.1.5';
|
|
13
14
|
const METADATA_FILE_NAME = '@metadata.json';
|
|
14
15
|
// 获取CLI内置的workspace模板路径
|
|
15
16
|
export function getWorkspaceTemplatePath() {
|
|
@@ -102,10 +103,26 @@ export async function installDependencies(dirs, operation = 'install') {
|
|
|
102
103
|
const baseDepsText = operation === 'update' ? 'Updating latest dependencies...' : 'Installing latest dependencies...';
|
|
103
104
|
const depsSpinner = ora({ text: baseDepsText, color: 'blue' }).start();
|
|
104
105
|
try {
|
|
105
|
-
const installPromises = Object.entries(dirs)
|
|
106
|
+
const installPromises = Object.entries(dirs)
|
|
107
|
+
.map(([dirType, dirPath]) => {
|
|
106
108
|
return new Promise((resolve, reject) => {
|
|
109
|
+
// 检查 dir 是否存在,不存在则跳过
|
|
110
|
+
if (!existsSync(dirPath)) {
|
|
111
|
+
resolve();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// 尝试删除 node_modules/.vite 目录
|
|
115
|
+
try {
|
|
116
|
+
const viteDir = path.join(dirPath, 'node_modules', '.vite');
|
|
117
|
+
if (existsSync(viteDir)) {
|
|
118
|
+
rmSync(viteDir, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
// ignore error
|
|
123
|
+
}
|
|
107
124
|
let errorOutput = '';
|
|
108
|
-
const depProcess = exec("npx -y taze -f -r -w -n '/arcblock|ocap|abtnode|blocklet|did-connect|did-comment|nedb/' latest && pnpm install && pnpm dedupe", {
|
|
125
|
+
const depProcess = exec("npx -y taze -f -r -w -n '/arcblock|ocap|abtnode|blocklet|did-connect|did-comment|nedb/' latest && pnpm install -f && pnpm dedupe", {
|
|
109
126
|
cwd: dirPath,
|
|
110
127
|
env: {
|
|
111
128
|
...process.env,
|
|
@@ -135,17 +152,21 @@ export async function installDependencies(dirs, operation = 'install') {
|
|
|
135
152
|
reject(new Error(`${dirType} process error: ${error.message}\n${errorOutput}`));
|
|
136
153
|
});
|
|
137
154
|
});
|
|
138
|
-
})
|
|
155
|
+
})
|
|
156
|
+
.filter((p) => p);
|
|
139
157
|
// 制作一个假进度条,每秒增加 1%
|
|
140
158
|
let progress = 0;
|
|
141
159
|
let progressStep = 1;
|
|
142
160
|
const interval = setInterval(() => {
|
|
143
161
|
if (progress < 99.9) {
|
|
144
|
-
progress = parseFloat((progress + progressStep).toFixed(
|
|
162
|
+
progress = parseFloat((progress + progressStep).toFixed(2));
|
|
145
163
|
depsSpinner.text = `${baseDepsText} ${progress}%`;
|
|
146
|
-
if (progress >=
|
|
164
|
+
if (progress >= 30) {
|
|
147
165
|
progressStep = 0.3;
|
|
148
166
|
}
|
|
167
|
+
if (progress >= 70) {
|
|
168
|
+
progressStep = 0.2;
|
|
169
|
+
}
|
|
149
170
|
if (progress >= 90) {
|
|
150
171
|
progressStep = 0.1;
|
|
151
172
|
}
|