@tarojs/cli
Version:
cli tool for taro
75 lines • 3.85 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("node:path");
const helper_1 = require("@tarojs/helper");
const shared_1 = require("@tarojs/shared");
const configName = 'mini';
exports.default = (ctx) => {
ctx.registerPlatform({
name: 'plugin',
useConfigName: configName,
fn(_a) {
return __awaiter(this, arguments, void 0, function* ({ config }) {
const { options, _ } = ctx.runOpts;
const { chalk, PLATFORMS } = ctx.helper;
const { WEAPP, ALIPAY, JD } = PLATFORMS;
const typeMap = {
[JD]: '京东',
[WEAPP]: '微信',
[ALIPAY]: '支付宝'
};
const { plugin, isWatch } = options;
if (plugin !== WEAPP && plugin !== ALIPAY && plugin !== JD) {
console.log(chalk.red('目前插件编译仅支持 微信/支付宝/京东 小程序!'));
return;
}
console.log(chalk.green(`开始编译${typeMap[plugin]}小程序插件`));
function buildPlugin(platform) {
return __awaiter(this, void 0, void 0, function* () {
process.env.TARO_ENV = platform;
process.env.TARO_PLATFORM = (0, shared_1.getPlatformType)(platform, configName);
yield ctx.applyPlugins({
name: 'build',
opts: {
config: Object.assign(Object.assign({}, config), { isBuildPlugin: true, isWatch, outputRoot: `${config.outputRoot}/plugin`, platform }),
options: Object.assign({}, options, {
platform
}),
_
}
});
yield ctx.applyPlugins({
name: 'build',
opts: {
config: Object.assign(Object.assign({}, config), { isBuildPlugin: false, isWatch, outputRoot: `${config.outputRoot}/miniprogram`, platform, output: Object.assign(Object.assign({}, (config.output || {})), { clean: false }) }),
options: Object.assign({}, options, {
platform
}),
_
}
});
});
}
yield buildPlugin(plugin);
try {
const docSrcPath = path.join(process.cwd(), 'src/plugin/doc');
const docDestPath = path.join(process.cwd(), 'miniprogram/doc');
helper_1.fs.copy(docSrcPath, docDestPath);
}
catch (err) {
console.error('[@tarojs/cli] build plugin doc failed: ', err);
}
});
}
});
};
//# sourceMappingURL=plugin.js.map
;