代码拉取完成,页面将自动刷新
const cp = require('child_process')
const fs = require('fs')
const path = require('path')
let revision = ''
try {
let res = cp.execSync('git rev-parse HEAD', {encoding: 'utf8'})
revision = res.trim().slice(0, 10)
} catch (e) {
// ignore
}
let entryPlugin = {
name: 'entry',
setup(build) {
build.onResolve({filter: /^index.ts$/}, args => {
return {
path: args.path,
namespace: 'entry-ns'
}
})
build.onLoad({filter: /.*/, namespace: 'entry-ns'}, () => {
let contents = `
let version = process.version.replace('v', '')
let parts = version.split('.')
function greatThanOrEqual(nums, major, minor) {
if (nums[0] > major) return true
if (nums[0] == major && nums[1] >= minor) return true
return false
}
let numbers = parts.map(function (s) {
return parseInt(s, 10)
})
if (!greatThanOrEqual(numbers, 10, 12)) {
console.error('node version ' + version + ' < 8.10.0, please upgrade nodejs, or use \`let g:coc_node_path = "/path/to/node"\` in your vimrc')
process.exit()
}
require('./src/main')
`
return {
contents,
resolveDir: __dirname
}
})
}
}
// replace require.main with empty string
let envPlugin = {
name: 'env',
setup(build) {
build.onResolve({filter: /\/appenders/}, args => {
let fullpath = path.join(args.resolveDir, args.path)
return {
path: path.relative(__dirname, fullpath),
namespace: 'env-ns'
}
})
build.onLoad({filter: /^node_modules\/log4js\/lib\/appenders$/, namespace: 'env-ns'}, args => {
let content = fs.readFileSync(path.join(args.path, 'index.js'), 'utf8')
return {
contents: content.replace(/require\.main/g, '""'),
resolveDir: args.path
}
})
}
}
async function start() {
await require('esbuild').build({
entryPoints: ['index.ts'],
bundle: true,
minify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV === 'development',
define: {REVISION: '"' + revision + '"', ESBUILD: 'true'},
mainFields: ['module', 'main'],
platform: 'node',
target: 'node10.12',
outfile: 'build/index.js',
plugins: [entryPlugin, envPlugin]
})
}
start().catch(e => {
console.error(e)
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。