Skip to content

Commit d652c4c

Browse files
author
Bernie Zang
committed
feat(tooling): Fix bad builds, add split package builds
1 parent 9e020c7 commit d652c4c

13 files changed

+90
-39
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/dist/**

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"version": "0.1.0",
44
"description": "The Cisco Spark for React library allows developers to easily incorporate Spark functionality into an application.",
55
"scripts": {
6-
"build": "NODE_ENV=production babel-node --presets=stage-1,es2015 scripts/build-all.js",
6+
"build": "npm run build:packages && npm run build:bundle",
7+
"build:packages": "NODE_ENV=production babel-node --presets=stage-1,es2015 scripts/build-packages.js",
78
"build:package": "NODE_ENV=production babel-node --presets=stage-1,es2015 scripts/build-package.js",
9+
"build:bundle": "NODE_ENV=production babel-node --presets=stage-1,es2015 scripts/build-bundle.js",
810
"test": "npm run static-analysis && npm run jest",
911
"jest": "jest --config=jest.config.json",
1012
"static-analysis": "npm run eslint && npm run stylelint",

scripts/build-bundle.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import buildPackage from './build-package';
2+
import path from 'path';
3+
4+
// Run buildPackage on all of our packages
5+
buildPackage(`react-ciscospark`, path.resolve(__dirname, `..`))
6+
.catch((error) => {
7+
throw new Error(error);
8+
});

scripts/build-package.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ const stat = denodeify(fs.stat);
88
/**
99
* Builds a specific package with Webpack
1010
* @param {string} pkgName
11+
* @param {string} pkgPath
1112
* @returns {undefined}
1213
*/
13-
export default function buildPackage(pkgName) {
14-
const pkgPath = path.resolve(__dirname, `..`, `packages`, `node_modules`, `@ciscospark`, pkgName);
14+
export default function buildPackage(pkgName, pkgPath) {
15+
pkgPath = pkgPath || path.resolve(__dirname, `..`, `packages`, `node_modules`, `@ciscospark`, pkgName);
1516
return stat(pkgPath)
1617
.then((statObj) => {
1718
// If the folder doesn't exist do nothing
1819
if (!statObj.isDirectory()) {
1920
return false;
2021
}
2122
console.log(`Building ${pkgName} ...`.cyan);
22-
const webpackConfigPath = path.resolve(__dirname, `webpack`, `webpack.prod.babel.js`);
23+
const webpackConfigPath = path.resolve(__dirname, `webpack`, `webpack.package.babel.js`);
2324
// Delete dist folder
2425
return exec(`rimraf ${path.resolve(pkgPath, `dist`)}`)
2526
.then(() =>
File renamed without changes.

scripts/utils/exec.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'colors';
88

99
let executionOptions = {
1010
dryRun: false,
11-
verbose: false
11+
verbose: true
1212
};
1313

1414
/**
@@ -40,13 +40,9 @@ export function exec(command, options = {}) {
4040

4141
const title = options.title || command;
4242

43-
function output(data, type) { // eslint-disable-line require-jsdoc
44-
return logWithPrefix(`[${title}] ${type}:`, data);
45-
}
46-
4743
return proc.progress(({stdout, stderr}) => {
48-
stdout.on(`data`, (data) => output(data, `stdout`));
49-
stderr.on(`data`, (data) => output(data, `stderr`));
44+
stdout.on(`data`, (data) => console.log(data));
45+
stderr.on(`data`, (data) => console.log(data));
5046
})
5147
.then((result) => {
5248
logWithPrefix(`[${title}]`, `Complete`.cyan);

scripts/webpack/webpack.base.babel.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin';
44
import InlineEnviromentVariablesPlugin from 'inline-environment-variables-webpack-plugin';
55

66
import cssnext from 'postcss-cssnext';
7+
import postcssReporter from 'postcss-reporter';
78

89
export default (options) => ({
9-
context: options.context || path.resolve(__dirname, `..`, `..`, `src`),
10+
context: options.context || path.resolve(process.cwd(), `src`),
1011
entry: options.entry,
1112
output: Object.assign({
1213
filename: `bundle.js`,
@@ -25,8 +26,8 @@ export default (options) => ({
2526
new webpack.LoaderOptionsPlugin({
2627
options: {
2728
postcss: [
28-
cssnext
29-
].concat(options.postcss)
29+
cssnext, postcssReporter
30+
]
3031
}
3132
})
3233
].concat(options.plugins),

scripts/webpack/webpack.dev.babel.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
/**
2+
* In development we assume that the code generated is going to be consumed by
3+
* webpack dev server and we are bundling into a single js file.
4+
*/
5+
16
import path from 'path';
27
import webpackConfigBase from './webpack.base.babel';
38
import HtmlWebpackPlugin from 'html-webpack-plugin';
4-
import postcssReporter from 'postcss-reporter';
59

610

711
const plugins = [
@@ -11,10 +15,9 @@ const plugins = [
1115
];
1216

1317
export default webpackConfigBase({
14-
entry: `./index.js`,
18+
entry: `./demo.js`,
1519
plugins,
1620
devtools: `cheap-module-eval-source-map`,
17-
postcss: [postcssReporter],
1821
babelInclude: [
1922
path.resolve(__dirname, `packages`, `node_modules`)
2023
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Webpack config for building individual packages for distribution
3+
*/
4+
5+
import path from 'path';
6+
import webpack from 'webpack';
7+
8+
import webpackBaseConfig from './webpack.base.babel';
9+
10+
const plugins = [
11+
// Setup uglify to compress and suppress warnings in logs
12+
new webpack.optimize.UglifyJsPlugin({
13+
sourceMap: true,
14+
compress: {
15+
warnings: false
16+
}
17+
}),
18+
// Remove locales from moment, may need to add back in future
19+
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
20+
];
21+
22+
export default webpackBaseConfig({
23+
entry: `./index.js`,
24+
output: {
25+
filename: `bundle.js`,
26+
path: path.resolve(process.cwd(), `dist`),
27+
sourceMapFilename: `[file].map`
28+
},
29+
// Full source maps for production debugging
30+
devtool: `source-map`,
31+
plugins,
32+
// Reset env values we don't want to see in bundles
33+
env: {
34+
CISCOSPARK_ACCESS_TOKEN: ``,
35+
TO_PERSON_EMAIL: ``,
36+
TO_PERSON_ID: ``
37+
}
38+
});

src/components.js

Whitespace-only changes.

0 commit comments

Comments
 (0)