Comparing version 2.1.41 to 2.1.42
{ | ||
"name": "@vmm/cli", | ||
"version": "2.1.41", | ||
"version": "2.1.42", | ||
"description": "vmm cli interface", | ||
@@ -5,0 +5,0 @@ "author": { |
const fs = require('fs-extra') | ||
const path = require('path') | ||
const snakecase = require('lodash.snakecase') | ||
const execSync = require('child_process').execSync | ||
@@ -52,2 +53,10 @@ | ||
console.log(pkg.name, ' developer run :', port) | ||
// 更新全局变量 | ||
pkg.globalVar = '__' + snakecase(pkg.name) | ||
pkg.loadFiles = [ | ||
"js/chunk-vendors.js", | ||
"js/dev.js" | ||
] | ||
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2)) | ||
// 更新 vue.config.js | ||
@@ -54,0 +63,0 @@ fs.writeFileSync('./vue.config.js', defaultVueConfigContent(port)) |
@@ -6,81 +6,10 @@ const fs = require('fs-extra') | ||
const execSync = require('child_process').execSync | ||
const { | ||
parseMetaAttrs, | ||
parseHtmlMeta, | ||
updateHtmlMeta, | ||
findMetaList, | ||
} = require('./htmlMetaParser') | ||
/** | ||
* 解析meta 标签属性 | ||
* @param {*} metaTag | ||
*/ | ||
function parseMetaAttrs(metaTag) { | ||
const sp = metaTag.split(/\s+/) | ||
const attrs = {} | ||
// console.log('attrs', attrs) | ||
for (let a of sp) { | ||
if (a.startsWith('<')) continue | ||
if (a.endsWith('>')) a = a.slice(0, a.length - 1) | ||
const am = a.match(/(.+)=\"(.*)\"/) | ||
// console.log('am', a, am) | ||
if (am && am.length === 3) { | ||
attrs[am[1]] = am[2] | ||
} else { | ||
attrs[a] = '' | ||
} | ||
} | ||
return attrs | ||
} | ||
/** | ||
* 解析 meta 字符串 | ||
* 返回meta列表 | ||
* @param {string} html | ||
*/ | ||
function parseHtmlMeta(html) { | ||
const meta = [] | ||
const ret = html.match(/<meta.+?>/g) | ||
for (const m of ret) { | ||
const attrs = parseMetaAttrs(m) | ||
if (attrs['name']) { | ||
meta.push(attrs) | ||
} | ||
} | ||
return meta | ||
} | ||
/** | ||
* 更新 meta 属性 | ||
* @param {string} html | ||
* @param {object} metaInfo | ||
*/ | ||
function updateHtmlMeta(html, metaInfo) { | ||
let str = '<meta'; | ||
for (const a of Object.keys(metaInfo)) { | ||
if (metaInfo[a]) { | ||
str += ` ${a}="${metaInfo[a]}"` | ||
} else { | ||
str += ` ${a}` | ||
} | ||
} | ||
str += '>' | ||
const regex = RegExp(`<meta\\s+name="${metaInfo.name}"\\s+package="${metaInfo.package}".*?>`, 'mg') | ||
// console.log('updateHtmlMeta:', metaInfo.name, metaInfo.package, regex) | ||
return html.replace(regex, str) | ||
} | ||
/** | ||
* 从 meta 列表中获取指定的meta元素,只取第一个 | ||
* @param {*} metaList 列表 | ||
* @param {*} name meta 名字 | ||
* @param {*} package 包名,可以为空 | ||
*/ | ||
function findMetaList(metaList, name, package) { | ||
for (const m of metaList) { | ||
if (package) { | ||
if (m.name === name && m.package === package) return m | ||
} else { | ||
if (m.name === name) return m | ||
} | ||
} | ||
return null | ||
} | ||
async function getLatestNpmPackage(pkg) { | ||
@@ -87,0 +16,0 @@ return execSync(`npm_config_registry=\"https://registry.npmjs.org/\" npm view ${pkg} version`, { |
const { | ||
createProxyMiddleware | ||
} = require('http-proxy-middleware') | ||
const { | ||
parseMetaAttrs, | ||
parseHtmlMeta, | ||
updateHtmlMeta, | ||
findMetaList, | ||
} = require('../src/htmlMetaParser') | ||
const proxyMiddle = createProxyMiddleware({ | ||
@@ -10,2 +15,3 @@ target: 'http://localhost:9000', | ||
}) | ||
// const serviceFn = require('@vmm/user-service/service.js') | ||
@@ -12,0 +18,0 @@ |
@@ -18,5 +18,9 @@ // 配置参考: https://cli.vuejs.org/zh/config/ | ||
}, | ||
publicPath: './', | ||
devServer: { | ||
port, | ||
headers: { | ||
'Access-Control-Allow-Origin': '*' | ||
}, | ||
contentBase: [path.resolve('./public'), path.resolve('.')], | ||
@@ -23,0 +27,0 @@ historyApiFallback: false, |
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
61364
52
1240