Skip to content

Commit 0034368

Browse files
committed
Shift to Storybook 3
1 parent 928b5f2 commit 0034368

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+11413
-2718
lines changed

.scripts/deployer/index.js

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
var shell = require('shelljs');
2-
var chalk = require('chalk');
3-
var publishUtils = require('./utils');
4-
var path = require('path');
5-
var packageJson = require(path.resolve('./package.json'));
6-
7-
var OUTPUT_DIR = 'out' + Math.ceil(Math.random() * 9999);
8-
9-
shell.echo(chalk.bold(`${packageJson.name}@${packageJson.version}\n`));
10-
11-
// get GIT url
12-
console.log(chalk.grey('=> Getting the git remote URL'));
13-
var GIT_URL = publishUtils.exec('git config --get remote.origin.url');
14-
if (!GIT_URL) {
15-
console.log('This project is not configured with a remote git repo');
16-
process.exit(-1);
17-
}
18-
19-
// clear and re-create the out directory
20-
shell.rm('-rf', OUTPUT_DIR);
21-
shell.mkdir(OUTPUT_DIR);
22-
23-
// run our compile script
24-
console.log(chalk.grey('=> Building storybook'));
25-
if (packageJson.scripts['build-storybook']) {
26-
publishUtils.exec('npm run build-storybook -- -o ' + OUTPUT_DIR);
27-
} else {
28-
publishUtils.exec('build-storybook -o ' + OUTPUT_DIR);
29-
}
30-
31-
// go to the out directory and create a *new* Git repo
32-
shell.cd(OUTPUT_DIR);
33-
publishUtils.exec('git init');
34-
35-
// inside this git repo we'll pretend to be a new user
36-
publishUtils.exec('git config user.name "GH Pages Bot"');
37-
publishUtils.exec('git config user.email "[email protected]"');
38-
39-
// The first and only commit to this new Git repo contains all the
40-
// files present with the commit message "Deploy to GitHub Pages".
41-
publishUtils.exec('git add .');
42-
publishUtils.exec('git commit -m "Deploy Storybook to GitHub Pages"');
43-
44-
// Force push from the current repo's master branch to the remote
45-
// repo's gh-pages branch. (All previous history on the gh-pages branch
46-
// will be lost, since we are overwriting it.) We redirect any output to
47-
// /dev/null to hide any sensitive credential data that might otherwise be exposed.
48-
console.log(chalk.grey('=> Deploying storybook'));
49-
publishUtils.exec('git push --force --quiet ' + GIT_URL + ' master:gh-pages')
50-
shell.cd('..');
51-
shell.rm('-rf', OUTPUT_DIR);
52-
53-
console.log();
54-
console.log(chalk.grey('=> Storybook deployed to: ') +
55-
chalk.cyan(publishUtils.getGHPagesUrl(GIT_URL)));
1+
var shell = require('shelljs');
2+
var chalk = require('chalk');
3+
var publishUtils = require('./utils');
4+
var path = require('path');
5+
var packageJson = require(path.resolve('./package.json'));
6+
7+
var OUTPUT_DIR = 'out' + Math.ceil(Math.random() * 9999);
8+
9+
shell.echo(chalk.bold(`${packageJson.name}@${packageJson.version}\n`));
10+
11+
// get GIT url
12+
console.log(chalk.grey('=> Getting the git remote URL'));
13+
var GIT_URL = publishUtils.exec('git config --get remote.origin.url');
14+
if (!GIT_URL) {
15+
console.log('This project is not configured with a remote git repo');
16+
process.exit(-1);
17+
}
18+
19+
// clear and re-create the out directory
20+
shell.rm('-rf', OUTPUT_DIR);
21+
shell.mkdir(OUTPUT_DIR);
22+
23+
// run our compile script
24+
console.log(chalk.grey('=> Building storybook'));
25+
if (packageJson.scripts['build-storybook']) {
26+
publishUtils.exec('npm run build-storybook -- -o ' + OUTPUT_DIR);
27+
} else {
28+
publishUtils.exec('build-storybook -o ' + OUTPUT_DIR);
29+
}
30+
31+
// go to the out directory and create a *new* Git repo
32+
shell.cd(OUTPUT_DIR);
33+
publishUtils.exec('git init');
34+
35+
// inside this git repo we'll pretend to be a new user
36+
publishUtils.exec('git config user.name "GH Pages Bot"');
37+
publishUtils.exec('git config user.email "[email protected]"');
38+
39+
// The first and only commit to this new Git repo contains all the
40+
// files present with the commit message "Deploy to GitHub Pages".
41+
publishUtils.exec('git add .');
42+
publishUtils.exec('git commit -m "Deploy Storybook to GitHub Pages"');
43+
44+
// Force push from the current repo's master branch to the remote
45+
// repo's gh-pages branch. (All previous history on the gh-pages branch
46+
// will be lost, since we are overwriting it.) We redirect any output to
47+
// /dev/null to hide any sensitive credential data that might otherwise be exposed.
48+
console.log(chalk.grey('=> Deploying storybook'));
49+
publishUtils.exec('git push --force --quiet ' + GIT_URL + ' master:gh-pages')
50+
shell.cd('..');
51+
shell.rm('-rf', OUTPUT_DIR);
52+
53+
console.log();
54+
console.log(chalk.grey('=> Storybook deployed to: ') +
55+
chalk.cyan(publishUtils.getGHPagesUrl(GIT_URL)));

