Skip to content

Commit 8d9e6f9

Browse files
scttcperrobmadole
authored andcommitted
Use ng-packagr to bundle (FortAwesome#40)
1 parent 8f632df commit 8d9e6f9

File tree

11 files changed

+679
-904
lines changed

11 files changed

+679
-904
lines changed

package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
"name": "@fortawesome/angular-fontawesome",
33
"version": "0.1.0-8",
44
"description": "Angular Fontawesome, an Angular library",
5-
"main": "./bundles/angular-fontawesome.umd.js",
5+
"private": true,
66
"scripts": {
77
"test": "node ./tasks/test",
8+
"prebuild": "rimraf dist",
89
"build": "node ./tasks/build",
910
"g": "node ./node_modules/angular-librarian",
1011
"lint": "tslint ./src/**/*.ts",
11-
"postbuild": "rimraf build",
1212
"posttagVersion": "npm run build && npm publish dist",
13-
"prebuild": "rimraf dist out-tsc",
1413
"start": "webpack-dev-server --open --config ./webpack/webpack.dev.js",
1514
"tagVersion": "node ./tasks/tag-version"
1615
},
@@ -58,14 +57,10 @@
5857
"karma-sourcemap-loader": "^0.3.7",
5958
"karma-webpack": "^2.0.0",
6059
"node-sass": "^4.0.0",
60+
"ng-packagr": "^3.0.0-rc.5",
6161
"phantomjs-prebuilt": "^2.1.7",
6262
"raw-loader": "^0.5.1",
6363
"rimraf": "^2.5.3",
64-
"rollup": "0.52.1",
65-
"rollup-plugin-commonjs": "^8.0.2",
66-
"rollup-plugin-node-resolve": "3.0.0",
67-
"rollup-plugin-sourcemaps": "0.4.2",
68-
"rollup-plugin-uglify": "2.0.1",
6964
"sass-loader": "^6.0.0",
7065
"script-loader": "^0.7.0",
7166
"semver": "^5.0.0",
@@ -80,9 +75,6 @@
8075
"webpack-merge": "^0.14.0",
8176
"webpack-node-externals": "^1.5.4"
8277
},
83-
"module": "./@fortawesome/angular-fontawesome.es5.js",
84-
"es2015": "./@fortawesome/angular-fontawesome.js",
85-
"typings": "./angular-fontawesome.d.ts",
8678
"keywords": [
8779
"angular",
8880
"font",

src/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "../node_modules/ng-packagr/package.schema.json",
3+
"name": "@fortawesome/angular-fontawesome",
4+
"version": "0.1.0-8",
5+
"description": "Angular Fontawesome, an Angular library",
6+
"private": true,
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/FortAwesome/angular-fontawesome"
10+
},
11+
"contributors": [
12+
"Mike Wilkerson <mwilkerson@gmail.com>",
13+
"Yaroslav Admin <devoto13@gmail.com>",
14+
"Travis Chase <travis@fontawesome.com>",
15+
"Rob Madole <rob@fontawesome.com>",
16+
"Zeev Katz <zeevk6@gmail.com>"
17+
],
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/FortAwesome/angular-fontawesome/issues"
21+
},
22+
"homepage": "https://github.com/FortAwesome/angular-fontawesome",
23+
"keywords": [
24+
"angular",
25+
"font",
26+
"awesome",
27+
"fontawesome",
28+
"icon",
29+
"svg"
30+
],
31+
"peerDependencies": {
32+
"@fortawesome/fontawesome-svg-core": "^1.2.0-9",
33+
"@angular/common": "^5.0.0 || ^6.0.0",
34+
"@angular/core": "^5.0.0 || ^6.0.0"
35+
},
36+
"ngPackage": {
37+
"lib": {
38+
"entryFile": "index.ts",
39+
"flatModuleFile": "angular-fontawesome"
40+
},
41+
"dest": "../dist"
42+
}
43+
}

tasks/build.js

Lines changed: 12 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,16 @@
11
'use strict';
22

