@blocklet/component-studio-cli 0.4.151 → 0.4.153
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/dist/commands/dev.js +9 -9
- package/dist/utils/helper.d.ts +1 -0
- package/dist/utils/helper.js +5 -2
- package/package.json +1 -1
package/dist/commands/dev.js
CHANGED
|
@@ -5,7 +5,7 @@ import fs from 'fs-extra';
|
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import ora from 'ora';
|
|
8
|
-
import { getWorkspaceTemplatePath, installDependencies, getWorkspacePath, getProjectPath, replaceInDirectoryFileNameWithExample, } from '../utils/helper.js';
|
|
8
|
+
import { getWorkspaceTemplatePath, installDependencies, getWorkspacePath, getProjectPath, replaceInDirectoryFileNameWithExample, checkShouldInstallDependencies, } from '../utils/helper.js';
|
|
9
9
|
async function createDevServer(projectPath, _options) {
|
|
10
10
|
// 1. 创建工作区
|
|
11
11
|
const workspacePath = getWorkspacePath();
|
|
@@ -54,18 +54,18 @@ async function createDevServer(projectPath, _options) {
|
|
|
54
54
|
await fs.ensureSymlink(projectPath, projectLinkDir);
|
|
55
55
|
projectLinkSpinner.succeed(chalk.green('Project linked to workspace successfully!'));
|
|
56
56
|
}
|
|
57
|
-
let shouldInstallWorkspaceDeps =
|
|
58
|
-
let shouldInstallProjectDeps =
|
|
57
|
+
let shouldInstallWorkspaceDeps = await checkShouldInstallDependencies(workspacePath);
|
|
58
|
+
let shouldInstallProjectDeps = await checkShouldInstallDependencies(projectPath);
|
|
59
59
|
// 5. 安装依赖
|
|
60
60
|
if (shouldInstallWorkspaceDeps || shouldInstallProjectDeps) {
|
|
61
|
-
const
|
|
62
|
-
if (shouldInstallWorkspaceDeps) {
|
|
63
|
-
dirsToInstall['Workspace'] = workspacePath;
|
|
64
|
-
}
|
|
61
|
+
const installDeps = {};
|
|
65
62
|
if (shouldInstallProjectDeps) {
|
|
66
|
-
|
|
63
|
+
installDeps.Project = projectPath;
|
|
64
|
+
}
|
|
65
|
+
if (shouldInstallWorkspaceDeps) {
|
|
66
|
+
installDeps.Workspace = workspacePath;
|
|
67
67
|
}
|
|
68
|
-
const result = await installDependencies(
|
|
68
|
+
const result = await installDependencies(installDeps);
|
|
69
69
|
if (!result) {
|
|
70
70
|
process.exit(1);
|
|
71
71
|
}
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -100,3 +100,4 @@ export declare function isCommandAvailable(command: string): boolean;
|
|
|
100
100
|
* @returns 安装是否成功
|
|
101
101
|
*/
|
|
102
102
|
export declare function installGlobalPackage(packageName: string): Promise<boolean>;
|
|
103
|
+
export declare function checkShouldInstallDependencies(dirPath: string): Promise<boolean>;
|
package/dist/utils/helper.js
CHANGED
|
@@ -107,7 +107,7 @@ export async function installDependencies(dirs, operation = 'install') {
|
|
|
107
107
|
let errorOutput = '';
|
|
108
108
|
const process = spawn('pnpm', ['update:deps'], {
|
|
109
109
|
cwd: dirPath,
|
|
110
|
-
stdio:
|
|
110
|
+
stdio: 'inherit',
|
|
111
111
|
});
|
|
112
112
|
// 收集错误输出
|
|
113
113
|
process.stderr?.on('data', (data) => {
|
|
@@ -125,7 +125,7 @@ export async function installDependencies(dirs, operation = 'install') {
|
|
|
125
125
|
resolve();
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
|
-
reject(new Error(`${dirType} dependencies install failed with code ${code}
|
|
128
|
+
reject(new Error(`${dirType} dependencies install failed with code ${code}. ${errorOutput ? `\nError details:\n${errorOutput?.trimStart()}` : ''}}`));
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
process.on('error', (error) => {
|
|
@@ -513,3 +513,6 @@ export async function installGlobalPackage(packageName) {
|
|
|
513
513
|
return false;
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
|
+
export async function checkShouldInstallDependencies(dirPath) {
|
|
517
|
+
return !(await fs.exists(join(dirPath, 'node_modules'))) || !(await fs.exists(join(dirPath, 'pnpm-lock.yaml')));
|
|
518
|
+
}
|