Skip to content

Commit

Permalink
build: Improved dist building
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Jan 23, 2016
1 parent a3f8131 commit 6facc0f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 31 deletions.
31 changes: 15 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,17 @@
});

/**
* Task: Generate index.html
* Task: Generate dist files
*/
grunt.registerTask('dist-index', 'Generate dist index.html', function(arg) {
grunt.log.writeln('Generating dist/index.html...');
_build.createIndex(grunt, arg, 'dist');
});

/**
* Task: Generate index.html
*/
grunt.registerTask('dist-dev-index', 'Generate dist-dev index.html', function(arg) {
grunt.log.writeln('Generating dist-dev/index.html...');
_build.createIndex(grunt, arg, 'dist-dev');
grunt.registerTask('dist-files', 'Generate dist files from template', function(arg) {
if ( arg ) {
if ( arg === 'dist' || arg === 'dist-dev' ) {
_build.createDistFiles(grunt, arg);
}
} else {
_build.createDistFiles(grunt, 'dist');
_build.createDistFiles(grunt, 'dist-dev');
}
});

/**
Expand Down Expand Up @@ -362,11 +360,12 @@
_build.createPackage(grunt, arg1, arg2);
});

grunt.registerTask('all', ['clean', 'config', 'dist-dev-index', 'dist-index', 'core', 'themes', 'packages', 'manifest']);
// DEPRECATED
grunt.registerTask('all', ['clean', 'config', 'dist-files', 'core', 'themes', 'packages', 'manifest']);
grunt.registerTask('default', ['all']);
grunt.registerTask('nw', ['config', 'dist-index', 'core:nw', 'themes', 'packages', 'manifest', 'standalone:nw', 'nwjs']);
grunt.registerTask('dist', ['config', 'dist-index', 'core', 'themes', 'packages', 'manifest']);
grunt.registerTask('dist-dev', ['config', 'dist-dev-index', 'themes:fonts', 'themes:styles', 'manifest']);
grunt.registerTask('nw', ['config', 'core:nw', 'themes', 'packages', 'manifest', 'standalone:nw', 'nwjs']);
grunt.registerTask('dist', ['config', 'dist-files:dist', 'core', 'themes', 'packages', 'manifest']);
grunt.registerTask('dist-dev', ['config', 'dist-files:dist-dev', 'themes:fonts', 'themes:styles', 'manifest']);
grunt.registerTask('test', ['jshint', 'jscs', 'csslint', 'mochaTest'/*, 'mocha'*/]);
};

Expand Down
2 changes: 1 addition & 1 deletion dist-dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</head>
<body>
<div id="LoadingScreen">
<img alt="" src="osjs-logo.png" />
<img alt="" src="splash.png" />
</div>

<div id="Login">
Expand Down
File renamed without changes
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</head>
<body>
<div id="LoadingScreen">
<img alt="" src="osjs-logo.png" />
<img alt="" src="splash.png" />
</div>

<div id="Login">
Expand Down
File renamed without changes
25 changes: 19 additions & 6 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,6 @@
tpl = replaceAll(tpl, '%HANDLER%', cfg.handler);

writeFile(_path.join(outdir, 'index.html'), tpl);
copyFile(_path.join(tpldir, 'favicon.png'), _path.join(outdir, 'favicon.png'));
copyFile(_path.join(tpldir, 'favicon.ico'), _path.join(outdir, 'favicon.ico'));
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1099,17 +1097,32 @@

grunt.log.subhead('CSS');
writeFile(PATHS.out_client_css, buildCSS());
}

grunt.log.subhead('Static files');
writeFile(PATHS.out_client_css, buildCSS());

/**
* Create static files in dist/
*/
function createDistFiles(grunt, dist) {
var cfg = generateBuildConfig(grunt);
var tpldir = _path.join(PATHS.templates, 'dist', cfg.dist.template);
var outdir = _path.join(ROOT, dist || 'dist-dev');
var stats = cfg.statics;

Object.keys(stats).forEach(function(f) {
var src = _path.join(ROOT, f);
var dst = _path.join(ROOT, stats[f]);
copyFile(src, dst);
});

var splashFile = _path.join(tpldir, 'splash.png');
if ( _fs.existsSync(splashFile) ) {
copyFile(splashFile, _path.join(outdir, 'splash.png'));
}

copyFile(_path.join(tpldir, 'favicon.png'), _path.join(outdir, 'favicon.png'));
copyFile(_path.join(tpldir, 'favicon.ico'), _path.join(outdir, 'favicon.ico'));

createIndex(grunt, null, dist);
}

/**
Expand Down Expand Up @@ -1568,7 +1581,7 @@

module.exports = {
createConfigurationFiles: createConfigurationFiles,
createIndex: createIndex,
createDistFiles: createDistFiles,
createApacheVhost: createApacheVhost,
createApacheHtaccess: createApacheHtaccess,
createLighttpdConfig: createLighttpdConfig,
Expand Down
17 changes: 11 additions & 6 deletions src/client/javascript/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,14 @@
/**
* Perform cURL call
*
* @param Object args cURL Arguments (see backend)
* @param Function callback Callback function
* fn(error, result)
* The response is in form of: {httpCode, body}
*
* @param Object args cURL Arguments (see docs)
* @param Function callback Callback function => fn(error, response)
*
* @return void
* @link http://os.js.org/doc/tutorials/using-curl.html
* @link http://os.js.org/doc/server/srcservernodenode_modulesosjsapijs.html#api-curl
* @api OSjs.API.curl()
*/
function doCurl(args, callback) {
Expand All @@ -288,13 +290,16 @@
/**
* Global function for calling API (backend)
*
* Response is in form of: {error, result}
*
* @param String m Method name
* @param Object a Method arguments
* @param Function cok Callback on success
* @param Function cerror (Optional) Callback on HTTP error
* @param Function cok Callback on success => fn(response)
* @param Function cerror (Optional) Callback on HTTP error => fn(error)
* @param Object options (Optional) Options to send to the XHR request
*
* @see OSjs.Core.Handler.callAPI()
* @see OSjs.Utils.ajax()
*
* @return void
* @api OSjs.API.call()
Expand Down Expand Up @@ -1571,7 +1576,7 @@
* Method for adding a hook
*
* @param String name Hook name
* @param Function fn Callback
* @param Function fn Callback => fn()
*
* @return void
* @api OSjs.API.addHook()
Expand Down
2 changes: 1 addition & 1 deletion src/templates/dist/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</head>
<body>
<div id="LoadingScreen">
<img alt="" src="osjs-logo.png" />
<img alt="" src="splash.png" />
</div>

<div id="Login">
Expand Down

0 comments on commit 6facc0f

Please sign in to comment.