UNPKG

2.68 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11const fs = require("fs-extra");
12const path = require("path");
13const chalk_1 = require("chalk");
14const helper_1 = require("./mini/helper");
15const mini_1 = require("./mini");
16const PLUGIN_JSON = 'plugin.json';
17const PLUGIN_MOCK_JSON = 'plugin-mock.json';
18function build(appPath, { watch, platform }, builder) {
19 return __awaiter(this, void 0, void 0, function* () {
20 switch (platform) {
21 case "weapp" /* WEAPP */:
22 yield buildWxPlugin(appPath, { watch, type: "weapp" /* WEAPP */ }, builder);
23 break;
24 case "alipay" /* ALIPAY */:
25 yield buildAlipayPlugin(appPath, { watch, type: "alipay" /* ALIPAY */ }, builder);
26 break;
27 default:
28 console.log(chalk_1.default.red('输入插件类型错误,目前只支持 weapp/alipay 插件类型'));
29 break;
30 }
31 });
32}
33exports.build = build;
34function buildWxPlugin(appPath, { watch, type }, builder) {
35 return __awaiter(this, void 0, void 0, function* () {
36 yield mini_1.build(appPath, { watch, type: "plugin" /* PLUGIN */ }, null, builder);
37 const { outputDirName } = helper_1.getBuildData();
38 yield mini_1.build(appPath, { watch, type }, {
39 outputDirName: `${outputDirName}/miniprogram`
40 }, builder);
41 });
42}
43function buildAlipayPlugin(appPath, { watch, type }, builder) {
44 return __awaiter(this, void 0, void 0, function* () {
45 yield mini_1.build(appPath, { watch, type }, null, builder);
46 const { sourceDir, outputDir } = helper_1.getBuildData();
47 const pluginJson = path.join(sourceDir, PLUGIN_JSON);
48 const pluginMockJson = path.join(sourceDir, PLUGIN_MOCK_JSON);
49 if (fs.existsSync(pluginJson)) {
50 fs.copyFileSync(pluginJson, path.join(outputDir, PLUGIN_JSON));
51 }
52 if (fs.existsSync(pluginMockJson)) {
53 fs.copyFileSync(pluginMockJson, path.join(outputDir, PLUGIN_MOCK_JSON));
54 }
55 });
56}