diff options
| author | Shyam Sunder <sgsunder1@gmail.com> | 2018-07-05 19:25:08 -0400 |
|---|---|---|
| committer | Marcin Kurczewski <rr-@sakuya.pl> | 2018-07-06 19:40:20 +0200 |
| commit | 60ab9246c66cba422ccd79592173a0791817e45b (patch) | |
| tree | 210552a517f2b7326b2664576f3d6d14519bdded /client/build.js | |
| parent | 3972b902d840e54bd4f8dd47a9d13bc20ee22c65 (diff) | |
client: improved build.js, use relative links
* Removed unnecessary require('config.js') calls
* 'markdown.js' now uses rel. links in EntityPermalinkWrapper
* 'password_reset.py' now generates rel. links
* Removed 'Base URL' config parameter
* Removed 'API URL' config parameter
* 'build.js' no longer reads/requires config.yaml
* Updated documentation
* Removed unnecessary node packages used in 'build.js'
abandon api_url parameter
Diffstat (limited to 'client/build.js')
| -rw-r--r-- | client/build.js | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/client/build.js b/client/build.js index c30f33f..120daa2 100644 --- a/client/build.js +++ b/client/build.js @@ -5,20 +5,6 @@ const glob = require('glob'); const path = require('path'); const util = require('util'); const execSync = require('child_process').execSync; -const camelcase = require('camelcase'); - -function convertKeysToCamelCase(input) { - let result = {}; - Object.keys(input).map((key, _) => { - const value = input[key]; - if (value !== null && value.constructor == Object) { - result[camelcase(key)] = convertKeysToCamelCase(value); - } else { - result[camelcase(key)] = value; - } - }); - return result; -} function readTextFile(path) { return fs.readFileSync(path, 'utf-8'); @@ -29,37 +15,27 @@ function writeFile(path, content) { } function getVersion() { - return execSync('git describe --always --dirty --long --tags') - .toString() - .trim(); + let build_info = process.env.BUILD_INFO; + if (build_info) { + return build_info.trim(); + } else { + try { + build_info = execSync('git describe --always --dirty --long --tags') + .toString(); + } catch (e) { + console.warn('Cannot find build version'); + return 'unknown'; + } + return build_info.trim(); + } } function getConfig() { - const yaml = require('js-yaml'); - const merge = require('merge'); - const camelcaseKeys = require('camelcase-keys'); - - function parseConfigFile(path) { - let result = yaml.load(readTextFile(path, 'utf-8')); - return convertKeysToCamelCase(result); - } - - let config = parseConfigFile('../config.yaml.dist'); - - try { - const localConfig = parseConfigFile('../config.yaml'); - config = merge.recursive(config, localConfig); - } catch (e) { - console.warn('Local config does not exist, ignoring'); - } - - config.canSendMails = !!config.smtp.host; - delete config.secret; - delete config.smtp; - delete config.database; - config.meta = { - version: getVersion(), - buildDate: new Date().toUTCString(), + let config = { + meta: { + version: getVersion(), + buildDate: new Date().toUTCString() + } }; return config; @@ -85,15 +61,11 @@ function minifyHtml(html) { }).trim(); } -function bundleHtml(config) { +function bundleHtml() { const underscore = require('underscore'); const babelify = require('babelify'); const baseHtml = readTextFile('./html/index.htm', 'utf-8'); - const finalHtml = baseHtml - .replace( - /(<title>)(.*)(<\/title>)/, - util.format('$1%s$3', config.name)); - writeFile('./public/index.htm', minifyHtml(finalHtml)); + writeFile('./public/index.htm', minifyHtml(baseHtml)); glob('./html/**/*.tpl', {}, (er, files) => { let compiledTemplateJs = '\'use strict\'\n'; @@ -143,7 +115,7 @@ function bundleCss() { }); } -function bundleJs(config) { +function bundleJs() { const browserify = require('browserify'); const external = [ 'underscore', @@ -170,7 +142,7 @@ function bundleJs(config) { for (let lib of external) { b.require(lib); } - if (config.transpile) { + if (!process.argv.includes('--no-transpile')) { b.add(require.resolve('babel-polyfill')); } writeJsBundle( @@ -179,15 +151,15 @@ function bundleJs(config) { if (!process.argv.includes('--no-app-js')) { let outputFile = fs.createWriteStream('./public/js/app.min.js'); - let b = browserify({debug: config.debug}); - if (config.transpile) { + let b = browserify({debug: process.argv.includes('--debug')}); + if (!process.argv.includes('--no-transpile')) { b = b.transform('babelify'); } writeJsBundle( b.external(external).add(files), './public/js/app.min.js', 'Bundled app JS', - !config.debug); + !process.argv.includes('--debug')); } }); } @@ -217,11 +189,11 @@ const config = getConfig(); bundleConfig(config); bundleBinaryAssets(); if (!process.argv.includes('--no-html')) { - bundleHtml(config); + bundleHtml(); } if (!process.argv.includes('--no-css')) { bundleCss(); } if (!process.argv.includes('--no-js')) { - bundleJs(config); + bundleJs(); } |