-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update optionalDependencies package name
- Loading branch information
1 parent
49f0868
commit 1335ca6
Showing
5 changed files
with
65 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,69 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { execSync } = require('child_process') | ||
const { getPackageInfoByCurrentPlatform } = require('../utils') | ||
|
||
try { | ||
// npm 文件夹路径 | ||
const npmDir = path.join(__dirname, '../npm') | ||
// 获取子文件夹 | ||
const folders = fs.readdirSync(npmDir) | ||
function updatePackageOptionalDependencies() { | ||
const packageJsonPath = path.join(__dirname, '../package.json') | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) | ||
// 获取当前版本号 | ||
const currentVersion = process.argv[2] | ||
if (!process.argv[2]) { | ||
return (packageJson.optionalDependencies = {}) | ||
} | ||
// 更新 optionalDependencies 中的版本号 | ||
const { packages } = getPackageInfoByCurrentPlatform() | ||
packageJson.optionalDependencies = Object.fromEntries( | ||
packages.map((name) => [name, currentVersion]), | ||
) | ||
} | ||
|
||
// 从环境变量中获取 npm token | ||
const npmToken = process.env.NPM_TOKEN | ||
function publishChildPackage() { | ||
try { | ||
// npm 文件夹路径 | ||
const npmDir = path.join(__dirname, '../npm') | ||
// 获取子文件夹 | ||
const folders = fs.readdirSync(npmDir) | ||
|
||
if (!npmToken) { | ||
console.error('请确保设置 NPM_TOKEN 环境变量。') | ||
process.exit(1) | ||
} | ||
// 从环境变量中获取 npm token | ||
const npmToken = process.env.NPM_TOKEN | ||
|
||
if (!npmToken) { | ||
console.error('请确保设置 NPM_TOKEN 环境变量。') | ||
process.exit(1) | ||
} | ||
|
||
// 遍历每个子文件夹 | ||
folders.forEach((folder) => { | ||
const folderPath = path.join(npmDir, folder) | ||
// 遍历每个子文件夹 | ||
folders.forEach((folder) => { | ||
const folderPath = path.join(npmDir, folder) | ||
|
||
// 检查是否是文件夹 | ||
const stats = fs.statSync(folderPath) | ||
if (stats.isDirectory()) { | ||
// 检查是否有 package.json | ||
const packageJsonPath = path.join(folderPath, 'package.json') | ||
if (fs.existsSync(packageJsonPath)) { | ||
console.log(`正在发布 ${folder}...`) | ||
try { | ||
// 执行 npm publish | ||
execSync( | ||
`npm publish --access public --scope=@grprogress --//registry.npmjs.org/:_authToken=${npmToken} --loglevel verbose`, | ||
{ | ||
cwd: folderPath, | ||
stdio: 'inherit', | ||
}, | ||
) | ||
console.log(`发布 ${folder} 成功!`) | ||
} catch (err) { | ||
console.error(`发布 ${folder} 失败:`, err.message) | ||
// 检查是否是文件夹 | ||
const stats = fs.statSync(folderPath) | ||
if (stats.isDirectory()) { | ||
// 检查是否有 package.json | ||
const packageJsonPath = path.join(folderPath, 'package.json') | ||
if (fs.existsSync(packageJsonPath)) { | ||
console.log(`正在发布 ${folder}...`) | ||
try { | ||
// 执行 npm publish | ||
execSync( | ||
`npm publish --access public --scope=@grprogress --//registry.npmjs.org/:_authToken=${npmToken} --loglevel verbose`, | ||
{ | ||
cwd: folderPath, | ||
stdio: 'inherit', | ||
}, | ||
) | ||
console.log(`发布 ${folder} 成功!`) | ||
} catch (err) { | ||
console.error(`发布 ${folder} 失败:`, err.message) | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
} catch (err) { | ||
console.error('发布发生错误:', err.message) | ||
}) | ||
} catch (err) { | ||
console.error('发布发生错误:', err.message) | ||
} | ||
} | ||
|
||
updatePackageOptionalDependencies() | ||
publishChildPackage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters