Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f2b264

Browse files
committedNov 30, 2017
PR review, changes
1 parent c99e228 commit 7f2b264

7 files changed

+40
-41
lines changed
 

‎lib/after-watch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var compiler = require('./compiler');
1+
const compiler = require('./compiler');
22
module.exports = function($logger) {
3-
var webpackProcess = compiler.getWebpackProcess();
3+
const webpackProcess = compiler.getWebpackProcess();
44
if (webpackProcess) {
55
$logger.info("Stopping webpack watch");
66
webpack.kill("SIGINT");

‎lib/before-prepareJS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function ($mobileHelper, $projectData, hookArgs) {
88
env,
99
platform,
1010
bundle: appFilesUpdaterOptions.bundle,
11-
watch: false
11+
watch: false // TODO: Read from CLI options...
1212
};
1313
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData);
1414
return result;

‎lib/compiler.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { spawn } = require("child_process");
33
const { join, resolve: pathResolve } = require("path");
44
const { existsSync } = require("fs");
55
const readline = require("readline");
6+
const { messages } = require("../plugins/WatchStateLoggerPlugin");
67

78
let hasBeenInvoked = false;
89

@@ -33,9 +34,6 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper,
3334
rejectBase();
3435
}
3536

36-
// TODO: Read from CLI options...
37-
const { watch } = true;
38-
3937
console.log(`Running webpack for ${config.platform}...`);
4038
const envFlagNames = Object.keys(config.env).concat([config.platform.toLowerCase()]);
4139

@@ -47,8 +45,8 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper,
4745
// Adding `npm i source-map-support --save-dev` in an app will make source maps work
4846
// and stack traces will point to .ts if .ts files and proper source maps exist.
4947
let sourceMapSupportArgs = [];
50-
let appSourceMapSupportInstallPath = pathResolve($projectData.projectDir, "node_modules", "source-map-support", "register.js");
51-
let devDepSourceMapSupportInstallPath = pathResolve(__dirname, "..", "node_modules", "source-map-support", "register.js");
48+
const appSourceMapSupportInstallPath = pathResolve($projectData.projectDir, "node_modules", "source-map-support", "register.js");
49+
const devDepSourceMapSupportInstallPath = pathResolve(__dirname, "..", "node_modules", "source-map-support", "register.js");
5250
if (existsSync(appSourceMapSupportInstallPath)) {
5351
sourceMapSupportArgs = ["--require", appSourceMapSupportInstallPath];
5452
} else if (existsSync(devDepSourceMapSupportInstallPath)) {
@@ -61,7 +59,7 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper,
6159
join($projectData.projectDir, "node_modules", "webpack", "bin", "webpack.js"),
6260
"--config=webpack.config.js",
6361
"--progress",
64-
... (config.watch ? ["--watch"] : []),
62+
...(config.watch ? ["--watch"] : []),
6563
...envFlagNames.map(item => `--env.${item}`),
6664
].filter(a => !!a);
6765

@@ -74,7 +72,7 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper,
7472
});
7573

