Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
upgrade to angular 5
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed Dec 1, 2017
1 parent 37c863c commit 0b92400
Show file tree
Hide file tree
Showing 22 changed files with 2,844 additions and 1,227 deletions.
101 changes: 61 additions & 40 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* tslint:disable:import-blacklist */
// from https://github.com/angular/angularfire2/blob/master/tools/build.js
import { rollup } from 'rollup';
import { spawn } from 'child_process';
import { Observable } from 'rxjs';
import { copy } from 'fs-extra';
import * as copyfiles from 'copy';
import { copy } from 'fs-extra';
import { rollup } from 'rollup';
import * as filesize from 'rollup-plugin-filesize';
import * as resolve from 'rollup-plugin-node-resolve';
import * as sourcemaps from 'rollup-plugin-sourcemaps';
import { Observable } from 'rxjs';

const pkg = require(`${process.cwd()}/package.json`);

Expand All @@ -17,7 +16,7 @@ const GLOBALS = {
'@angular/common': 'ng.common',
'@angular/animations': 'ng.animations',
'@angular/platform-browser': 'ng.platformBrowser',
'rxjs': 'Rx',
rxjs: 'Rx',
'rxjs/Observable': 'Rx',
'rxjs/Subject': 'Rx',
'rxjs/Observer': 'Rx',
Expand All @@ -26,7 +25,10 @@ const GLOBALS = {

// Constants for running typescript commands
const NGC = './node_modules/.bin/ngc';
const TSC_ARGS = (config = 'build') => [`-p`, `${process.cwd()}/src/lib/tsconfig-${config}.json`];
const TSC_ARGS = (config = 'build') => [
`-p`,
`${process.cwd()}/src/lib/tsconfig-${config}.json`,
];

/**
* Create an Observable of a spawned child process.
Expand All @@ -37,25 +39,35 @@ function spawnObservable(command, args) {
return Observable.create(observer => {
const cmd = spawn(command, args);
observer.next(''); // hack to kick things off, not every command will have a stdout
cmd.stdout.on('data', (data) => { observer.next(data.toString()); });
cmd.stderr.on('data', (data) => { observer.error(data.toString()); });
cmd.on('close', (data) => { observer.complete(); });
cmd.stdout.on('data', data => {
observer.next(data.toString());
});
cmd.stderr.on('data', data => {
observer.error(data.toString());
});
cmd.on('close', data => {
observer.complete();
});
});
}

function generateBundle(input, file, globals, name, format) {
const plugins = [
resolve(),
sourcemaps(),
filesize(),
];
const plugins = [sourcemaps(), filesize()];
return rollup({
input,
external: Object.keys(globals),
file,
plugins,
onwarn(warning) {
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
return;
}
console.log(warning.message);
},
}).then(bundle => {
console.log(file);
return bundle.write({
file,
name,
Expand Down Expand Up @@ -91,12 +103,8 @@ function createEs(globals, target) {
}

function getVersions() {
const paths = [
`${process.cwd()}/dist/packages-dist/package.json`,
];
return paths
.map(path => require(path))
.map(pkgs => pkgs.version);
const paths = [`${process.cwd()}/dist/packages-dist/package.json`];
return paths.map(path => require(path)).map(pkgs => pkgs.version);
}

function verifyVersions() {
Expand All @@ -112,35 +120,48 @@ function verifyVersions() {
function buildModule(globals) {
const es2015$ = spawnObservable(NGC, TSC_ARGS());
const esm$ = spawnObservable(NGC, TSC_ARGS('esm'));
return Observable
.forkJoin(es2015$, esm$);
return Observable.forkJoin(es2015$, esm$);
}

function createBundles(globals) {
return Observable
.forkJoin(
Observable.from(createUmd(globals)),
Observable.from(createEs(globals, 'es2015')),
Observable.from(createEs(globals, 'es5')),
);
return Observable.forkJoin(
Observable.from(createUmd(globals)),
Observable.from(createEs(globals, 'es2015')),
Observable.from(createEs(globals, 'es5')),
);
}

function copyFiles() {
const copyAll: ((s: string, s1: string) => any) = Observable.bindCallback(copyfiles);
return Observable
.forkJoin(
copyAll(`${process.cwd()}/dist/es5/**/*.d.ts`, `${process.cwd()}/dist/packages-dist`),
copyAll(`${process.cwd()}/dist/es5/**/*.metadata.json`, `${process.cwd()}/dist/packages-dist`),
Observable.from(copy(`${process.cwd()}/README.md`, `${process.cwd()}/dist/packages-dist/README.md`)),
Observable.from(copy(`${process.cwd()}/src/lib/package.json`, `${process.cwd()}/dist/packages-dist/package.json`)),
);

const copyAll: ((s: string, s1: string) => any) = Observable.bindCallback(
copyfiles,
);
return Observable.forkJoin(
copyAll(
`${process.cwd()}/dist/es5/**/*.d.ts`,
`${process.cwd()}/dist/packages-dist`,
),
copyAll(
`${process.cwd()}/dist/es5/**/*.metadata.json`,
`${process.cwd()}/dist/packages-dist`,
),
Observable.from(
copy(
`${process.cwd()}/README.md`,
`${process.cwd()}/dist/packages-dist/README.md`,
),
),
Observable.from(
copy(
`${process.cwd()}/src/lib/package.json`,
`${process.cwd()}/dist/packages-dist/package.json`,
),
),
);
}

function buildLibrary(globals) {
const modules$ = buildModule(globals);
return Observable
.forkJoin(modules$)
return Observable.forkJoin(modules$)
.switchMap(() => createBundles(globals))
.switchMap(() => copyFiles())
.do(() => verifyVersions());
Expand Down
Loading

0 comments on commit 0b92400

Please sign in to comment.