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

fix(ns-bundle): run gradlew clean instead of platform add/remove #153

Merged
merged 2 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
template-generator
prepublish
68 changes: 33 additions & 35 deletions bin/ns-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { spawn } = require("child_process");
const { resolve: pathResolve } = require("path");
const { existsSync } = require("fs");
const { getPackageJson } = require("../projectHelpers");

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

let platformVersion;
try {
platformVersion = packageJson.nativescript[`tns-${options.platform}`].version;
} catch(e) {}

function getTnsArgs(args) {
const other = [
"run",
Expand All @@ -44,24 +40,52 @@ execute(options);

function execute(options) {
let commands = [];
const platform = options.platform;

if (options.bundle) {
commands.push(() => clearPlatform(options.platform));
commands.push(() => webpack(options.platform));
commands.push(() => cleanApp(platform));
commands.push(() => webpack(platform));
}

if (platform === "android") {
commands.push(() => gradlewClean());
}

// If "build-app" or "start-app" is specified,
// the respective command should be run last.
// Otherwise, the app should be just prepared.
if (options.command) {
commands.push(() => runTns(options.command, options.platform));
commands.push(() => runTns(options.command, platform));
} else {
commands.shift(() => runTns("prepare", options.platform))
commands.shift(() => runTns("prepare", platform))
}

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

// Clear platform/**/app folder contents
function cleanApp(platform) {
return new Promise((resolve, reject) => {
spawnChildProcess(true, "tns", "clean-app", platform)
.then(resolve)
.catch(throwError)
});
}

function gradlewClean() {
return new Promise((resolve, reject) => {
const platformsPath = pathResolve(PROJECT_DIR, "platforms", "android")
const gradlew = pathResolve(platformsPath, "gradlew");
if (!existsSync(gradlew)) {
resolve();
}

spawnChildProcess(true, gradlew, "-p", platformsPath, "clean")
.then(resolve)
.catch(throwError);
});
}

function webpack(platform) {
return new Promise(function (resolve, reject) {
console.log(`Running webpack for ${platform}...`);
Expand All @@ -81,32 +105,6 @@ function webpack(platform) {
});
}

function clearPlatform(platform) {
return removePlatform(platform)
.then(() => addPlatform(platform));
}

function removePlatform(platform) {
return new Promise(function (resolve, reject) {
console.log(`Removing platform ${platform}...`);

spawnChildProcess(false, "tns", "platform", "remove", platform)
.then(resolve)
.catch(resolve);
});
}

function addPlatform(platform) {
return new Promise(function (resolve, reject) {
const platformToAdd = platformVersion ? `${platform}@${platformVersion}` : platform;
console.log(`Adding platform ${platformToAdd}...`);

spawnChildProcess(false, "tns", "platform", "add", platformToAdd)
.then(resolve)
.catch(resolve);
});
}

function runTns(command, platform) {
return new Promise((resolve, reject) => {
console.log(`Running tns ${command}...`);
Expand Down
14 changes: 0 additions & 14 deletions prepublish/angular/getExtensions.js.orig

This file was deleted.

1 change: 0 additions & 1 deletion prepublish/angular/imports.js.orig

This file was deleted.

11 changes: 0 additions & 11 deletions prepublish/angular/plugins.js.orig

This file was deleted.

10 changes: 0 additions & 10 deletions prepublish/angular/rules.js.orig

This file was deleted.

11 changes: 0 additions & 11 deletions prepublish/javascript/getExtensions.js.orig

This file was deleted.

13 changes: 0 additions & 13 deletions prepublish/typescript/getExtensions.js.orig

This file was deleted.

9 changes: 0 additions & 9 deletions prepublish/typescript/rules.js.orig

This file was deleted.