Skip to content

Commit

Permalink
Add build server
Browse files Browse the repository at this point in the history
  • Loading branch information
aputinski committed Jun 6, 2016
1 parent 16204f5 commit c9f624b
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.tmp
/.dist
/.npm
/.build
/.logs
/.generated
/.www
/scripts/deploy
Expand Down
23 changes: 23 additions & 0 deletions .logs/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

> [email protected] test-unit /Users/adam.putinski/Development/github/design-system-internal
> mocha --compilers js:babel-register --require scripts/helpers/setup.js --reporter min 'test/unit/**/*.js' "--color"


36 passing (241ms)


> [email protected] test-integration /Users/adam.putinski/Development/github/design-system-internal
> mocha --compilers js:babel-register --require scripts/helpers/setup.js --reporter min 'test/integration/**/*.js' "--color"


2 passing (430ms)


> [email protected] test-browser /Users/adam.putinski/Development/github/design-system-internal
> karma start "--color"

ERROR LOG: 'Warning: ReactDOMComponent: Do not access .props of a DOM node; instead, recreate the props as `render` did originally or read the DOM properties/attributes directly from this node (e.g., this.refs.box.className). This DOM node was rendered by `BreadCrumbs`.'

Chrome 50.0.2661 (Mac OS X 10.11.5): Executed 3247 of 3247 SUCCESS (0.888 secs / 0.236 secs)
TOTAL: 3247 SUCCESS

3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ install:
- bundle install --path vendor/bundle
- npm install
script:
- npm run lint
- npm run test
- npm run build-travis
after_success:
- export SHA=`git rev-parse --short HEAD`
- if [ -n $TRAVIS_PULL_REQUEST ] ; then curl https://$VISUALTEST_USERNAME:[email protected]/ci/$SHA ; fi
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ gulp.task('clean', del.bind(null, [
__PATHS__.www,
__PATHS__.generated,
__PATHS__.tmp,
__PATHS__.dist
__PATHS__.dist,
__PATHS__.logs
]));

gulp.task('serve', () => {
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@
},
"scripts": {
"postinstall": "babel-node scripts/npm/postinstall.js",
"pretest": "npm run gulp -- build:test",
"test": "npm run test-unit && npm run test-browser && npm run test-integration",
"test": "babel-node scripts/npm/test.js",
"test-unit": "mocha --compilers js:babel-register --require scripts/helpers/setup.js --reporter min 'test/unit/**/*.js'",
"test-browser": "karma start",
"test-integration": "mocha --compilers js:babel-register --require scripts/helpers/setup.js --reporter min 'test/integration/**/*.js'",
"start": "npm run gulp",
"build": "npm run gulp -- build",
"build-prod": "npm run gulp -- build",
"build-server": "babel-node scripts/npm/build-server.js",
"build-travis": "babel-node scripts/npm/build-travis.js",
"dist": "babel-node scripts/dist.js",
"dist-npm": "babel-node scripts/dist.js --npm",
"lint": "npm run gulp -- lint",
"install-ruby-dependencies": "babel-node scripts/install-ruby-dependencies.js",
"gulp": "gulp"
},
"dependencies": {
"@salesforce-ux/design-tokens": "git+ssh://[email protected]:salesforce-ux/design-tokens-internal.git#v2.0.5",
"@salesforce-ux/build-server-api": "1.3.4",
"@salesforce-ux/design-tokens": "2.0.5",
"@salesforce-ux/icons": "3.4.0",
"app-module-path": "1.0.5",
"async": "1.5.2",
Expand Down Expand Up @@ -115,13 +117,16 @@
},
"devDependencies": {
"chai": "3.5.0",
"cssstats": "^3.0.0-beta.1",
"karma": "0.13.21",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "0.2.2",
"karma-mocha": "0.2.2",
"karma-spec-reporter": "0.0.24",
"karma-webpack": "1.7.0",
"mkdirp": "^0.5.1",
"mocha": "2.4.5",
"sinon": "1.17.3"
"sinon": "1.17.3",
"strip-ansi": "^3.0.1"
}
}
77 changes: 77 additions & 0 deletions scripts/gulp/generate-examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import fs from 'fs';
import gulp from 'gulp';
import gutil from 'gulp-util';
import path from 'path';
import through from 'through2';
import beautify from 'js-beautify';
import { renderToStaticMarkup } from 'react-dom/server';

