Skip to content

Commit

Permalink
feat: Inline templates and CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrim committed Mar 20, 2018
1 parent 3dde557 commit a4191a2
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
dist
tmp
7 changes: 7 additions & 0 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"es2016",
"dom"
]
// For use with npm link & npm run start --preserve-symlinks
// ,
// "paths": {
// "@angular/*": [
// "../node_modules/@angular/*"
// ]
// }
}
}
10 changes: 10 additions & 0 deletions misc/inline-resources.gulp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var gulp = require('gulp');
var inlineNg2Template = require('gulp-inline-ng2-template');

gulp.task('default', function () {
var result = gulp.src('../tmp/ngx-json-view/**/*.ts')
.pipe(inlineNg2Template({ useRelativePaths: true }));

return result
.pipe(gulp.dest('../tmp/ngx-json-view'));
});
50 changes: 50 additions & 0 deletions misc/replace_scss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
var path = require('path');
var glob = require('glob');
var async = require('async');

var rootTmpDir = path.resolve(__dirname, '../tmp');

/**
* Replace SCSS styleUrls references
*/
glob(path.join(rootTmpDir, '**/*.ts'), function(err, matches) {
console.log(matches);
if (err) {
console.log(error);
return;
}

async.each(matches, function(filename, callback) {

fs.readFileAsync(path.join(filename))
.then(function(file) {
return file.toString().replace(/(?:styleUrls[\s]*:[\s]*)[\s]*\[.*(?:\.scss)+.*\]/g, function(match) {
console.log('Replaced scss reference in file %s (%s)', filename, match);
return match.replace('.scss', '.css');
})
})
.then(function(content) {
return [filename, content];
})
.spread(fs.writeFileAsync)
.then(function() {
callback();
});

}, function(err) {
// if any of the file processing produced an error, err would equal that error
if( err ) {
// One of the iterations produced an error.
// All processing will now stop.
console.log('A file failed to process');
console.log(err);
} else {
console.log('All files have been processed successfully');
}
});

});


17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"scripts": {
"ngc": "ngc",
"clean": "npm run rimraf -- dist",
"gulp": "gulp",
"inline": "npm run gulp -- --gulpfile misc/inline-resources.gulp.js",
"ngc": "ngc -p tsconfig-aot.json && npm run rimraf -- dist/node_modules",
"rimraf": "rimraf",
"sass": "npm run sass:compile && npm run sass:replace",
"sass:compile": "node-sass src -o tmp",
"sass:replace": "node misc/replace_scss.js",
"tmp": "ncp src tmp",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular -r 0",
"build": "npm run rimraf -- dist && npm run ngc -p tsconfig.json && npm run rimraf -- dist/node_modules",
"build": "npm run clean && npm run tmp && npm run sass && npm run inline && npm run ngc",
"prepublish": "npm run build"
},
"repository": {
Expand All @@ -19,6 +26,7 @@
"angular",
"angular2",
"angular4",
"angular5",
"ng",
"ng2",
"json-view",
Expand All @@ -35,7 +43,12 @@
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/core": "^4.0.0",
"bluebird": "^3.5.1",
"conventional-changelog-cli": "^1.3.1",
"gulp": "^3.9.1",
"gulp-inline-ng2-template": "^4.1.0",
"ncp": "^2.0.0",
"node-sass": "^4.7.2",
"rimraf": "^2.6.2",
"rxjs": "^5.1.0",
"typescript": "~2.2.0",
Expand Down
11 changes: 11 additions & 0 deletions tsconfig-aot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"include": [
],
"files": [
"tmp/index.ts"
],
"angularCompilerOptions": {
"annotateForClosureCompiler": true
}
}

0 comments on commit a4191a2

Please sign in to comment.