UNPKG

4 kBJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3const inquirer = require('inquirer');
4const lodash = require("lodash");
5const logger = require('./logger');
6const utils = require("./index");
7const project = require("./project");
8const expand = require("./expand");
9
10function start() {
11 let projectPath = path.resolve(process.cwd());
12 let releaseFile = path.resolve(projectPath, ".eeui.release");
13 let releaseConfig = utils.jsonParse(!fs.existsSync(releaseFile) ? {} : fs.readFileSync(releaseFile, 'utf8'));
14 //
15 let applicationid = "";
16 let questions = [{
17 type: 'input',
18 name: 'appName',
19 default: function () {
20 return releaseConfig.appName || 'eeui演示';
21 },
22 message: "请输入App名称",
23 validate: function (value) {
24 return value !== ''
25 }
26 }, {
27 type: 'input',
28 name: 'applicationID',
29 default: function () {
30 return releaseConfig.applicationID || 'app.eeui.simple';
31 },
32 message: "请输入Android应用ID",
33 validate: function (value) {
34 let pass = value.match(/^[a-z][a-z0-9_]+([.][a-z][a-z0-9_]+){2,4}$/i);
35 if (pass) {
36 applicationid = value;
37 return true;
38 }
39 return '输入格式错误,请重新输入。';
40 }
41 }, {
42 type: 'input',
43 name: 'versionCode',
44 default: function () {
45 return expand.androidGradle("versionCode") || 1;
46 },
47 message: "请输入Android应用版本号",
48 validate: function (value) {
49 if (Math.ceil(value) === Math.floor(value) && Math.ceil(value) > 0) {
50 return true;
51 }
52 return '输入格式错误,版本号应为整数。';
53 }
54 }, {
55 type: 'input',
56 name: 'versionName',
57 default: function () {
58 return expand.androidGradle("versionName") || "1.0.0";
59 },
60 message: "请输入Android应用版本名称",
61 validate: function (value) {
62 return value !== ''
63 }
64 }, {
65 type: 'input',
66 name: 'bundleIdentifier',
67 default: function () {
68 return releaseConfig.bundleIdentifier || applicationid;
69 },
70 message: "请输入iOS应用ID",
71 validate: function (value) {
72 let pass = value.match(/^[a-z][a-z0-9_]+([.][a-z][a-z0-9_]+){2,4}$/i);
73 if (pass) {
74 return true;
75 }
76 return '输入格式错误,请重新输入。';
77 }
78 }, {
79 type: 'input',
80 name: 'CFBundleVersion',
81 default: function () {
82 return expand.iosInfo("CFBundleVersion") || 1;
83 },
84 message: "请输入iOS应用版本号",
85 validate: function (value) {
86 if (Math.ceil(value) === Math.floor(value) && Math.ceil(value) > 0) {
87 return true;
88 }
89 return '输入格式错误,版本号应为整数。';
90 }
91 }, {
92 type: 'input',
93 name: 'CFBundleShortVersionString',
94 default: function () {
95 return expand.iosInfo("CFBundleShortVersionString") || "1.0.0";
96 },
97 message: "请输入iOS应用版本名称",
98 validate: function (value) {
99 return value !== ''
100 }
101 }];
102
103 inquirer.prompt(questions).then(answers => {
104
105 releaseConfig = lodash.merge(releaseConfig, answers);
106 project.initConfig(projectPath, releaseConfig);
107
108 expand.androidGradle("versionCode", answers.versionCode);
109 expand.androidGradle("versionName", answers.versionName);
110 expand.iosInfo("CFBundleVersion", answers.CFBundleVersion);
111 expand.iosInfo("CFBundleShortVersionString", answers.CFBundleShortVersionString);
112
113 logger.success(`Android设置成功`);
114 logger.success(`iOS设置成功`);
115
116 }).catch(console.error);
117}
118
119module.exports = {start};