import { resolve } from 'path';
import { assign, flatMap } from 'lodash';
import { generateUI } from './generate-ui';

const prettyHTML = html => beautify.html(html, {
'indent_size': 2,
'indent_char': ' ',
'unformatted': ['a'],
'wrap_line_length ': 78,
'indent_inner_html': true
});

const toStates = (ex, k) =>
[{ id: k, element: ex[k] }];

const getStates = file =>
file.preview ? toStates(file, 'preview')
: file.default ? toStates(file, 'default')
: file.states;

const requireExample = flavor =>
require(resolve(__PATHS__.ui, flavor.examplePath));

export const addExamples = comps =>
comps.map(c => assign(c, {
flavors: c.flavors
.filter(f => f.examplePath)
.map(f => assign(f, { examples: getStates(requireExample(f)) }))
})
);

export const getComponents = schema =>
flatMap(generateUI(schema), 'components');

const getName = (component, flavor, example) =>
`${component.id}_${flavor.id}_${example.id}`;

const flattenExamples = comps =>
flatMap(comps, comp =>
flatMap(comp.flavors, flavor =>
flatMap(flavor.examples, ex =>
assign(ex, { uid: getName(comp, flavor, ex) }))));

const toHtml = el =>
prettyHTML(renderToStaticMarkup(el));

gulp.task('generate:examples', ['generate:whitelist'], () => {
const stream = through.obj();
const examples = flattenExamples(addExamples(getComponents()));
examples.forEach(ex =>
stream.write(new gutil.File({
path: `${ex.uid}.html`,
contents: new Buffer(toHtml(ex.element))
})));
stream.end();
return stream
.pipe(gulp.dest(resolve(__PATHS__.generated, 'examples')));
});
4 changes: 2 additions & 2 deletions scripts/gulp/generate-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const addExamplePath = scheme =>
});
});

