Skip to content

Commit

Permalink
Build project through npm scripts, to avoid path issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Jul 24, 2016
1 parent 8d48ccd commit 738aff3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ env:
- MODE=browserstack_required
- MODE=saucelabs_optional
- MODE=browserstack_optional
- MODE=plunker
# - MODE=plunker

matrix:
fast_finish: true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/create-plunker-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 9 additions & 7 deletions tools/inline-resources-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down

0 comments on commit 738aff3

Please sign in to comment.