Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 3181821

Browse files
authored
fix(ns-bundle): run gradlew clean instead of platform add/remove (#153)
fixes NativeScript/android#759
1 parent 2d132de commit 3181821

File tree

9 files changed

+34
-105
lines changed

9 files changed

+34
-105
lines changed

Diff for: .npmignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
template-generator
1+
prepublish

Diff for: bin/ns-bundle

+33-35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { spawn } = require("child_process");
44
const { resolve: pathResolve } = require("path");
5+
const { existsSync } = require("fs");
56
const { getPackageJson } = require("../projectHelpers");
67

78
const PROJECT_DIR = pathResolve(__dirname, "../../../");
@@ -16,11 +17,6 @@ const tnsArgs = getTnsArgs(npmArgs).map(escape);
1617
const flags = npmArgs.filter(a => a.startsWith("--")).map(a => a.substring(2));
1718
const options = getOptions(flags);
1819

19-
let platformVersion;
20-
try {
21-
platformVersion = packageJson.nativescript[`tns-${options.platform}`].version;
22-
} catch(e) {}
23-
2420
function getTnsArgs(args) {
2521
const other = [
2622
"run",
@@ -44,24 +40,52 @@ execute(options);
4440

4541
function execute(options) {
4642
let commands = [];
43+
const platform = options.platform;
4744

4845
if (options.bundle) {
49-
commands.push(() => clearPlatform(options.platform));
50-
commands.push(() => webpack(options.platform));
46+
commands.push(() => cleanApp(platform));
47+
commands.push(() => webpack(platform));
48+
}
49+
50+
if (platform === "android") {
51+
commands.push(() => gradlewClean());
5152
}
5253

5354
// If "build-app" or "start-app" is specified,
5455
// the respective command should be run last.
5556
// Otherwise, the app should be just prepared.
5657
if (options.command) {
57-
commands.push(() => runTns(options.command, options.platform));
58+
commands.push(() => runTns(options.command, platform));
5859
} else {
59-
commands.shift(() => runTns("prepare", options.platform))
60+
commands.shift(() => runTns("prepare", platform))
6061
}
6162

6263
return commands.reduce((current, next) => current.then(next), Promise.resolve());
6364
}
6465

66+
// Clear platform/**/app folder contents
67+
function cleanApp(platform) {
68+
return new Promise((resolve, reject) => {
69+
spawnChildProcess(true, "tns", "clean-app", platform)
70+
.then(resolve)
71+
.catch(throwError)
72+
});
73+
}
74+
75+
function gradlewClean() {
76+
return new Promise((resolve, reject) => {
77+
const platformsPath = pathResolve(PROJECT_DIR, "platforms", "android")
78+
const gradlew = pathResolve(platformsPath, "gradlew");
79+
if (!existsSync(gradlew)) {
80+
resolve();
81+
}
82+
83+
spawnChildProcess(true, gradlew, "-p", platformsPath, "clean")
84+
.then(resolve)
85+
.catch(throwError);
86+
});
87+
}
88+
6589
function webpack(platform) {
6690
return new Promise(function (resolve, reject) {
6791
console.log(`Running webpack for ${platform}...`);
@@ -81,32 +105,6 @@ function webpack(platform) {
81105
});
82106
}
83107

84-
function clearPlatform(platform) {
85-
return removePlatform(platform)
86-
.then(() => addPlatform(platform));
87-
}
88-
89-
function removePlatform(platform) {
90-
return new Promise(function (resolve, reject) {
91-
console.log(`Removing platform ${platform}...`);
92-
93-
spawnChildProcess(false, "tns", "platform", "remove", platform)
94-
.then(resolve)
95-
.catch(resolve);
96-
});
97-
}
98-
99-
function addPlatform(platform) {
100-
return new Promise(function (resolve, reject) {
101-
const platformToAdd = platformVersion ? `${platform}@${platformVersion}` : platform;
102-
console.log(`Adding platform ${platformToAdd}...`);
103-
104-
spawnChildProcess(false, "tns", "platform", "add", platformToAdd)
105-
.then(resolve)
106-
.catch(resolve);
107-
});
108-
}
109-
110108
function runTns(command, platform) {
111109
return new Promise((resolve, reject) => {
112110
console.log(`Running tns ${command}...`);

Diff for: prepublish/angular/getExtensions.js.orig

-14
This file was deleted.

Diff for: prepublish/angular/imports.js.orig

-1
This file was deleted.

Diff for: prepublish/angular/plugins.js.orig

-11
This file was deleted.

Diff for: prepublish/angular/rules.js.orig

-10
This file was deleted.

Diff for: prepublish/javascript/getExtensions.js.orig

-11
This file was deleted.

Diff for: prepublish/typescript/getExtensions.js.orig

-13
This file was deleted.

Diff for: prepublish/typescript/rules.js.orig

-9
This file was deleted.

0 commit comments

Comments
 (0)