Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
const colors = require("ansi-colors");
const config = require("../src/config");
function cb(str) { return colors.cyanBright.bold(str) }
function c(str) { return colors.greenBright.bold(str) }
function cw(str) { return colors.magentaBright.bold(str) }
function cd(str) { return colors.cyan.italic(str) }
function od(str) { return colors.italic(str) }
function odc(str) { return colors.reset.gray(str) }
function ed(str) { return colors.gray(str) }
var argv = require("yargs")
.scriptName("mp")
.usage(colors.whiteBright.inverse.bold("\n> Wechat MiniProgram build tools 微信小程序编译打包工具 <\n"))
.usage(`${colors.italic("Short Usage")} <短用法>: ${colors.bold.yellowBright("$0")} ${colors.cyanBright("[command...]")} ${colors.italic("[--option]")}`)
.usage(`${colors.italic("Full Name")} <完整名称>: ${colors.bold.yellowBright("miniprogram-build")} ${colors.cyanBright("[命令...]")} ${colors.italic("[--选项]")}`)
.example(colors.green.italic("$0 js js-watch"), ed("编译并监测生成js文件"))
.example(colors.green.italic("$0 --config=mpconfig.json"), ed("指定配置文件"))
.example(colors.green.italic("$0 --release --var.APP_ID=1234"), ed("优化编译,并替换变量{{APP_ID}}"))
// configuration
.pkgConf("mpconfig")
.config("config", od(`JSONC config file ${odc("<配置置文件,命令参数优先级高于配置>")}`), config.load)
.config(config.auto())
.alias("c", "config")
.help("help", od(`show help ${odc("<显示帮助信息>")}`))
.alias("h", "help")
.describe("version", od(`show version number ${odc("<查看本版号>")}`))
.epilog(colors.red.bold("♥ ")
+ colors.italic(colors.gray("2018 - " + new Date().getFullYear()) + colors.cyan.dim(" @NewFuture "))
+ colors.gray(" → https://github.com/NewFuture/miniprogram-build")
+ colors.red.bold(" ♥")
module.exports = (percent, fps, timemark) => {
const stream = process.stderr
let percentStr = `${c.bold(percent)}${c.bold('%')}`
let fpsStr = `${c.bold(fps)}${c.italic('/fps')}`
let timemarkStr = `${c.bold(timemark)}${c.italic('/encoded')}`
// calculate 3 dots
let dotsCount = (Number(Number(percent).toFixed()) % 3) + 1
let downloadingStr = `${c.bold(`Downloading${'.'.repeat(dotsCount)}`)}${' '.repeat(3 - dotsCount)}`
let str = `${c.bold.cyan('i')} ${downloadingStr} ${percentStr} ${fpsStr} ${timemarkStr}`
stream.cursorTo(0)
stream.write(str)
stream.clearLine(1)
}
const colors = require("ansi-colors");
const config = require("../src/config");
function cb(str) { return colors.cyanBright.bold(str) }
function c(str) { return colors.greenBright.bold(str) }
function cw(str) { return colors.magentaBright.bold(str) }
function cd(str) { return colors.cyan.italic(str) }
function od(str) { return colors.italic(str) }
function odc(str) { return colors.reset.gray(str) }
function ed(str) { return colors.gray(str) }
var argv = require("yargs")
.scriptName("mp")
.usage(colors.whiteBright.inverse.bold("\n> Wechat MiniProgram build tools 微信小程序编译打包工具 <\n"))
.usage(`${colors.italic("Short Usage")} <短用法>: ${colors.bold.yellowBright("$0")} ${colors.cyanBright("[command...]")} ${colors.italic("[--option]")}`)
.usage(`${colors.italic("Full Name")} <完整名称>: ${colors.bold.yellowBright("miniprogram-build")} ${colors.cyanBright("[命令...]")} ${colors.italic("[--选项]")}`)
.example(colors.green.italic("$0 js js-watch"), ed("编译并监测生成js文件"))
.example(colors.green.italic("$0 --config=mpconfig.json"), ed("指定配置文件"))
.example(colors.green.italic("$0 --release --var.APP_ID=1234"), ed("优化编译,并替换变量{{APP_ID}}"))
// configuration
.pkgConf("mpconfig")
.config("config", od(`JSONC config file ${odc("<配置置文件,命令参数优先级高于配置>")}`), config.load)
.config(config.auto())
.alias("c", "config")
.help("help", od(`show help ${odc("<显示帮助信息>")}`))
.alias("h", "help")
.describe("version", od(`show version number ${odc("<查看本版号>")}`))
.epilog(colors.red.bold("♥ ")
+ colors.italic(colors.gray("2018 - " + new Date().getFullYear()) + colors.cyan.dim(" @NewFuture "))
+ colors.gray(" → https://github.com/NewFuture/miniprogram-build")
+ colors.red.bold(" ♥")
)
.usage(colors.whiteBright.inverse.bold("\n> Wechat MiniProgram build tools 微信小程序编译打包工具 <\n"))
.usage(`${colors.italic("Short Usage")} <短用法>: ${colors.bold.yellowBright("$0")} ${colors.cyanBright("[command...]")} ${colors.italic("[--option]")}`)
.usage(`${colors.italic("Full Name")} <完整名称>: ${colors.bold.yellowBright("miniprogram-build")} ${colors.cyanBright("[命令...]")} ${colors.italic("[--选项]")}`)
.example(colors.green.italic("$0 js js-watch"), ed("编译并监测生成js文件"))
.example(colors.green.italic("$0 --config=mpconfig.json"), ed("指定配置文件"))
.example(colors.green.italic("$0 --release --var.APP_ID=1234"), ed("优化编译,并替换变量{{APP_ID}}"))
// configuration
.pkgConf("mpconfig")
.config("config", od(`JSONC config file ${odc("<配置置文件,命令参数优先级高于配置>")}`), config.load)
.config(config.auto())
.alias("c", "config")
.help("help", od(`show help ${odc("<显示帮助信息>")}`))
.alias("h", "help")
.describe("version", od(`show version number ${odc("<查看本版号>")}`))
.epilog(colors.red.bold("♥ ")
+ colors.italic(colors.gray("2018 - " + new Date().getFullYear()) + colors.cyan.dim(" @NewFuture "))
+ colors.gray(" → https://github.com/NewFuture/miniprogram-build")
+ colors.red.bold(" ♥")
)
.option("production", {
describe: od(`production mode ${odc("<发布模式会优化压缩>")}`),
default: process.env.NODE_ENV === "production" || process.env.NODE_ENV === "prod",
boolean: true,
})
.alias("production", "release")
.option("src", {
describe: od(`source folder ${odc("<源文件目录>")}`),
default: "src",
type: "string",
})
.option("dist", {
describe: od(`output folder ${odc("<编译输出目录>")}`),
async function step(actor, message, context = '') {
let prefix
prefix = actor.padEnd(7)
if (context) context = c.italic(` <${context}>`)
if (actor === 'alice') prefix = c.cyan(prefix)
else if (actor === 'bob') prefix = c.magenta(prefix)
else if (actor === 'charlie') prefix = c.yellow(prefix)
console.log(`${prefix}${context} ${c.grey(message)}`)
if (settings.DEBUG_MODE) {
await utils.delay(2000)
}
}
function logReplace(n, key, value, file) {
log.info(
colors.gray(TITLE),
colors.gray.bold(colors.symbols.check.repeat(n)),
colors.gray.dim.italic.strikethrough(key.toString()),
colors.dim.gray(colors.symbols.pointerSmall),
typeof value === 'function' ? colors.cyan(colors.italic('Function:') + (value.name || '')) : colors.underline(value),
colors.gray('(' + colors.underline(
path.relative(file.base, file.path)
) + ')')
)
}
const enable = (choices, fn) => choices.forEach(ch => (ch.enabled = fn(ch)));
const prompt = new MultiSelect({
name: 'food',
message: 'What are your favorite foods?',
choices: [
{ name: 'all',
message: colors.italic('All'),
onChoice(state, choice, i) {
if (state.index === i && choice.enabled) {
enable(state.choices, ch => ch.name !== 'none');
}
}
},
{ name: 'none',
message: colors.italic('None'),
onChoice(state, choice, i) {
if (state.index === i) {
if (choice.enabled) {
enable(state.choices, ch => ch.name === 'none');
}
}
if (state.keypress && state.keypress.name === 'a') choice.enabled = false;
if (state.index !== i && state.choices[state.index].enabled === true) {
choice.enabled = false;
}
}
},
{ role: 'separator' },
{ name: 'lasagna', message: 'Lasagna' },
{ name: 'pizza', message: 'Pizza' },
{ name: 'chicken_curry', message: 'Chicken Curry' },
function od(str) { return colors.italic(str) }
function odc(str) { return colors.reset.gray(str) }