Skip to content

Commit d3c0156

Browse files
committed
Added support to Android application bundle.
1 parent e2d0d62 commit d3c0156

6 files changed

Lines changed: 52 additions & 30 deletions

File tree

index.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ const args = require('yargs')
6363
describe: '(Android) password for key.',
6464
type: 'string'
6565
})
66+
.option('p', {
67+
alias: 'packageType',
68+
describe: 'apk (or) bundle',
69+
default: 'apk',
70+
choices: ['apk', 'bundle']
71+
})
6672
}, args => {
6773
args.platform = 'android';
6874
build(args)
@@ -106,11 +112,20 @@ const args = require('yargs')
106112
alias: 'cordovaVersion',
107113
describe: 'Cordova Version'
108114
})
109-
.option('p', {
110-
alias: 'packageType',
111-
describe: 'development (or) release',
112-
default: 'development',
113-
choices: ['development', 'production']
115+
.option('bt', {
116+
alias: 'buildType',
117+
describe: 'development (or) debug (or) production (or) release',
118+
default: 'debug',
119+
coerce: (val) => {
120+
if (val === 'development') {
121+
return 'debug';
122+
}
123+
if (val === 'production') {
124+
return 'release';
125+
}
126+
return val;
127+
},
128+
choices: ['development', 'debug', 'production', 'release']
114129
})
115130
.option('ah', {
116131
alias: 'allowHooks',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wavemaker/wm-cordova-cli",
3-
"version": "1.6.1",
3+
"version": "2.0.0",
44
"description": "command line tool to easily build a wavemaker mobile project",
55
"main": "index.js",
66
"preferGlobal": true,

src/android.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ const {
1515
} = require('./requirements');
1616
const loggerLabel = 'android-build';
1717

18-
const buildSigningFile = (path, keyStore, storePassword, keyAlias, keyPassword, buildType) => {
18+
const buildSigningFile = (path, keyStore, storePassword, keyAlias, keyPassword, buildType, packageType) => {
1919
const siginingSettings = {
2020
keystore: keyStore,
2121
storePassword: storePassword,
2222
alias: keyAlias,
23-
password: keyPassword
23+
password: keyPassword,
24+
packageType: packageType
2425
};
2526
const settings = {
2627
android : {}
@@ -39,10 +40,11 @@ module.exports = {
3940
storePassword,
4041
keyStore,
4142
cordovaAndroidVersion,
43+
buildType,
4244
packageType,
4345
androidXMigrationEnabled
4446
} = args;
45-
if (packageType === 'development' && !keyStore) {
47+
if (buildType === 'debug' && !keyStore) {
4648
keyStore = __dirname + '/../defaults/android-debug.keystore';
4749
keyAlias = 'androiddebugkey';
4850
keyPassword = 'android';
@@ -92,14 +94,14 @@ module.exports = {
9294
message: 'Prepared for cordova android'
9395
});
9496
const settingsPath = projectDir + '__build.json';
95-
const buildType = packageType === 'production' ? 'release' : 'debug';
9697
buildSigningFile(
9798
settingsPath,
9899
keyStore,
99100
storePassword,
100101
keyAlias,
101102
keyPassword,
102-
buildType
103+
buildType,
104+
packageType
103105
);
104106
await exec(cordova, [
105107
'build', 'android', '--verbose',
@@ -113,10 +115,15 @@ module.exports = {
113115
message: 'build completed'
114116
});
115117
const output = projectDir + 'output/android/';
116-
const outputFilePath = `${output}${projectInfo.displayName || projectInfo.name}(${projectInfo.version}).${packageType}.apk`;
117-
const apkPath = findFile(`${projectDir}platforms/android/app/build/outputs/apk/${packageType === 'production' ? 'release' : 'debug'}`, /\.apk?/);
118+
const outputFilePath = `${output}${projectInfo.displayName || projectInfo.name}(${projectInfo.version}).${buildType}.${packageType === 'bundle' ? 'aab': 'apk'}`;
119+
let bundlePath = null;
120+
if (packageType === 'bundle') {
121+
bundlePath = findFile(`${projectDir}platforms/android/app/build/outputs/bundle/${buildType}`, /\.aab?/);
122+
} else {
123+
bundlePath = findFile(`${projectDir}platforms/android/app/build/outputs/apk/${buildType}`, /\.apk?/);
124+
}
118125
fs.mkdirSync(output, {recursive: true});
119-
fs.copyFileSync(apkPath, outputFilePath);
126+
fs.copyFileSync(bundlePath, outputFilePath);
120127
return {
121128
success: true,
122129
output: outputFilePath

src/command.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ module.exports = {
299299
storePassword: args.aStorePassword,
300300
keyAlias: args.aKeyAlias,
301301
keyPassword: args.aKeyPassword,
302+
buildType: args.buildType,
302303
packageType: args.packageType,
303304
androidXMigrationEnabled: !args.allowHooks && args.androidXMigrationEnabled
304305
});
@@ -311,7 +312,7 @@ module.exports = {
311312
certificate: args.iCertificate,
312313
certificatePassword: args.iCertificatePassword,
313314
provisionalFile: args.iProvisioningFile,
314-
packageType: args.packageType
315+
buildType: args.buildType,
315316
});
316317
}
317318
if (result.errors && result.errors.length) {

src/ios.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,24 @@ async function getPackageType(provisionalFile) {
9494

9595
module.exports = {
9696
build: async (args) => {
97-
const {
97+
let {
9898
cordova,
9999
cordovaVersion,
100100
cordovaIosVersion,
101101
projectDir,
102102
certificate,
103103
certificatePassword,
104104
provisionalFile,
105-
packageType
105+
buildType,
106+
packageType
106107
} = args;
107108

108109
if (!await hasValidNodeVersion() || !await isGitInstalled() || !await isCocoaPodsIstalled()) {
109110
return {
110111
success: false
111112
}
112113
}
113-
const errors = validateForIos(certificate, certificatePassword, provisionalFile, packageType);
114+
const errors = validateForIos(certificate, certificatePassword, provisionalFile, buildType);
114115
if (errors.length > 0) {
115116
return {
116117
success: false,
@@ -126,8 +127,6 @@ module.exports = {
126127
label: loggerLabel,
127128
message: `provisional UUID : ${provisionuuid}`
128129
});
129-
const codeSignIdentity = packageType === 'production' ? "iPhone Distribution" : "iPhone Developer";
130-
131130
if (semver.satisfies(cordovaVersion, '8.x')) {
132131
useModernBuildSystem = 'NO';
133132
}
@@ -163,15 +162,15 @@ module.exports = {
163162
label: loggerLabel,
164163
message: 'Prepared for cordova ios'
165164
});
166-
let provisionalType = 'development';
167-
if (packageType === 'production') {
168-
provisionalType = await getPackageType(provisionalFile);
165+
packageType = packageType || 'development';
166+
if (buildType === 'release') {
167+
packageType = await getPackageType(provisionalFile);
169168
}
170169
await exec(cordova, [
171170
'build', 'ios', '--verbose', '--device',
172-
packageType === 'production' ? '--release' : '--debug',
173-
`--codeSignIdentity="${codeSignIdentity}"`,
174-
`--packageType="${provisionalType}"`,
171+
`--${buildType}`,
172+
`--codeSignIdentity="iPhone Developer"`,
173+
`--packageType="${packageType}"`,
175174
`--developmentTeam="${developmentTeamId}"`,
176175
`--provisioningProfile="${provisionuuid}"`,
177176
`--buildFlag="-UseModernBuildSystem=${useModernBuildSystem}"`,
@@ -185,7 +184,7 @@ module.exports = {
185184
message: 'build completed'
186185
});
187186
const output = projectDir + 'output/ios/';
188-
const outputFilePath = `${output}${projectInfo.displayName || projectInfo.name}(${projectInfo.version}).${packageType}.ipa`;
187+
const outputFilePath = `${output}${projectInfo.displayName || projectInfo.name}(${projectInfo.version}).${buildType}.ipa`;
189188
fs.mkdirSync(output, {recursive: true});
190189
fs.copyFileSync(findFile(projectDir + 'platforms/ios/build/device', /\.ipa?/), outputFilePath);
191190
return {

src/requirements.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ module.exports = {
159159
return errors;
160160
},
161161

162-
validateForIos: (certificate, password, provisionalFilePath, packageType) => {
162+
validateForIos: (certificate, password, provisionalFilePath, buildType) => {
163163
let errors = [];
164164
if (!(certificate && fs.existsSync(certificate))) {
165165
errors.push(`p12 certificate does not exists : ${certificate}`);
@@ -170,8 +170,8 @@ module.exports = {
170170
if (!(provisionalFilePath && fs.existsSync(provisionalFilePath))) {
171171
errors.push(`Provisional file does not exists : ${provisionalFilePath}`);
172172
}
173-
if (!packageType) {
174-
errors.push('Package type is required.');
173+
if (!buildType) {
174+
errors.push('Build type is required.');
175175
}
176176
return errors;
177177
}

0 commit comments

Comments
 (0)