Skip to content

Commit

Permalink
Update build process to work with Angular 5 compiler-cli.
Browse files Browse the repository at this point in the history
  • Loading branch information
dschnelldavis committed Nov 10, 2017
1 parent 7422e1f commit c7b48b8
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 540 deletions.
13 changes: 5 additions & 8 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Modified from angular-quickstart-lib
// https://github.com/filipesilva/angular-quickstart-lib/blob/master/build.js

'use strict';

const fs = require('fs');
Expand Down Expand Up @@ -28,15 +31,13 @@ return Promise.resolve()
.then(() => console.log('Inlining succeeded.'))
)
// Compile to ES2015.
.then(() => ngc({ project: `${tempLibFolder}/tsconfig.json` })
.then(() => ngc(['--project', `${tempLibFolder}/tsconfig.json`]))
.then(exitCode => exitCode === 0 ? Promise.resolve() : Promise.reject())
.then(() => console.log('ES2015 compilation succeeded.'))
)
// Compile to ES5.
.then(() => ngc({ project: `${tempLibFolder}/tsconfig.es5.json` })
.then(() => ngc(['--project', `${tempLibFolder}/tsconfig.es5.json`]))
.then(exitCode => exitCode === 0 ? Promise.resolve() : Promise.reject())
.then(() => console.log('ES5 compilation succeeded.'))
)
// Copy typings and metadata to `dist/` folder.
.then(() => Promise.resolve()
.then(() => _relativeCopy('**/*.d.ts', es2015OutputFolder, distFolder))
Expand Down Expand Up @@ -133,10 +134,6 @@ return Promise.resolve()
})
});

// return rollup.rollup(fesm5config.input)
// .then(bundle => bundle.write(fesm5config.output))
// .then(() => console.log('fesm5config bundle generated successfully.'));
// console.log(umdConfig, minifiedUmdConfig, fesm5config, fesm2015config);
const allBundles = [umdConfig, minifiedUmdConfig, fesm5config, fesm2015config]
.map(cfg => rollup.rollup(cfg).then(bundle => bundle.write(cfg.output)));

Expand Down
33 changes: 16 additions & 17 deletions inline-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const writeFile = promiseify(fs.writeFile);

/**
* Inline resources in a tsc/ngc compilation.
* @param projectPath {string} Path to the project.
* @param { string } projectPath Path to the project.
*/
function inlineResources(projectPath) {

Expand All @@ -41,17 +41,15 @@ function inlineResources(projectPath) {
return path.join(path.dirname(fullFilePath), url);
}))
.then(content => writeFile(fullFilePath, content))
.catch(err => {
console.error('An error occured: ', err);
});
.catch(err => console.error('An error occured: ', err));
}));
}

/**
* Inline resources from a string content.
* @param content {string} The source file's content.
* @param urlResolver {Function} A resolver that takes a URL and return a path.
* @returns {string} The content with resources inlined.
* @param { string } content The source file's content.
* @param { Function } urlResolver A resolver that takes a URL and return a path.
* @return { string } The content with resources inlined.
*/
function inlineResourcesFromString(content, urlResolver) {
// Curry through the inlining functions.
Expand All @@ -63,11 +61,12 @@ function inlineResourcesFromString(content, urlResolver) {
}

/**
* 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 content {string} The source file's content.
* @param urlResolver {Function} A resolver that takes a URL and return a path.
* @return {string} The content with all templates inlined.
* Inline the templates for a source file.
* Search for instances of `templateUrl: ...` and replace with `template: ...`
* (with the content of the file included).
* @param { string } content The source file's content.
* @param { Function } urlResolver A resolver that takes a URL and return a path.
* @return { string } The content with all templates inlined.
*/
function inlineTemplate(content, urlResolver) {
return content.replace(/templateUrl:\s*'([^']+?\.html)'/g, function (m, templateUrl) {
Expand All @@ -83,9 +82,9 @@ function inlineTemplate(content, urlResolver) {
/**
* Inline the styles for a source file. Search for instances of `styleUrls: [...]`
* and replace with `styles: [...]` (with the content of the file included).
* @param urlResolver {Function} A resolver that takes a URL and return a path.
* @param content {string} The source file's content.
* @return {string} The content with all styles inlined.
* @param { Function } urlResolver A resolver that takes a URL and return a path.
* @param { string } content The source file's content.
* @return { string } The content with all styles inlined.
*/
function inlineStyle(content, urlResolver) {
return content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, function (m, styleUrls) {
Expand All @@ -104,8 +103,8 @@ function inlineStyle(content, urlResolver) {

/**
* Remove every mention of `moduleId: module.id`.
* @param content {string} The source file's content.
* @returns {string} The content with all moduleId: mentions removed.
* @param { string } content The source file's content.
* @return { string } The content with all moduleId: mentions removed.
*/
function removeModuleId(content) {
return content.replace(/\s*moduleId:\s*module\.id\s*,?\s*/gm, '');
Expand Down
Loading

0 comments on commit c7b48b8

Please sign in to comment.