This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Build component libraries #198
Merged
Merged
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 a7c3277
updates for rc.0 release (#190)
Blackbaud-PatrickOFriel 189eb63
Omnibar config (#193)
314aefd
Fixed codelyzer path (#192)
Blackbaud-SteveBrush 28830ba
Ignore public directory when generating components (#187)
Blackbaud-SteveBrush 424672f
Plugin File Processor should not check directories (#186)
Blackbaud-SteveBrush 1085d54
Updated CHANGELOG.md and package.json for 1.0.0-rc.1 (#194)
7bb867e
Added basic files
Blackbaud-SteveBrush 6de9f1f
Updated template branch, bug fix for component pattern (#195)
Blackbaud-SteveBrush 3468ac0
Added travis scripts
Blackbaud-SteveBrush 650fc82
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush 9e52340
Release 1.0.0 rc.2 (#196)
Blackbaud-SteveBrush b9f8688
Remove extra s. (#197)
blackbaud-johnly 6c665c6
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush 4bf171d
Added basic spec files
Blackbaud-SteveBrush 37cf6e7
Added unit tests for cli
Blackbaud-SteveBrush 256d4b8
Fixed type error, updated SKY UX (#199)
Blackbaud-SteveBrush db62d70
Release 1.0.0 rc.3 (#200)
Blackbaud-SteveBrush 64984f1
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush 978813f
Param functionality (#201)
a7f6ac3
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush bc96df6
Removed tslint loader
Blackbaud-SteveBrush f375f52
Readded webpack test
Blackbaud-SteveBrush 4272474
Fixed `skyux test/watch` performance (#202)
Blackbaud-SteveBrush 3ed462a
Release 1.0.0-rc.4 (#207)
Blackbaud-SteveBrush 7fcfe14
Added to skyux builder (#204)
Blackbaud-SandhyaRajasabeson 5454e9a
Updated package dependencies (#208)
Blackbaud-SteveBrush 9320118
Add hash routing option for easy mode. (#206)
Blackbaud-AdamHickey 3846c64
Updates rc5 (#209)
Blackbaud-PatrickOFriel 7c58a14
Capitalize Angular. (#211)
blackbaud-johnly bde093f
Merge branch 'rc-ng4-upgrade' into lib-release
Blackbaud-SteveBrush aecf452
Renamed cli command
Blackbaud-SteveBrush fd2cab3
100% code coverage
Blackbaud-SteveBrush 839f2e0
Merge branch 'master' into lib-release
Blackbaud-SteveBrush c77c51f
Merge branch 'master' into lib-release
Blackbaud-SteveBrush 40481c8
Enforcing package main name
Blackbaud-SteveBrush 4082cb3
Factored out compiler step
Blackbaud-SteveBrush 4245e52
Fixed unit test
Blackbaud-SteveBrush 8ef39fa
Fixed unit tests
Blackbaud-SteveBrush 94c7f7c
Fixed e2e tests
Blackbaud-SteveBrush 40ccfc5
Merge branch 'master' into lib-release
Blackbaud-PaulCrowder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { | ||
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); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?