Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Dist To Github
Browse files Browse the repository at this point in the history
  • Loading branch information
swcho committed Apr 3, 2017
1 parent 9e56eed commit f7bd40a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 12 deletions.
62 changes: 62 additions & 0 deletions dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

set -e

DIST_BRANCH='gh-pages'
DIST_OUT='out/client'

GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
if [ "$GIT_REPO_ROOT" != "$PWD" ]; then
echo "Should run this script in the repository root";
exit 1;
fi

GIT_BRANCH_NAME=$(git symbolic-ref HEAD 2>/dev/null)
if [ "$GIT_BRANCH_NAME" != "refs/heads/master" ]; then
echo "Should checkout master branch";
exit 1;
fi

if [[ -n $(git status -s) ]]; then
echo "Should be clean";
exit 1;
fi

if [[ -n $(git log origin/master..master) ]]; then
echo "Should be pushed to master";
exit 1;
fi

# Update remote commits
git remote update

# Get hash
LAST_HASH=$(git rev-parse HEAD)

echo "Commit $LAST_HASH will be distributed"

# Check out to dist branch
git checkout $DIST_BRANCH

# Rebase against master
git rebase master

# Reset to last commit
git reset --hard $LAST_HASH

# Build
npm run build

# Add built files
git add $DIST_OUT

# Commit
git commit -am "Built"

# Push
git push -f

# Back to master
git checkout master

echo "FINISHED"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"fs-extra": "^2.0.0",
"glob": "^7.1.1",
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-spawn-process": "^0.1.1",
"grunt-ts": "^6.0.0-beta.11",
"grunt-webpack": "^2.0.1",
Expand Down
Empty file added src/config.ts
Empty file.
15 changes: 10 additions & 5 deletions src/tasks/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import * as webpack from 'webpack';

module.exports = (grunt: IGrunt) => {

grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-spawn-process');

const PATH_OUT = path.join(__dirname, '../../out');
const PATH_OUT_CLIENT = path.join(PATH_OUT, 'client');
const PATH_OUT_SERVER = path.join(PATH_OUT, 'server');

const webpackConfig = require("./webpack.config");

grunt.initConfig({
clean: {
client: PATH_OUT_CLIENT,
server: PATH_OUT_SERVER,
},
webpack: {
options: webpackConfig,
build: {
Expand All @@ -29,7 +35,7 @@ module.exports = (grunt: IGrunt) => {
new webpack.optimize.UglifyJsPlugin()
)
},
"watch": {
watch: {
devtool: "sourcemap",
watch: true
}
Expand Down Expand Up @@ -70,8 +76,7 @@ module.exports = (grunt: IGrunt) => {
}
});

console.log('server path: ', path.join(__dirname, '../../out/server'));

grunt.registerTask('serve', ['ts:server', 'spawnProcess:server', 'webpack:watch']);
grunt.registerTask('default', ['webpack:build-dev', 'ts:server']);
grunt.registerTask('serve', ['clean', 'ts:server', 'spawnProcess:server', 'webpack:watch']);
grunt.registerTask('dist', ['clean:client', 'webpack:build', 'ts:server']);
grunt.registerTask('default', ['clean:client', 'webpack:build', 'ts:server']);
}
10 changes: 5 additions & 5 deletions src/tasks/plugins/client-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as webpack from 'webpack';
// const log = debug('plugin/config');

function out_html(outputOption: webpack.Output, path, html, config: Config, assets: string[]) {
console.log('out_html', config, html);
// console.log('out_html', config, html);
const $ = cheerio.load(html);
console.log('out_html', assets);
// console.log('out_html', assets);
assets
.filter(assetName => !/\.map$/.test(assetName))
.forEach(assetName => {
Expand Down Expand Up @@ -57,7 +57,7 @@ export class ClientPlugin {
const contextCompiler = this.context;
compilation.entries.forEach((entry) => {
const contextCompilation = entry.context;
console.log('\nDBG: emit', contextCompilation);
// console.log('\nDBG: emit', contextCompilation);
const pathname = contextCompilation.replace(contextCompiler, '');
const htmlPath = `${out}${pathname}/index.html`;

Expand All @@ -66,7 +66,7 @@ export class ClientPlugin {
const html: string = entry.__html__ || entryInfo && entryInfo.html;

if (config && html) {
console.log('\nDBG: compilation with html');
// console.log('\nDBG: compilation with html');
entryInfoMap[contextCompilation] = {
context: contextCompilation,
config,
Expand All @@ -80,7 +80,7 @@ export class ClientPlugin {
});

compiler.plugin('done', () => {
console.log('\nDBG: ConfigPlugin DONE')
// console.log('\nDBG: ConfigPlugin DONE')
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/tasks/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const entryInfoList = configList.map<EntryInfo>(configPath => {
const entries = entryInfoList.reduce((ret, info) => {
ret[info.chunkName] = info.entryFilePath;
return ret;
}, {})
}, {});

module.exports = {
const webpackConfig: webpack.Configuration = {
cache: true,
entry: entries,
output: {
Expand Down Expand Up @@ -157,3 +157,5 @@ module.exports = {
__filename: true
}
};

module.exports = webpackConfig;

0 comments on commit f7bd40a

Please sign in to comment.