3-
const fs = require('fs-extra');
4-
const ngc = require('@angular/compiler-cli/src/main').main;
5-
const librarianUtils = require('angular-librarian/commands/utilities');
6-
const path = require('path');
7-
8-
const copyGlobs = require('./copy-globs');
9-
const copyToBuild = require('./copy-build');
10-
const inlineResources = require('./inline-resources');
11-
const rollup = require('./rollup');
12-
13-
const colorize = librarianUtils.colorize;
14-
const execute = librarianUtils.execute;
15-
const rootDir = path.resolve(__dirname, '..');
16-
const buildDir = path.resolve(rootDir, 'build');
17-
const distDir = path.resolve(rootDir, 'dist');
18-
const libName = require(path.resolve(rootDir, 'package.json')).name;
19-
const srcDir = path.resolve(rootDir, 'src');
20-
const tscDir = path.resolve(rootDir, 'out-tsc');
21-
const es5Dir = path.resolve(tscDir, 'lib-es5');
22-
const es2015Dir = path.resolve(tscDir, 'lib-es2015');
23-
24-
const runPromise = (message, fn) => {
25-
return function() {
26-
console.info(colorize.colorize(message, 'cyan'));
27-
return fn().then(complete);
28-
};
29-
};
30-
31-
const complete = (depth = 0) => {
32-
const spaces = ' '.repeat(depth);
33-
console.info(colorize.colorize(`${ spaces }> Complete`, 'green'));
34-
};
35-
const evaluateExitCode = (exitCode) => {
36-
return exitCode === 0 ? Promise.resolve() : Promise.reject();
37-
};
38-
const getAngularCompilerVersion = () => {
39-
const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
40-
const lines = execute.execute(npm, ['list', '--depth=0', '@angular/compiler']).split(/\r?\n/);
41-
const compilerLine = lines.find((line) => line.indexOf('@angular/compiler@') !== -1);
42-
let version;
43-
44-
if (compilerLine) {
45-
version = compilerLine.match(/\bangular\/compiler@[^\s]+\s?/) || [''];
46-
version = version[0].trim().replace('angular/compiler@', '');
47-
}
48-
49-
if (!version || version === '(empty)') {
50-
Promise.reject('Angular Compiler is not installed!');
51-
}
52-
53-
return version;
54-
};
55-
const compileCode = () => Promise.all([2015, 5].map((type) => {
56-
const compilerVersion = getAngularCompilerVersion();
57-
const majorCompilerVersion = +compilerVersion.split('.')[0];
58-
59-
if (majorCompilerVersion >= 5) {
60-
const exitCode = ngc(['--project', path.resolve(rootDir, `tsconfig.es${ type }.json`)]);
61-
return evaluateExitCode(exitCode);
62-
} else {
63-
ngc({ project: path.resolve(rootDir, `tsconfig.es${ type }.json`)})
64-
.then((exitCode) =>
65-
evaluateExitCode(exitCode)
66-
)
67-
}
68-
}));
69-
const copyMetadata = () =>
70-
copyGlobs(['**/*.d.ts', '**/*.metadata.json'], es2015Dir, distDir);
71-
const copyPackageFiles = () =>
72-
copyGlobs(['.npmignore', 'package.json', 'README.md'], rootDir, distDir)
73-
.then(() => {
74-
const contents = fs.readFileSync(path.resolve(distDir, 'package.json'), 'utf8');
75-
76-
return fs.writeFileSync(path.resolve(distDir, 'package.json'), contents.replace('"dependencies":', '"peerDependencies":'));
77-
});
78-
const copySource = () => copyGlobs('**/*', srcDir, buildDir);
79-
const doInlining = () => inlineResources(buildDir, 'src');
80-
const rollupBundles = () => rollup(libName, {
81-
dist: distDir,
82-
es2015: es2015Dir,
83-
es5: es5Dir,
84-
root: rootDir
85-
});
3+
const copySync = require('fs-extra').copySync;
4+
const ngPackagr = require('ng-packagr').ngPackagr;
5+
const join = require('path').join;
866

877
return Promise.resolve()
88-
.then(runPromise('Copying `src` files into `build`', copySource))
89-
.then(runPromise('Inlining resources', doInlining))
90-
.then(runPromise('Compiling code', compileCode))
91-
.then(runPromise('Copying typings + metadata to `dist`', copyMetadata))
92-
.then(runPromise('Generating bundles via rollup', rollupBundles))
93-
.then(runPromise('Copying package files to `dist`', copyPackageFiles))
94-
.catch((error) => {
95-
console.error('\x1b[31m%s\x1b[0m', '> Build failed\n');
96-
console.error(error);
97-
process.exit(1);
98-
});
8+
.then(() =>
9+
ngPackagr()
10+
.forProject(join(process.cwd(), 'src/package.json'))
11+
.build(),
12+
)
13+
.then(() => {
14+
copySync('README.md', join(process.cwd(), 'dist/README.md'));
15+
})
16+
.then(() => console.log('success'));

tasks/copy-build.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

tasks/copy-globs.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)