.scripts/deployer/utils.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
var shell = require('shelljs');
2-
var chalk = require('chalk');
3-
var parseGitUrl = require('git-url-parse');
4-
5-
module.exports.exec = function exec(command) {
6-
shell.echo(chalk.grey(" executing: ") + command);
7-
const options = { silent: true };
8-
const ref = shell.exec(command, options);
9-
if (ref.code === 0) {
10-
return ref.stdout.trim();
11-
}
12-
13-
const message =
14-
'Exec code(' + ref.code + ') on executing: ' + command + '\n' +
15-
shell.stderr;
16-
17-
throw new Error(message);
18-
};
19-
20-
module.exports.getGHPagesUrl = function getGHPagesUrl(ghUrl) {
21-
var parsedUrl = parseGitUrl(ghUrl);
22-
var ghPagesUrl = 'https://' + parsedUrl.owner + '.github.io/' + parsedUrl.name + '/';
23-
return ghPagesUrl;
24-
};
1+
var shell = require('shelljs');
2+
var chalk = require('chalk');
3+
var parseGitUrl = require('git-url-parse');
4+
5+
module.exports.exec = function exec(command) {
6+
shell.echo(chalk.grey(" executing: ") + command);
7+
const options = { silent: true };
8+
const ref = shell.exec(command, options);
9+
if (ref.code === 0) {
10+
return ref.stdout.trim();
11+
}
12+
13+
const message =
14+
'Exec code(' + ref.code + ') on executing: ' + command + '\n' +
15+
shell.stderr;
16+
17+
throw new Error(message);
18+
};
19+
20+
module.exports.getGHPagesUrl = function getGHPagesUrl(ghUrl) {
21+
var parsedUrl = parseGitUrl(ghUrl);
22+
var ghPagesUrl = 'https://' + parsedUrl.owner + '.github.io/' + parsedUrl.name + '/';
23+
return ghPagesUrl;
24+
};

