Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Build component libraries #198

Merged
merged 41 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0bb6c7b
Update angular (#189)
Blackbaud-PatrickOFriel Jun 17, 2017
a7c3277
updates for rc.0 release (#190)
Blackbaud-PatrickOFriel Jun 17, 2017
189eb63
Omnibar config (#193)
Jun 20, 2017
314aefd
Fixed codelyzer path (#192)
Blackbaud-SteveBrush Jun 20, 2017
28830ba
Ignore public directory when generating components (#187)
Blackbaud-SteveBrush Jun 20, 2017
424672f
Plugin File Processor should not check directories (#186)
Blackbaud-SteveBrush Jun 20, 2017
1085d54
Updated CHANGELOG.md and package.json for 1.0.0-rc.1 (#194)
Jun 20, 2017
7bb867e
Added basic files
Blackbaud-SteveBrush Jun 20, 2017
6de9f1f
Updated template branch, bug fix for component pattern (#195)
Blackbaud-SteveBrush Jun 20, 2017
3468ac0
Added travis scripts
Blackbaud-SteveBrush Jun 21, 2017
650fc82
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush Jun 21, 2017
9e52340
Release 1.0.0 rc.2 (#196)
Blackbaud-SteveBrush Jun 21, 2017
b9f8688
Remove extra s. (#197)
blackbaud-johnly Jun 22, 2017
6c665c6
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush Jun 22, 2017
4bf171d
Added basic spec files
Blackbaud-SteveBrush Jun 22, 2017
37cf6e7
Added unit tests for cli
Blackbaud-SteveBrush Jun 22, 2017
256d4b8
Fixed type error, updated SKY UX (#199)
Blackbaud-SteveBrush Jun 23, 2017
db62d70
Release 1.0.0 rc.3 (#200)
Blackbaud-SteveBrush Jun 23, 2017
64984f1
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush Jun 27, 2017
978813f
Param functionality (#201)
Jun 27, 2017
a7f6ac3
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush Jun 27, 2017
bc96df6
Removed tslint loader
Blackbaud-SteveBrush Jun 28, 2017
f375f52
Readded webpack test
Blackbaud-SteveBrush Jun 28, 2017
4272474
Fixed `skyux test/watch` performance (#202)
Blackbaud-SteveBrush Jun 29, 2017
3ed462a
Release 1.0.0-rc.4 (#207)
Blackbaud-SteveBrush Jun 29, 2017
7fcfe14
Added to skyux builder (#204)
Blackbaud-SandhyaRajasabeson Jun 30, 2017
5454e9a
Updated package dependencies (#208)
Blackbaud-SteveBrush Jul 1, 2017
9320118
Add hash routing option for easy mode. (#206)
Blackbaud-AdamHickey Jul 3, 2017
3846c64
Updates rc5 (#209)
Blackbaud-PatrickOFriel Jul 3, 2017
7c58a14
Capitalize Angular. (#211)
blackbaud-johnly Jul 3, 2017
bde093f
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush Jul 3, 2017
aecf452
Renamed cli command
Blackbaud-SteveBrush Jul 3, 2017
fd2cab3
100% code coverage
Blackbaud-SteveBrush Jul 3, 2017
839f2e0
Merge branch 'master' into lib-release
Blackbaud-SteveBrush Jul 5, 2017
c77c51f
Merge branch 'master' into lib-release
Blackbaud-SteveBrush Jul 10, 2017
40481c8
Enforcing package main name
Blackbaud-SteveBrush Jul 10, 2017
4082cb3
Factored out compiler step
Blackbaud-SteveBrush Jul 11, 2017
4245e52
Fixed unit test
Blackbaud-SteveBrush Jul 11, 2017
8ef39fa
Fixed unit tests
Blackbaud-SteveBrush Jul 11, 2017
94c7f7c
Fixed e2e tests
Blackbaud-SteveBrush Jul 11, 2017
40ccfc5
Merge branch 'master' into lib-release
Blackbaud-PaulCrowder Jul 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions cli/build-public-library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*jshint node: true*/
'use strict';

const fs = require('fs-extra');
const logger = require('winston');
const rimraf = require('rimraf');
const webpack = require('webpack');

const stageTypeScriptFiles = require('./utils/stage-library-ts');
const preparePackage = require('./utils/prepare-library-package');
const webpackConfig = require('../config/webpack/build-public-library.webpack.config.js');
const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config');

function cleanTemp() {
rimraf.sync(skyPagesConfigUtil.spaPathTemp());
}

function cleanDist() {
rimraf.sync(skyPagesConfigUtil.spaPath('dist'));
}

function cleanAll() {
cleanTemp();
cleanDist();
}

function writeTSConfig() {
var config = {
'compilerOptions': {
'target': 'es5',
'module': 'es2015',
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'allowSyntheticDefaultImports': true,
'sourceMap': true,
'noImplicitAny': true,
'declaration': true,
'skipLibCheck': true,
'lib': [
'dom',
'es6'
],
'types': [
'jasmine',
'node'
],
'outDir': skyPagesConfigUtil.spaPath('dist'),
'rootDir': skyPagesConfigUtil.spaPathTemp()
},
'files': [
skyPagesConfigUtil.spaPathTemp('index.ts')
]
};

fs.writeJSONSync(skyPagesConfigUtil.spaPathTemp('tsconfig.json'), config);
}

function transpile(skyPagesConfig) {
const config = webpackConfig.getWebpackConfig(skyPagesConfig);
const compiler = webpack(config);

return new Promise((resolve, reject) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if https://github.com/blackbaud/skyux-builder/blob/master/cli/build.js#L133-L163 is similar enough to factor this functionality out?

compiler.run((err, stats) => {
if (err) {
logger.error(err);
reject(err);
return;
}

const jsonStats = stats.toJson();

if (jsonStats.errors.length) {
logger.error(jsonStats.errors);
}

if (jsonStats.warnings.length) {
logger.warn(jsonStats.warnings);
}

logger.info(stats.toString({
chunks: false,
colors: false
}));

resolve(stats);
});
});
}

module.exports = (skyPagesConfig) => {
cleanAll();
stageTypeScriptFiles();
writeTSConfig();

return transpile(skyPagesConfig)
.then(() => {
preparePackage();
cleanTemp();
process.exit(0);
})
.catch(() => {
cleanAll();
process.exit(1);
});
};
35 changes: 35 additions & 0 deletions cli/utils/prepare-library-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*jshint node: true*/
'use strict';

const fs = require('fs-extra');
const skyPagesConfigUtil = require('../../config/sky-pages/sky-pages.config');

function makePackageFileForDist() {
const packageJson = fs.readJSONSync(
skyPagesConfigUtil.spaPath('package.json')
);
packageJson.module = 'index.js';
packageJson.main = 'bundles/bundle.umd.js';
fs.writeJSONSync(
skyPagesConfigUtil.spaPath('dist', 'package.json'),
packageJson,
{ spaces: 2 }
);
}

function copyFilesToDist() {
fs.copySync(
skyPagesConfigUtil.spaPath('README.md'),
skyPagesConfigUtil.spaPath('dist', 'README.md')
);

fs.copySync(
skyPagesConfigUtil.spaPath('CHANGELOG.md'),
skyPagesConfigUtil.spaPath('dist', 'CHANGELOG.md')
);
}

module.exports = () => {
makePackageFileForDist();
copyFilesToDist();
};
98 changes: 98 additions & 0 deletions cli/utils/stage-library-ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*jshint node: true*/
'use strict';

const fs = require('fs-extra');
const glob = require('glob');
const path = require('path');
const sass = require('node-sass');
const skyPagesConfigUtil = require('../../config/sky-pages/sky-pages.config');
const spaPathTempSrc = skyPagesConfigUtil.spaPathTempSrc();

function copySource() {
fs.copySync(
skyPagesConfigUtil.spaPath('src', 'app', 'public'),
skyPagesConfigUtil.spaPathTemp()
);
}

function deleteNonDistFiles() {
let files = glob.sync(`${spaPathTempSrc}/**/*.spec.ts`);
files.forEach(file => fs.removeSync(file));
}

function inlineHtmlCss() {
const templateUrlRegEx = /templateUrl\:\s*'(.+?\.html)'/gi;
const styleUrlsRegEx = /styleUrls\:\s*\[\s*'(.+?\.scss)']/gi;

let files = glob.sync(`${spaPathTempSrc}/**/*.ts`);

files.forEach((file) => {
let fileContents = fs.readFileSync(file, { encoding: 'utf8' });
let dirname = path.dirname(file);
let matches;

// templateUrl
matches = templateUrlRegEx.exec(fileContents);
while (matches) {
let requireFile = path.join(dirname, matches[1]);
let requireContents = getFileContents(requireFile);
requireContents = `template: ${requireContents}`;
fileContents = fileContents.replace(matches[0], requireContents);
matches = templateUrlRegEx.exec(fileContents);

// Since we're changing the file contents in each iteration and since the regex is stateful
// we need to reset the regex; otherwise it might not be able to locate subsequent matches
// after the first replacement.
templateUrlRegEx.lastIndex = 0;
}

// styleUrls
matches = styleUrlsRegEx.exec(fileContents);
while (matches) {
let requireFile = path.join(dirname, matches[1]);
let requireContents = getFileContents(requireFile);
requireContents = `styles: [${requireContents}]`;
fileContents = fileContents.replace(matches[0], requireContents);
styleUrlsRegEx.lastIndex = 0;
matches = styleUrlsRegEx.exec(fileContents);
}

fs.writeFileSync(file, fileContents, { encoding: 'utf8' });
});
}

function getFileContents(filePath) {
let contents = '';
switch (path.extname(filePath)) {
case '.scss':
contents = compileSass(filePath);
break;
case '.html':
contents = getHtmlContents(filePath);
break;
}

contents = contents
.toString()
.replace(/\\f/g, '\\\\f')
.replace(/`/g, '\\`');

return '`' + contents + '`';
}

function getHtmlContents(filePath) {
return fs.readFileSync(filePath).toString();
}

function compileSass(filePath) {
return sass.renderSync({
file: filePath,
outputStyle: 'compressed'
}).css;
}

module.exports = () => {
copySource();
deleteNonDistFiles();
inlineHtmlCss();
};
68 changes: 68 additions & 0 deletions config/webpack/build-public-library.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*jslint node: true */
'use strict';

const webpack = require('webpack');
const ngcWebpack = require('ngc-webpack');
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
const ProcessExitCode = require('../../plugin/process-exit-code');

function getWebpackConfig(skyPagesConfig) {
const libraryName = skyPagesConfig.skyux.name || 'SkyAppLibrary';
return {
entry: skyPagesConfigUtil.spaPathTemp('index.ts'),
output: {
path: skyPagesConfigUtil.spaPath('dist', 'bundles'),
filename: 'bundle.umd.js',
libraryTarget: 'umd',
library: libraryName
},
externals: [
/^@angular\//,
/^@blackbaud\//,
/^rxjs\//
],
resolve: {
extensions: ['.js', '.ts']
},
module: {
rules: [
{
test: /\.ts$/,
use: ['awesome-typescript-loader', 'angular2-template-loader'],
exclude: [/\.(spec|e2e)\.ts$/]
},
{
test: /\.html$/,
use: 'raw-loader'
},
{
test: /\.scss$/,
use: ['raw-loader', 'sass-loader']
},
{
test: /\.css$/,
use: ['raw-loader', 'style-loader']
}
]
},
plugins: [
new ngcWebpack.NgcWebpackPlugin({
tsConfig: skyPagesConfigUtil.spaPathTemp('tsconfig.json')
}),

new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false,
compress: { warnings: false },
mangle: { screw_ie8: true, keep_fnames: true }
}),

// Webpack 2 behavior does not correctly return non-zero exit code.
new ProcessExitCode()
]
};
}

module.exports = {
getWebpackConfig: getWebpackConfig
};
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = {
case 'build':
require('./cli/build')(argv, skyPagesConfig, webpack);
break;
case 'build-public-library':
require('./cli/build-public-library')(skyPagesConfig);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably originally did it for testing, but should we pass in webpack here to stay consistent?

break;
case 'e2e':
require('./cli/e2e')(argv, skyPagesConfig, webpack);
break;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"karma-webpack": "2.0.3",
"loader-utils": "1.1.0",
"merge": "1.2.0",
"ngc-webpack": "3.0.0",
"node-sass": "4.5.3",
"open": "0.0.5",
"portfinder": "1.0.13",
Expand Down
Loading