export const generateUI = () => {
const scheme = Scheme({ path: __PATHS__.ui }).generate();
export const generateUI = (scheme) => {
scheme = scheme || Scheme({ path: __PATHS__.ui }).generate();
addStatus(scheme);
addExamplePath(scheme);
return scheme;
Expand Down
2 changes: 2 additions & 0 deletions scripts/gulp/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import './generate-release-notes';
import './generate-tokens-zip';
import './generate-tokens';
import './generate-ui';
import './generate-examples';
import './generate-whitelist';

gulp.task('generate', [
Expand All @@ -24,6 +25,7 @@ gulp.task('generate', [
'generate:tokens:zip',
'generate:tokens',
'generate:ui',
'generate:examples',
'generate:whitelist',
'generate:whitelist-utilities'
]);
4 changes: 3 additions & 1 deletion scripts/helpers/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const paths = {

dist: path.resolve(root, '.dist'),
npm: path.resolve(root, '.npm'),
build: path.resolve(root, '.build'),
generated: path.resolve(root, '.generated'),
tmp: path.resolve(root, '.tmp'),
test: path.resolve(root, '.test'),
www: path.resolve(root, '.www')
www: path.resolve(root, '.www'),
logs: path.resolve(root, '.logs')
};

export default {
Expand Down
138 changes: 138 additions & 0 deletions scripts/helpers/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import './setup';
import _ from 'lodash';
import async from 'async';
import cssstats from 'cssstats';
import { exec } from 'child_process';
import fs from 'fs';
import gulp from 'gulp';
import gulpzip from 'gulp-zip';
import path from 'path';
import buildServerApi from '@salesforce-ux/build-server-api';

const { publish } = buildServerApi(process.env.BUILD_SERVER_HOST_NEW);

const packageJSON = require('../../package.json');

const CSS_PATH = 'assets/styles/salesforce-lightning-design-system.css';

const paths = {
build: path.resolve.bind(path, __PATHS__.build),
buildDist: path.resolve.bind(path, __PATHS__.build, 'dist')
};

const execute = (cmd, done) =>
exec(cmd, { cwd: __PATHS__.root, stdio: 'inherit' }, (err, out, stderr) => {
if (err) return done(err);
done(null, out.trim());
});

const getDependencies = (done) => {
const deps = _.assign({},
packageJSON.devDependencies, packageJSON.dependencies);
done(null, _.keys(deps)
.filter(k => k.match(/@salesforce/i))
.reduce((acc, k) =>
_.assign(acc, { [k.split('/')[1]]: deps[k] }), {}));
};

const formatStats = stats => ({
kbSize: stats.size,
gzipSize: stats.gzipSize,
ruleCount: stats.rules.total,
selectorCount: stats.selectors.total,
declarationCount: stats.declarations.total
});

const formatTestCounts = out => {
const matches = out.match(/(\d+)\s+(SUCCESS|passing)/ig);
if (!matches) return {};
return {
unitTests: parseInt(matches[0]),
integrationTests: parseInt(matches[1]),
allyTests: parseInt(matches[2])
};
};

const zip = (src, done) =>
gulp.src(paths.build(`${src}/**/*`))
.pipe(gulpzip(`${src}.zip`))
.on('error', done)
.pipe(gulp.dest(paths.build()))
.on('error', done)
.on('finish', done);

const prepare = (done) => {
console.log('[BUILD:PREPARE]');
return async.series([
// clean
(done) => async.series([
async.apply(execute, `rm -rf ${__PATHS__.build}`),
async.apply(execute, `mkdir ${__PATHS__.build}`)
], done),
// dist
(done) => async.series([
async.apply(execute, 'npm run dist-npm'),
async.apply(execute, `cp -a ${__PATHS__.npm}/. ${__PATHS__.build}/dist`),
async.apply(execute, `rm -rf ${__PATHS__.build}/dist/*.zip`)
], done),
// examples
async.apply(execute, `cp -a ${__PATHS__.generated}/examples/. ${__PATHS__.build}/examples`),
// website
async.apply(execute, `cp -a ${__PATHS__.www}/. ${__PATHS__.build}/www`),
// git info
async.apply(execute, 'git show --format="%an|%ae|%ad|%s" | head -n 1'),
// stats
(done) => async.series([
(done) => {
let counts = fs.readFileSync(`${__PATHS__.logs}/test.txt`, 'utf-8') || '';
done(null, formatTestCounts(counts));
},
(done) => {
let css = fs.readFileSync(paths.buildDist(CSS_PATH), 'utf8');
let stats = cssstats(css);
done(null, formatStats(stats));
}
], (err, [counts, tests]) => {
if (err) return done(err);
done(null, _.assign({}, counts, tests));
}),
// SHA
async.apply(execute, 'git rev-parse HEAD'),
// Dependencies
getDependencies,
// zip
async.apply(zip, 'dist'),
async.apply(zip, 'examples'),
async.apply(zip, 'www')
], (err, [_prepare, _dist, _examples, _website, info, stats, sha, dependencies, _zip]) => {
if (err) return done(err);
let result = _.assign({}, { sha, info, stats, dependencies }, {
tag: process.env.TRAVIS_TAG || '',
pullRequest: process.env.TRAVIS_PULL_REQUEST || '',
branch: process.env.TRAVIS_BRANCH || '',
version: packageJSON.version
});
done(null, result);
});
};

module.exports = (done) => prepare((err, result) => {
if (err) return done(err);
publish({
result,
zips: ['dist.zip', 'examples.zip', 'www.zip']
.map((p) => paths.build(p)),
project: 'design-system'
}, done);
});
17 changes: 17 additions & 0 deletions scripts/npm/build-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import publish from '../helpers/publish';

if (process.env.BUILD_SERVER_HOST_NEW) {
publish((err, res) => {
if (err) throw err;
console.log('Successfully published build', res);
});
}
Loading

0 comments on commit c9f624b

Please sign in to comment.