.scripts/lint.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
const path = require('path');
2-
const shell = require('shelljs');
3-
const chalk = require('chalk');
4-
5-
6-
const isJSON = process.argv.includes('-f') && process.argv.includes('json');
7-
const out = isJSON ? ['-o .scripts/lintresult.json'] : [];
8-
9-
const lint = ['node_modules', '.bin', 'eslint'].join(path.sep);
10-
const args = [
11-
'src',
12-
'--ext .jsx,.js',
13-
'--color',
14-
...process.argv.slice(2),
15-
...out,
16-
].join(' ');
17-
const cmd = `${lint} ${args}`;
18-
19-
if(isJSON) {
20-
shell.echo('\nESLint:');
21-
} else {
22-
require('./ver');
23-
}
24-
shell.echo(chalk.gray(cmd));
25-
shell.exec(cmd);
26-
27-
if(isJSON) {
28-
shell.echo('');
29-
const lintresult = require('./lintresult.json');
30-
lintresult.forEach( val => {
31-
const err = val.errorCount;
32-
const war = val.warningCount;
33-
const fpath = path.relative(process.cwd(), val.filePath);
34-
if (err || war) {
35-
shell.echo(`${chalk.grey(fpath)} ${err ? chalk.red(`errors: ${err}` + (war ? ', ' : '')) : ''}${war ? chalk.yellow(`warnings: ${war}`) : ''}`);
36-
37-
38-
}
39-
})
40-
shell.rm('.scripts/lintresult.json');
41-
}
1+
const path = require('path');
2+
const shell = require('shelljs');
3+
const chalk = require('chalk');
4+
5+
6+
const isJSON = process.argv.includes('-f') && process.argv.includes('json');
7+
const out = isJSON ? ['-o .scripts/lintresult.json'] : [];
8+
9+
const lint = ['node_modules', '.bin', 'eslint'].join(path.sep);
10+
const args = [
11+
'src',
12+
'--ext .jsx,.js',
13+
'--color',
14+
...process.argv.slice(2),
15+
...out,
16+
].join(' ');
17+
const cmd = `${lint} ${args}`;
18+
19+
if(isJSON) {
20+
shell.echo('\nESLint:');
21+
} else {
22+
require('./ver');
23+
}
24+
shell.echo(chalk.gray(cmd));
25+
shell.exec(cmd);
26+
27+
if(isJSON) {
28+
shell.echo('');
29+
const lintresult = require('./lintresult.json');
30+
lintresult.forEach( val => {
31+
const err = val.errorCount;
32+
const war = val.warningCount;
33+
const fpath = path.relative(process.cwd(), val.filePath);
34+
if (err || war) {
35+
shell.echo(`${chalk.grey(fpath)} ${err ? chalk.red(`errors: ${err}` + (war ? ', ' : '')) : ''}${war ? chalk.yellow(`warnings: ${war}`) : ''}`);
36+
37+
38+
}
39+
})
40+
shell.rm('.scripts/lintresult.json');
41+
}

.scripts/npm-postpublish.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var shell = require('shelljs');
2-
var chalk = require('chalk');
3-
const packageJson = require('../package.json');
4-
5-
shell.echo(chalk.grey(`${packageJson.name}@${packageJson.version} was successfully published.`));
1+
var shell = require('shelljs');
2+
var chalk = require('chalk');
3+
const packageJson = require('../package.json');
4+
5+
shell.echo(chalk.grey(`${packageJson.name}@${packageJson.version} was successfully published.`));

.scripts/npm-prepublish.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
var path = require('path');
2-
var shell = require('shelljs');
3-
var chalk = require('chalk');
4-
var babel = ['node_modules', '.bin', 'babel'].join(path.sep);
5-
6-
require('./ver');
7-
8-
9-
const args = '--ignore tests,stories,story.jsx,story.js src --out-dir dist';
10-
const cmd = `${babel} ${args}`;
11-
shell.echo(chalk.gray(cmd));
12-
shell.rm('-rf', 'dist');
13-
14-
shell.echo('');
15-
shell.echo(chalk.gray('Transpiling \'src\' into ES5 ...'));
16-
shell.exec(cmd);
17-
shell.echo(chalk.gray('Transpiling completed.'));
18-
shell.echo('');
1+
var path = require('path');
2+
var shell = require('shelljs');
3+
var chalk = require('chalk');
4+
var babel = ['node_modules', '.bin', 'babel'].join(path.sep);
5+
6+
require('./ver');
7+
8+
9+
const args = '--ignore tests,stories,story.jsx,story.js src --out-dir dist';
10+
const cmd = `${babel} ${args}`;
11+
shell.echo(chalk.gray(cmd));
12+
shell.rm('-rf', 'dist');
13+
14+
shell.echo('');
15+
shell.echo(chalk.gray('Transpiling \'src\' into ES5 ...'));
16+
shell.exec(cmd);
17+
shell.echo(chalk.gray('Transpiling completed.'));
18+
shell.echo('');

