1 | import config from "../config";
|
2 | import rimraf from "rimraf";
|
3 | import path from "path";
|
4 | import fs from "fs";
|
5 | import { copyFiles, readJson, mkdirs, runCommands } from "node-pearls";
|
6 | import console from "cli-console";
|
7 | import tarzip from "../utils/tar&zip";
|
8 |
|
9 | export default async function(options){
|
10 |
|
11 | const platforms = options.platforms ? options.platforms.split(",").map(platform => platform.trim()) : [];
|
12 | const businessName = options.businessName;
|
13 | const iosZipname = options.iosZipname || businessName + "_package";
|
14 | const androidZipname = options.androidZipname || businessName + "_package";
|
15 | const pushBranch = options.increment ? "increment" : (options.pushBranch || "master");
|
16 | const version = options.version;
|
17 | const buildId = options.buildId;
|
18 | const currentDir = process.cwd();
|
19 |
|
20 | var depPlatforms = [];
|
21 | var hasRn = platforms.some(platform => ["ios", "android"].indexOf(platform) !== -1);
|
22 | if(hasRn){
|
23 | depPlatforms = ["rn"].concat(platforms.filter(platform => ["ios", "android"].indexOf(platform) === -1));
|
24 | }else{
|
25 | depPlatforms = platforms;
|
26 | }
|
27 |
|
28 |
|
29 | console.title("安装依赖");
|
30 | await runCommands(`npm i`);
|
31 | await runCommands(depPlatforms.map(platform => `enjoy update --${platform === "rn" ? "ios" : platform}`).join("\n"));
|
32 |
|
33 | try{
|
34 |
|
35 | await runCommands("npm shrinkwrap", {
|
36 | cwd: currentDir
|
37 | });
|
38 | fs.renameSync(
|
39 | path.join(currentDir, "npm-shrinkwrap.json"),
|
40 | path.join(currentDir, "_npm-shrinkwrap.json")
|
41 | );
|
42 |
|
43 | await Promise.all(depPlatforms.map(platform => (async () => {
|
44 | let dir = platform === "rn" ? path.join(currentDir, "rn") : path.join(currentDir, config["group-hash"][platform], platform);
|
45 | await runCommands("npm shrinkwrap", {
|
46 | cwd: dir
|
47 | });
|
48 | fs.renameSync(
|
49 | path.join(dir, "npm-shrinkwrap.json"),
|
50 | path.join(dir, "_npm-shrinkwrap.json")
|
51 | );
|
52 | })()));
|
53 | }catch(e){
|
54 | console.log(e);
|
55 | }
|
56 |
|
57 |
|
58 | console.title("打包");
|
59 | await runCommands(platforms.map(platform => {
|
60 | let zipname = {
|
61 | "ios": iosZipname,
|
62 | "android": androidZipname
|
63 | }[platform] || "";
|
64 |
|
65 | let argus = [];
|
66 |
|
67 | if(zipname){
|
68 | argus.push(`--zipname ${zipname}`);
|
69 | }
|
70 |
|
71 | if(options.release){
|
72 | argus.push("--release");
|
73 | }
|
74 |
|
75 | return [`enjoy bundle --${platform}`].concat(argus).join(" ");
|
76 | }).join("\n"));
|
77 |
|
78 |
|
79 | mkdirs.sync(config["tmp-dir"]);
|
80 | await Promise.all(platforms.map(platform => (async () => {
|
81 | if(platform === "ios"){
|
82 | let gitname = `elongreactnativepackages@${pushBranch}`;
|
83 | let gitdir = path.join(config["tmp-dir"], gitname);
|
84 |
|
85 | console.title("拉取项目");
|
86 | if(!fs.existsSync(gitdir)){
|
87 | await runCommands(`
|
88 | git clone git@code.corp.elong.com:ios/elongreactnativepackages.git ${gitdir} -b ${pushBranch} --depth 1
|
89 | `);
|
90 | }else{
|
91 | await runCommands(`
|
92 | git pull
|
93 | `, {
|
94 | cwd: gitdir
|
95 | });
|
96 | }
|
97 |
|
98 | console.title("生成zip包");
|
99 | let COMBO_PATH = path.join(currentDir, "rn", "ios", "bundle", "combo");
|
100 | let dirs = fs.readdirSync(COMBO_PATH)
|
101 | .map(file => path.join(COMBO_PATH, file))
|
102 | .filter(file => fs.statSync(file).isDirectory());
|
103 |
|
104 | let md5 = await tarzip(
|
105 | path.join(COMBO_PATH, `business.js`),
|
106 | dirs,
|
107 | gitdir,
|
108 | iosZipname
|
109 | );
|
110 |
|
111 | console.title("提交git");
|
112 | await runCommands(`
|
113 | git add .
|
114 | git commit -m ${options.increment ? "1": "0"}:${businessName}@${version}:${md5}:${buildId}
|
115 | git push
|
116 | `, {
|
117 | cwd: gitdir
|
118 | });
|
119 | }else if(platform === "android"){
|
120 | let gitname = `as_elongrnplugin_44_jsbundle@${pushBranch}`;
|
121 | let gitdir = path.join(config["tmp-dir"], gitname);
|
122 |
|
123 | console.title("拉取项目");
|
124 | if(!fs.existsSync(gitdir)){
|
125 | await runCommands(`
|
126 | git clone git@code.corp.elong.com:elongtravel_android/as_elongrnplugin_44_jsbundle.git ${gitdir} -b ${pushBranch} --depth 1
|
127 | `);
|
128 | }else{
|
129 | await runCommands(`
|
130 | git pull
|
131 | `, {
|
132 | cwd: gitdir
|
133 | });
|
134 | }
|
135 |
|
136 | console.title("生成zip包");
|
137 | let COMBO_PATH = path.join(currentDir, "rn", "android", "bundle", "combo");
|
138 | let assetsdir = path.join(COMBO_PATH, "assets");
|
139 | let dirs = fs.readdirSync(COMBO_PATH)
|
140 | .map(file => path.join(COMBO_PATH, file))
|
141 | .filter(file => fs.statSync(file).isDirectory() && file !== assetsdir);
|
142 |
|
143 | let md5 = await tarzip(
|
144 | path.join(COMBO_PATH, `business.js`),
|
145 | dirs,
|
146 | gitdir,
|
147 | androidZipname
|
148 | );
|
149 |
|
150 | console.title("提交git");
|
151 | await runCommands(`
|
152 | git add .
|
153 | git commit -m ${options.increment ? "1": "0"}:${businessName}@${version}:${md5}:${buildId}
|
154 | git push
|
155 | `, {
|
156 | cwd: gitdir
|
157 | });
|
158 | }else{
|
159 |
|
160 | }
|
161 | })()));
|
162 |
|
163 | console.title("提交git");
|
164 | await runCommands(`
|
165 | git add .
|
166 | git commit -m "publish@${version}"
|
167 | git push
|
168 | `, {
|
169 | cwd: currentDir
|
170 | });
|
171 | } |
\ | No newline at end of file |