7674
function resolveOnWebpackCompilationComplete(message) {
77-
if (message === "Webpack compilation complete. Watching for file changes.") {
75+
if (message === messages.compilationComplete) {
7876
console.log("Initial webpack build done!");
7977
resolve();
8078
}

‎plugins/NativeScriptAngularCompilerPlugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const appNgToolsWebpack: typeof ngToolsWebpack = require(ngToolsWebpackDir);
1111

1212
export const AngularCompilerPlugin: typeof ngToolsWebpack.AngularCompilerPlugin = appNgToolsWebpack.AngularCompilerPlugin;
1313

14-
export type NativeScriptAngularCompilerPluginOptions = ngToolsWebpack.AngularCompilerPluginOptions & { platformOptions?: PlatformFSPluginOptions };
14+
export interface NativeScriptAngularCompilerPluginOptions extends ngToolsWebpack.AngularCompilerPluginOptions {
15+
platformOptions?: PlatformFSPluginOptions;
16+
}
1517

1618
export interface CompiledFile {
1719
outputText: string;
@@ -47,7 +49,7 @@ export class NativeScriptAngularCompilerPlugin extends AngularCompilerPlugin {
4749
}
4850
};
4951
this.__compilerHost.resourceNameToFileName = function(file, relativeTo) {
50-
const parsed= path.parse(file);
52+
const parsed = path.parse(file);
5153
const platformFile = parsed.name + "." + platform + parsed.ext;
5254
let resolved;
5355
try {
@@ -63,7 +65,7 @@ export class NativeScriptAngularCompilerPlugin extends AngularCompilerPlugin {
6365
getCompiledFile(this: NativeScriptAngularCompilerPlugin, file: string): CompiledFile {
6466
try {
6567
if (this.platform) {
66-
const parsed= path.parse(file);
68+
const parsed = path.parse(file);
6769
const platformFile = parsed.dir + path.sep + parsed.name + "." + this.platform + parsed.ext;
6870
const result = super.getCompiledFile(platformFile);
6971
return result;

‎plugins/PlatformFSPlugin.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,17 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
6565
const isIgnored = file => minimatchFileFilters.some(filter => filter(file));
6666

6767
const alienPlatforms = platforms.filter(p => p !== platform);
68-
const alienPlatformFilters = alienPlatforms.map(platform => ({
69-
endsWithSuffix: `.${platform}`,
70-
contains: `.${platform}.`
71-
})).map(({endsWithSuffix, contains}) => baseFileName =>
72-
baseFileName.endsWith(endsWithSuffix) ||
73-
baseFileName.indexOf(contains) != -1);
68+
const alienPlatformFilters = alienPlatforms
69+
.map(platform => `.${platform}.`)
70+
.map(contains => baseFileName => baseFileName.indexOf(contains) !== -1);
7471

7572
const isNotAlienPlatformFile = file => !alienPlatformFilters.some(filter => filter(basename(file)));
7673

7774
const currentPlatformExt = `.${platform}`;
7875

7976
const trimPlatformSuffix = file => {
8077
const {dir, name, ext} = parseFile(file);
81-
if (ext === currentPlatformExt) {
82-
return join(dir, name);
83-
} else if (name.endsWith(currentPlatformExt)) {
78+
if (name.endsWith(currentPlatformExt)) {
8479
return join(dir, name.substr(0, name.length - currentPlatformExt.length) + ext);
8580
}
8681
return file;
@@ -99,7 +94,7 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
9994

10095
function platformSpecificFile(file: string): string {
10196
const {dir, name, ext} = parseFile(file);
102-
const platformFilePath = join(dir, name + ("." + platform) + ext);
97+
const platformFilePath = join(dir, `${name}.${platform}${ext}`);
10398
return platformFilePath;
10499
}
105100

@@ -117,7 +112,7 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
117112
* Expects array with absolute paths.
118113
* Returns array with absolute paths.
119114
*/
120-
function filterAlienFilesAndMap(files: string[]): string[] {
115+
function filterIgnoredFilesAlienFilesAndMap(files: string[]): string[] {
121116
const mappedFiles = files
122117
.filter(isNotIgnored)
123118
.filter(isNotAlienPlatformFile)
@@ -152,10 +147,10 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
152147
fileTimestamps,
153148
contextTimestamps) {
154149

155-
const mappedFilesModified = filterAlienFilesAndMap(filesModified);
150+
const mappedFilesModified = filterIgnoredFilesAlienFilesAndMap(filesModified);
156151

157152
const mappedTimestamps = {};
158-
for(var file in fileTimestamps) {
153+
for(const file in fileTimestamps) {
159154
const timestamp = fileTimestamps[file];
160155
mappedTimestamps[file] = timestamp;
161156
const platformSuffixIndex = file.lastIndexOf(platformSuffix);
@@ -173,8 +168,6 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
173168
fs.watch(mappedFiles, dirs, missing, startTime, watchOptions, callbackCalled);
174169
}
175170

176-
return mappedFS;
177-
178171
/**
179172
* For FS functions that get as first argument a file path,
180173
* this will map it to a platform specific file if such file exists or fallback to the default.
@@ -183,7 +176,7 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
183176
*/
184177
function mapPath(fName) {
185178
const base = fs[fName];
186-
mappedFS[fName] = platform ? function() {
179+
mappedFS[fName] = function() {
187180
const args = arguments;
188181
const originalFilePath = args[0];
189182
const callback = args[args.length - 1];
@@ -198,7 +191,7 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
198191
}
199192
base.apply(fs, args);
200193
});
201-
} : base;
194+
};
202195
}
203196

204197
/**
@@ -209,8 +202,8 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
209202
function filterResultingFiles(name) {
210203
const base = fs[name];
211204
mappedFS[name] = function() {
212-
const callback = arguments[arguments.length - 1];
213205
const dir = arguments[0];
206+
const callback = arguments[arguments.length - 1];
214207
if (isIgnored(dir)) {
215208
// Return empty file list for filtered directories.
216209
callback(null, []);
@@ -222,12 +215,14 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
222215
} else {
223216
// Create absolute paths for "ignored" testing, map platforms, and return back the base name.
224217
const absoluteFilePaths = files.map(file => join(dir, file));
225-
const resultAbsolute = filterAlienFilesAndMap(absoluteFilePaths);
218+
const resultAbsolute = filterIgnoredFilesAlienFilesAndMap(absoluteFilePaths);
226219
const resultFileNames = resultAbsolute.map(f => basename(f));
227220
callback(null, resultFileNames);
228221
}
229222
}
230223
base.apply(fs, arguments);
231224
}
232225
}
226+
227+
return mappedFS;
233228
}

‎plugins/WatchStateLoggerPlugin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11

2+
export enum messages {
3+
compilationComplete = "Webpack compilation complete. Watching for file changes.",
4+
changeDetected = "File change detected. Starting incremental webpack compilation..."
5+
}
6+
27
/**
38
* This little plugin will report the webpack state through the console.
49
* So the {N} CLI can get some idea when compilation completes.
510
*/
611
export class WatchStateLoggerPlugin {
712
apply(compiler) {
813
compiler.plugin("watch-run", function(compiler, callback) {
9-
console.log("File change detected. Starting incremental webpack compilation...");
10-
process.send && process.send("File change detected. Starting incremental webpack compilation...", error => null);
14+
console.log(messages.changeDetected);
15+
process.send && process.send(messages.changeDetected, error => null);
1116
callback();
1217
});
1318
compiler.plugin("after-emit", function(compilation, callback) {
1419
callback();
15-
console.log("Webpack compilation complete. Watching for file changes.");
16-
process.send && process.send("Webpack compilation complete. Watching for file changes.", error => null);
20+
console.log(messages.compilationComplete);
21+
process.send && process.send(messages.compilationComplete, error => null);
1722
});
1823
}
1924
}

‎templates/webpack.angular.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ module.exports = env => {
1515
}
1616
const platforms = ["ios", "android"];
1717
const mainSheet = "app.css";
18-
const { snapshot, uglify, report, skipCodeGeneration } = env;
19-
const ngToolsWebpackOptions = { tsConfigPath: skipCodeGeneration ? "tsconfig.json" : "tsconfig.aot.json"};
18+
const { snapshot, uglify, report, aot } = env;
19+
const ngToolsWebpackOptions = { tsConfigPath: aot ? "tsconfig.aot.json" : "tsconfig.json"};
2020

2121
const config = {
2222
context: resolve("./app"),
2323
target: nativescriptTarget,
2424
entry: {
25-
bundle: skipCodeGeneration ? "./main.ts" : "./main.aot.ts",
25+
bundle: aot ? "./main.aot.ts" : "./main.ts",
2626
vendor: "./vendor",
2727
},
2828
output: {
@@ -80,7 +80,6 @@ module.exports = env => {
8080
}),
8181
// Copy assets to out dir. Add your own globs as needed.
8282
new CopyWebpackPlugin([
83-
{ from: "css/**" },
8483
{ from: "fonts/**" },
8584
{ from: "**/*.jpg" },
8685
{ from: "**/*.png" },
@@ -97,7 +96,7 @@ module.exports = env => {
9796
new nsWebpack.NativeScriptAngularCompilerPlugin(
9897
Object.assign({
9998
entryModule: resolve(__dirname, "app/app.module#AppModule"),
100-
skipCodeGeneration,
99+
skipCodeGeneration: !aot,
101100
platformOptions: {
102101
platform,
103102
platforms,

0 commit comments

Comments
 (0)
This repository has been archived.