From 738aff3fbe96d61ce1a7523fff6d0499b1dec6e8 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sun, 24 Jul 2016 20:56:05 +0200 Subject: [PATCH] Build project through npm scripts, to avoid path issues. --- .travis.yml | 2 +- package.json | 1 + scripts/ci/create-plunker-bundle.js | 2 +- tools/inline-resources-tools.js | 16 +++++++++------- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9e50dedf9fb0..6afcfc0c781c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ env: - MODE=browserstack_required - MODE=saucelabs_optional - MODE=browserstack_optional - - MODE=plunker +# - MODE=plunker matrix: fast_finish: true diff --git a/package.json b/package.json index 3f68db9287b1..e85f5fa6b14a 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "ci:forbidden-identifiers": "node ./scripts/ci/forbidden-identifiers.js", "build": "ng build", + "build:production": "ng build -prod", "demo-app": "ng serve", "test": "karma start test/karma.conf.js", "tslint": "tslint -c tslint.json 'src/**/*.ts'", diff --git a/scripts/ci/create-plunker-bundle.js b/scripts/ci/create-plunker-bundle.js index c4c4121bccbc..e9d4f5727fa9 100644 --- a/scripts/ci/create-plunker-bundle.js +++ b/scripts/ci/create-plunker-bundle.js @@ -66,7 +66,7 @@ function inlineBundle() { function buildProject() { // Note: We can't use spawnSync here, because on some environments the Angular CLI // is not added to the System Paths and is only available in the locals. - let out = exec('ng build -prod', { cwd: distRoot }).toString(); + let out = exec('npm run build:production').toString(); return out.indexOf('successfully') !== -1; } diff --git a/tools/inline-resources-tools.js b/tools/inline-resources-tools.js index 43421ebcb810..5107cf33507a 100644 --- a/tools/inline-resources-tools.js +++ b/tools/inline-resources-tools.js @@ -6,19 +6,21 @@ const fs = require('fs-extra'); /** * Inline the templates for a source file. Simply search for instances of `templateUrl: ...` and * replace with `template: ...` (with the content of the file included). - * @param filePath {string|function} The path of the source file. + * @param filePath {string} The path of the source file. * @param content {string} The source file's content. * @return {string} The content with all templates inlined. */ function inlineTemplate(filePath, content) { // Transform the filePath into a function, to be able to customize the path. - if (typeof filePath !== 'function') filePath = () => filePath; + let fileRootFn = typeof filePath !== 'function' ? () => filePath : filePath; return content.replace(/templateUrl:\s*(?:'|")(.+?\.html)(?:"|')/g, function(m, templateUrl) { - const templateFile = path.join(path.dirname(filePath(templateUrl)), templateUrl); + const templateFile = path.join(path.dirname(fileRootFn(templateUrl)), templateUrl); - if (!fs.existsSync(templateFile)) return; + if (!fs.existsSync(templateFile)) { + return; + } const templateContent = fs.readFileSync(templateFile, 'utf-8'); const shortenedTemplate = templateContent @@ -33,20 +35,20 @@ function inlineTemplate(filePath, content) { /** * Inline the styles for a source file. Simply search for instances of `styleUrls: [...]` and * replace with `styles: [...]` (with the content of the file included). - * @param filePath {string|function} The path of the source file. + * @param filePath {string} The path of the source file. * @param content {string} The source file's content. * @return {string} The content with all styles inlined. */ function inlineStyle(filePath, content) { // Transform the filePath into a function, to be able to customize the path. - if (typeof filePath !== 'function') filePath = () => filePath; + let fileRootFn = typeof filePath !== 'function' ? () => filePath : filePath; return content.replace(/styleUrls:\s*(\[[\s\S]*?])/gm, function(m, styleUrls) { const urls = eval(styleUrls); let inlineStyles = urls - .map(styleUrl => path.join(path.dirname(filePath(styleUrl)), styleUrl)) + .map(styleUrl => path.join(path.dirname(fileRootFn(styleUrl)), styleUrl)) .filter(styleUrl => fs.existsSync(styleUrl)) .map(styleFile => { const styleContent = fs.readFileSync(styleFile, 'utf-8');