Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 26d0d13d
authored
Oct 29, 2025
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
style(scripts): 统一使用双引号替换单引号字符串
修改脚本中的字符串引号风格,从单引号统一改为双引号以保持代码风格一致
1 parent
b3145a7c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
23 deletions
scripts/createShims.cjs
scripts/createShims.cjs
View file @
26d0d13
...
@@ -10,10 +10,10 @@
...
@@ -10,10 +10,10 @@
* On POSIX: write venus (bash) with executable permission
* On POSIX: write venus (bash) with executable permission
*/
*/
const fs = require(
'fs'
);
const fs = require(
"fs"
);
const path = require(
'path'
);
const path = require(
"path"
);
const os = require(
'os'
);
const os = require(
"os"
);
const cp = require(
'child_process'
);
const cp = require(
"child_process"
);
function log(msg) {
function log(msg) {
console.log(`[createShims] ${msg}`);
console.log(`[createShims] ${msg}`);
...
@@ -21,10 +21,13 @@ function log(msg) {
...
@@ -21,10 +21,13 @@ function log(msg) {
function safeExec(cmd) {
function safeExec(cmd) {
try {
try {
const out = cp.execSync(cmd, { stdio: ['ignore', 'pipe', 'pipe'] }).toString().trim();
const out = cp
.execSync(cmd, { stdio: ["ignore", "pipe", "pipe"] })
.toString()
.trim();
return out;
return out;
} catch (e) {
} catch (e) {
return
''
;
return
""
;
}
}
}
}
...
@@ -38,46 +41,52 @@ function ensureDir(dir) {
...
@@ -38,46 +41,52 @@ function ensureDir(dir) {
function writeFile(filePath, content, mode) {
function writeFile(filePath, content, mode) {
ensureDir(path.dirname(filePath));
ensureDir(path.dirname(filePath));
fs.writeFileSync(filePath, content,
'utf8'
);
fs.writeFileSync(filePath, content,
"utf8"
);
if (mode) {
if (mode) {
try { fs.chmodSync(filePath, mode); } catch (_) {}
try {
fs.chmodSync(filePath, mode);
} catch (_) {}
}
}
log(`wrote shim: ${filePath}`);
log(`wrote shim: ${filePath}`);
}
}
function main() {
function main() {
const repoRoot = process.cwd();
const repoRoot = process.cwd();
const entry = path.resolve(repoRoot,
'packages/cli/dist/index.cjs.js'
);
const entry = path.resolve(repoRoot,
"packages/cli/dist/index.cjs.js"
);
const isWin = process.platform ===
'win32'
;
const isWin = process.platform ===
"win32"
;
if (!fs.existsSync(entry)) {
if (!fs.existsSync(entry)) {
log(`entry not found: ${entry}`);
log(`entry not found: ${entry}`);
log(
'skip creating shims (CLI not built yet).'
);
log(
"skip creating shims (CLI not built yet)."
);
return;
return;
}
}
// Prefer pnpm reported global bin, then common fallback dirs
// Prefer pnpm reported global bin, then common fallback dirs
const pnpmGlobalBin = safeExec(
'pnpm bin -g'
);
const pnpmGlobalBin = safeExec(
"pnpm bin -g"
);
const candidates = [];
const candidates = [];
if (pnpmGlobalBin) candidates.push(pnpmGlobalBin);
if (pnpmGlobalBin) candidates.push(pnpmGlobalBin);
if (isWin) {
if (isWin) {
// Common Node.js global bin location added to PATH by many installers
// Common Node.js global bin location added to PATH by many installers
candidates.push(path.join(os.homedir(),
'AppData', 'Roaming', 'npm'
));
candidates.push(path.join(os.homedir(),
"AppData", "Roaming", "npm"
));
} else {
} else {
// Common pnpm homes on POSIX
// Common pnpm homes on POSIX
candidates.push(path.join(os.homedir(),
'.local', 'share', 'pnpm'
));
candidates.push(path.join(os.homedir(),
".local", "share", "pnpm"
));
candidates.push(path.join(os.homedir(),
'Library', 'pnpm'
)); // macOS
candidates.push(path.join(os.homedir(),
"Library", "pnpm"
)); // macOS
}
}
// De-duplicate and keep only existing dirs
// De-duplicate and keep only existing dirs
const dirs = Array.from(new Set(candidates)).filter((d) => {
const dirs = Array.from(new Set(candidates)).filter(d => {
try { return fs.existsSync(d); } catch (_) { return false; }
try {
return fs.existsSync(d);
} catch (_) {
return false;
}
});
});
if (dirs.length === 0) {
if (dirs.length === 0) {
log(
'no global bin directories found.'
);
log(
"no global bin directories found."
);
log(
'you may need to run `pnpm setup` to add PNPM_HOME to PATH.'
);
log(
"you may need to run `pnpm setup` to add PNPM_HOME to PATH."
);
return;
return;
}
}
...
@@ -85,20 +94,20 @@ function main() {
...
@@ -85,20 +94,20 @@ function main() {
try {
try {
if (isWin) {
if (isWin) {
const cmdBody = `@echo off\r\nnode "${entry}" %*`;
const cmdBody = `@echo off\r\nnode "${entry}" %*`;
writeFile(path.join(dir,
'venus.cmd'
), cmdBody);
writeFile(path.join(dir,
"venus.cmd"
), cmdBody);
const ps1Body = `& node "${entry}" $args`;
const ps1Body = `& node "${entry}" $args`;
writeFile(path.join(dir,
'venus.ps1'
), ps1Body);
writeFile(path.join(dir,
"venus.ps1"
), ps1Body);
} else {
} else {
const bashBody = `#!/usr/bin/env bash\nnode "${entry}" "$@"`;
const bashBody = `#!/usr/bin/env bash\nnode "${entry}" "$@"`;
writeFile(path.join(dir,
'venus'
), bashBody, 0o755);
writeFile(path.join(dir,
"venus"
), bashBody, 0o755);
}
}
} catch (e) {
} catch (e) {
log(`failed to write into ${dir}: ${e && e.message}`);
log(`failed to write into ${dir}: ${e && e.message}`);
}
}
}
}
log(
'done.'
);
log(
"done."
);
}
}
main();
main();
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment