Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

Commit

Permalink
Auto merge of #626 - saneyuki:build, r=saneyuki
Browse files Browse the repository at this point in the history
refactor(build): clean up

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/karen-irc/karen/626)
<!-- Reviewable:end -->
  • Loading branch information
dokidokivisual committed Apr 25, 2016
2 parents e11d239 + c975c05 commit fcc9bfc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 41 deletions.
Empty file removed dist/client/.gitkeep
Empty file.
Empty file removed dist/server/.gitkeep
Empty file.
90 changes: 51 additions & 39 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const SRC_DIR = path.resolve(__dirname, './src/');
const OBJ_DIR = path.resolve(__dirname, './obj/');
const DIST_DIR = path.resolve(__dirname, './dist/');

const SRC_SERVER = path.resolve(SRC_DIR, './server');
const OBJ_CLIENT = path.resolve(OBJ_DIR, './client/');
const OBJ_SERVER = path.resolve(OBJ_DIR, './server/');

const DIST_SERVER = path.resolve(DIST_DIR, './server/');
const DIST_CLIENT = path.resolve(DIST_DIR, './client/');
Expand Down Expand Up @@ -84,48 +85,65 @@ const CWD = path.relative(__dirname, '');
* - MUST name `__taskname`.
*/

gulp.task('__uglify', ['__clean:client:js'], function () {
if (isEnableRize) {
return Promise.resolve();
}
else {
return buildLegacyLib(CLIENT_SRC_JS, DIST_CLIENT_JS, 'libs.min.js');
}
// clean up
gulp.task('__clean:client:js:obj', function () {
return del(OBJ_CLIENT);
});
gulp.task('__clean:client:js:dist', function () {
return del(DIST_CLIENT_JS);
});

gulp.task('__cp:client:js', ['__cp:client:js:rize', '__cp:client:js:classic']);
gulp.task('__cp:client:js:classic', ['__clean:client:js'], function () {
gulp.task('__clean:client:css:dist', function () {
return del(DIST_CLIENT_CSS);
});

gulp.task('__clean:server:obj', function () {
return del(OBJ_SERVER);
});
gulp.task('__clean:server:dist', function () {
return del(DIST_SERVER);
});

// make obj/
gulp.task('__cp:client:js:obj', ['__cp:client:js::obj:rize', '__cp:client:js:obj:classic']);
gulp.task('__cp:client:js:obj:classic', ['__clean:client:js:obj'], function () {
const src = ['./src/client/script/**/*.@(js|jsx)'];
const objDir = path.resolve(OBJ_DIR, './script');
const objDir = path.resolve(OBJ_CLIENT, './script');
return doCopy(src, objDir);
});
gulp.task('__cp:client:js:rize', ['__clean:client:js'], function () {
gulp.task('__cp:client:js::obj:rize', ['__clean:client:js:obj'], function () {
if (!isEnableRize) {
return Promise.resolve();
}
else {
const src = ['./src/client/rize/**/*.@(js|jsx)'];
const objDir = path.resolve(OBJ_DIR, './rize');
const objDir = path.resolve(OBJ_CLIENT, './rize');
return doCopy(src, objDir);
}
});
gulp.task('__cp:server:js:obj', ['__clean:server:obj'], function () {
const src = ['./src/server/**/*.@(js|jsx)'];
return doCopy(src, OBJ_SERVER);
});

gulp.task('__typescript', ['__clean:client:js'], function () {
gulp.task('__typescript', ['__clean:client:js:obj'], function () {
return compileTypeScript(CWD, NPM_MOD_DIR);
});

gulp.task('__browserify', ['__clean:client:js', '__cp:client:js', '__typescript'], function () {
// make dist/
gulp.task('__link:client:js', ['__clean:client:js:dist', '__cp:client:js:obj', '__typescript'], function () {
const root = isEnableRize ?
'./rize/index.js' : './script/karen.js';
const ENTRY_POINT = path.resolve(OBJ_DIR, root);
const ENTRY_POINT = path.resolve(OBJ_CLIENT, root);

return runLinkerForClient(ENTRY_POINT, DIST_CLIENT_JS, 'karen.js', isRelease);
});

gulp.task('__postcss', ['__clean:client:css'], function () {
return buildCSS('./src/client/css/style.css', DIST_CLIENT_CSS);
gulp.task('__babel:server', ['__clean:server:dist', '__cp:server:js:obj'], function () {
return compileScriptForServer(CWD, NPM_MOD_DIR, OBJ_SERVER, DIST_SERVER, isRelease);
});

// lint
gulp.task('__eslint', function () {
const src = [
'./.eslintrc.js',
Expand All @@ -135,6 +153,7 @@ gulp.task('__eslint', function () {
'./src/client/script/',
'./src/client/rize/',
'./src/server/',
'./src/server/.eslintrc.js',
'./tools/',
];
return runESLint(CWD, NPM_MOD_DIR, src);
Expand All @@ -148,38 +167,31 @@ gulp.task('__tslint', function () {
return runTSLint(CWD, NPM_MOD_DIR, SRC);
});

gulp.task('__babel:server', ['clean:server'], function () {
return compileScriptForServer(CWD, NPM_MOD_DIR, SRC_SERVER, DIST_SERVER, isRelease);
});

gulp.task('__clean:client:js', function () {
const deleter = function (dir) {
return del(path.join(dir, '**', '*.*'));
};

const obj = deleter(OBJ_DIR);
const dist = deleter(DIST_CLIENT_JS);

return Promise.all([obj, dist]);
});

gulp.task('__clean:client:css', function () {
return del(path.join(DIST_CLIENT_CSS, '**', '*.*'));
// others
gulp.task('__postcss', ['__clean:client:css:dist'], function () {
return buildCSS('./src/client/css/style.css', DIST_CLIENT_CSS);
});

gulp.task('clean:server', function () {
return del(path.join(DIST_SERVER, '**', '*.*'));
gulp.task('__uglify', ['__clean:client:js:dist'], function () {
if (isEnableRize) {
return Promise.resolve();
}
else {
return buildLegacyLib(CLIENT_SRC_JS, DIST_CLIENT_JS, 'libs.min.js');
}
});

gulp.task('__build:server', ['__babel:server']);
gulp.task('__build:client:js', ['__uglify', '__browserify']);
gulp.task('__build:client:js', ['__uglify', '__link:client:js']);
gulp.task('__build:client:css', ['__postcss']);

// public target
gulp.task('jslint', ['__eslint', '__tslint']);
gulp.task('tsc', ['__typescript']);
gulp.task('build:server', ['jslint', '__build:server']);
gulp.task('build:client', ['jslint', '__build:client:js', '__build:client:css']);
gulp.task('build', ['build:server', 'build:client']);
gulp.task('clean:client', ['__clean:client:js', '__clean:client:css']);
gulp.task('clean:server', ['__clean:server:obj', '__clean:server:dist']);
gulp.task('clean:client', ['__clean:client:js:obj', '__clean:client:js:dist', '__clean:client:css:dist']);
gulp.task('clean', ['clean:client', 'clean:server']);
gulp.task('default', ['build']);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"start": "node index",
"test": "npm run lint",
"lint": "gulp jslint",
"clean": "gulp clean",
"tsc": "gulp tsc",
"gulp": "gulp"
},
Expand Down
2 changes: 1 addition & 1 deletion src/server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*eslint quote-props: [2, "always"] */
/*eslint quote-props: [2, "always"], strict: 0 */

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitUseStrict": false,
"outDir": "./obj/",
"outDir": "./obj/client/",
"pretty": true,
"preserveConstEnums": true,
"removeComments": false,
Expand Down

0 comments on commit fcc9bfc

Please sign in to comment.