Comparing version 2.1.13 to 2.1.14
{ | ||
"name": "@vmm/cli", | ||
"version": "2.1.13", | ||
"version": "2.1.14", | ||
"description": "vmm cli interface", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -29,4 +29,32 @@ const fs = require('fs-extra') | ||
/** | ||
* 更新或者替换html的调试信息 | ||
* @param {*} port | ||
*/ | ||
function updateDebugHtml(port) { | ||
let html = fs.readFileSync('./public/index.html', 'utf8') | ||
if (html.match(/<meta name="vmm-debug"/)) { | ||
// 替换 | ||
// console.log('-- replace') | ||
html = html.replace(/<meta name="vmm-debug".*?>/, | ||
`<meta name="vmm-debug" package="http://localhost:${port}">`) | ||
} else { | ||
// 新加 | ||
const pos = html.indexOf('</head>') | ||
html = html.slice(0, pos) + `<meta name="vmm-debug" package="http://localhost:${port}">\n` + html.slice(pos) | ||
} | ||
fs.writeFileSync('./public/index.html', html) | ||
} | ||
/** | ||
* 更新 package.json,更新loadFiles 和 depends 字段 | ||
*/ | ||
function updatePackageJson() { | ||
const pkg = fs.readJsonSync('./package.json') | ||
pkg.loadFiles = ['js/chunk-vendors.js', 'js/dev.js'] | ||
pkg.depends = Object.keys(pkg.dependencies) | ||
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2)) | ||
} | ||
/** | ||
* 开发模式运行 | ||
@@ -40,4 +68,10 @@ * 检查后台运行的vmm服务调度和应用 | ||
console.log(pkg.name, ' developer run :', port) | ||
// 更新 vue.config.js | ||
fs.writeFileSync('./vue.config.js', defaultVueConfigContent(port)) | ||
// 根据 port 更新 html | ||
updateDebugHtml(port) | ||
// 更新package.json | ||
// updatePackageJson() | ||
// 启动调试 | ||
execSync(`./node_modules/.bin/vue-cli-service serve --port ${port}`, { | ||
@@ -44,0 +78,0 @@ stdio: 'inherit' |
@@ -85,7 +85,11 @@ const fs = require('fs-extra') | ||
async function getLatestNpmPackage(pkg) { | ||
return await ( | ||
await fetch( | ||
`https://data.jsdelivr.com/v1/package/resolve/npm/${pkg}` | ||
) | ||
).json() | ||
return execSync(`npm view ${pkg} version`, { | ||
encoding: "utf8" | ||
}).trim() | ||
// 方法2 | ||
// return await ( | ||
// await fetch( | ||
// `https://data.jsdelivr.com/v1/package/resolve/npm/${pkg}` | ||
// ) | ||
// ).json().version | ||
} | ||
@@ -107,13 +111,13 @@ | ||
let newHtml = html | ||
const script = `\t<script src="` + | ||
encodeURI(`${baseAddr}/${loaderMeta.package}@${loaderMeta.version}/${pkg.main}`) + | ||
const script = `<script src="` + | ||
`${baseAddr}/${loaderMeta.package}@${loaderMeta.version}/${pkg.main}` + | ||
`"></script>` | ||
if (m) { | ||
// console.log('----replace') | ||
newHtml = html.replace(/^.*<script src=".*?@vmm\/loader.*?">.*?<\/script>/m, script) | ||
newHtml = html.replace(/<script src=".*?@vmm\/loader.*?">.*?<\/script>/m, script) | ||
} else { | ||
// console.log('----insert') | ||
const pos = html.indexOf('</head>') | ||
const pos = html.indexOf('</html>') | ||
if (pos > 0) { | ||
newHtml = html.slice(0, pos) + script + html.slice(pos) | ||
newHtml = html.slice(0, pos) + script + '\n' + html.slice(pos) | ||
} | ||
@@ -234,6 +238,6 @@ } | ||
console.log('fetch latest vmm-module:', modMeta.package) | ||
const info = await getLatestNpmPackage(modMeta.package) | ||
if (info && info.version) { | ||
console.log('-->', modMeta.name, info.version) | ||
modMeta.version = info.version | ||
const version = await getLatestNpmPackage(modMeta.package) | ||
if (version) { | ||
console.log('-->', modMeta.name, version) | ||
modMeta.version = version | ||
indexHtml = updateHtmlMeta(indexHtml, modMeta) | ||
@@ -240,0 +244,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32637
729
16