.scripts/npm-status.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
var path = require('path');
2-
var shell = require('shelljs');
3-
var chalk = require('chalk');
4-
var semver = require('semver');
5-
var dateFormat = require('dateformat');
6-
const packageJson = require('../package.json');
7-
8-
const ref = shell.exec('npm view --json', { silent: true });
9-
if (ref.code === 0) {
10-
const data = JSON.parse(ref.stdout);
11-
const lastVersion = data.version;
12-
const lastName = data.name;
13-
const lastPublish = data.time[lastVersion];
14-
const maintainers = data.maintainers.reduce((str, val) => `${str}, ${val}` );
15-
16-
if (lastVersion === packageJson.version) {
17-
shell.echo(chalk.bold(`\n${packageJson.name}@${packageJson.version}`));
18-
shell.echo(chalk.grey('was published to NPM at ' + dateFormat(lastPublish, 'dd-mmm-yyyy, HH:MM')));
19-
20-
} else {
21-
const diff = semver.diff(lastVersion, packageJson.version);
22-
const verColor = diff.match(/major/) ? 'red' : diff.match(/minor/) ? 'yellow' : 'bold';
23-
24-
shell.echo(chalk.grey('\nthe current version: ') + chalk.white(`${packageJson.name}`) + chalk[verColor](`@${packageJson.version}`));
25-
shell.echo(chalk.grey('the latest published version: ') + chalk.white(`${lastName}@${lastVersion}`));
26-
shell.echo(
27-
chalk.grey('was published to NPM at ') +
28-
chalk.white(dateFormat(lastPublish, 'dd-mmm-yyyy, HH:MM')) +
29-
chalk.grey(` by ${maintainers}`)
30-
);
31-
}
32-
} else {
33-
if ( ref.stderr.match('npm ERR! code E404')) {
34-
shell.echo(chalk.bold(`\n${packageJson.name}@${packageJson.version}`));
35-
shell.echo(chalk.grey('wasn\'t published to NPM yet'));
36-
} else {
37-
console.log(ref.stderr);
38-
}
39-
}
1+
var path = require('path');
2+
var shell = require('shelljs');
3+
var chalk = require('chalk');
4+
var semver = require('semver');
5+
var dateFormat = require('dateformat');
6+
const packageJson = require('../package.json');
7+
8+
const ref = shell.exec('npm view --json', { silent: true });
9+
if (ref.code === 0) {
10+
const data = JSON.parse(ref.stdout);
11+
const lastVersion = data.version;
12+
const lastName = data.name;
13+
const lastPublish = data.time[lastVersion];
14+
const maintainers = data.maintainers.reduce((str, val) => `${str}, ${val}` );
15+
16+
if (lastVersion === packageJson.version) {
17+
shell.echo(chalk.bold(`\n${packageJson.name}@${packageJson.version}`));
18+
shell.echo(chalk.grey('was published to NPM at ' + dateFormat(lastPublish, 'dd-mmm-yyyy, HH:MM')));
19+
20+
} else {
21+
const diff = semver.diff(lastVersion, packageJson.version);
22+
const verColor = diff.match(/major/) ? 'red' : diff.match(/minor/) ? 'yellow' : 'bold';
23+
24+
shell.echo(chalk.grey('\nthe current version: ') + chalk.white(`${packageJson.name}`) + chalk[verColor](`@${packageJson.version}`));
25+
shell.echo(chalk.grey('the latest published version: ') + chalk.white(`${lastName}@${lastVersion}`));
26+
shell.echo(
27+
chalk.grey('was published to NPM at ') +
28+
chalk.white(dateFormat(lastPublish, 'dd-mmm-yyyy, HH:MM')) +
29+
chalk.grey(` by ${maintainers}`)
30+
);
31+
}
32+
} else {
33+
if ( ref.stderr.match('npm ERR! code E404')) {
34+
shell.echo(chalk.bold(`\n${packageJson.name}@${packageJson.version}`));
35+
shell.echo(chalk.grey('wasn\'t published to NPM yet'));
36+
} else {
37+
console.log(ref.stderr);
38+
}
39+
}

0 commit comments

Comments
 (0)