front/build: replace npm scripts with 1 script
This commit is contained in:
parent
797ace982f
commit
1846a1fa2c
4 changed files with 89 additions and 39 deletions
12
package.json
12
package.json
|
@ -2,22 +2,22 @@
|
|||
"name": "szurubooru",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"browserify": "browserify static/js/*.js -o public/bundle.js",
|
||||
"build:html": "cat static/html/index.htm >public/index.htm",
|
||||
"build:css": "cat static/css/*.css >public/bundle.css && cssmin public/bundle.css >public/bundle.min.css",
|
||||
"build:js": "node static/prepare_config.js && npm run browserify -o public/bundle.js && uglifyjs <public/bundle.js >public/bundle.min.js",
|
||||
"build": "npm run build:html && npm run build:js && npm run build:css",
|
||||
"build": "node scripts/build-frontend.js",
|
||||
"watch": "watch 'npm run build' static --wait=0 --ignoreDotFiles"
|
||||
},
|
||||
"dependencies": {
|
||||
"browserify": "^13.0.0",
|
||||
"camelcase-keys": "^2.1.0",
|
||||
"cssmin": "^0.4.3",
|
||||
"glob": "^7.0.3",
|
||||
"handlebars": "^4.0.5",
|
||||
"html-minifier": "^1.3.1",
|
||||
"ini": "^1.3.4",
|
||||
"merge": "^1.2.0",
|
||||
"page": "^1.7.1",
|
||||
"uglify-js": "git://github.com/mishoo/UglifyJS2.git#harmony",
|
||||
"uglify-js": "git://github.com/mishoo/UglifyJS2.git#harmony"
|
||||
},
|
||||
"devDependencies": {
|
||||
"watch": "latest"
|
||||
}
|
||||
}
|
||||
|
|
83
scripts/build-frontend.js
Normal file
83
scripts/build-frontend.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
'use strict';
|
||||
|
||||
const glob = require('glob');
|
||||
const fs = require('fs');
|
||||
|
||||
function getConfig() {
|
||||
const ini = require('ini');
|
||||
const merge = require('merge');
|
||||
const camelcaseKeys = require('camelcase-keys');
|
||||
|
||||
function parseIniFile(path) {
|
||||
let result = ini.parse(fs.readFileSync(path, 'utf-8')
|
||||
.replace(/#.+$/gm, '')
|
||||
.replace(/\s+$/gm, ''));
|
||||
Object.keys(result).map((key, _) => {
|
||||
result[key] = camelcaseKeys(result[key]);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
let config = parseIniFile('./config.ini.dist');
|
||||
|
||||
try {
|
||||
const localConfig = parseIniFile('./config.ini');
|
||||
config = merge.recursive(config, localConfig);
|
||||
} catch (e) {
|
||||
console.warn('Local config does not exist, ignoring');
|
||||
}
|
||||
|
||||
delete config.basic.secret;
|
||||
delete config.smtp;
|
||||
delete config.database;
|
||||
config.service.userRanks = config.service.userRanks.split(/,\s*/);
|
||||
config.service.tagCategories = config.service.tagCategories.split(/,\s*/);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function bundleHtml() {
|
||||
const minify = require('html-minifier').minify;
|
||||
const html = fs.readFileSync('./static/html/index.htm', 'utf-8');
|
||||
fs.writeFileSync(
|
||||
'./public/index.htm',
|
||||
minify(html, {removeComments: true, collapseWhitespace: true}));
|
||||
console.info('Bundled HTML');
|
||||
}
|
||||
|
||||
function bundleCss() {
|
||||
const minify = require('cssmin');
|
||||
glob('static/**/*.css', {}, (er, files) => {
|
||||
let css = '';
|
||||
for (const file of files) {
|
||||
css += fs.readFileSync(file);
|
||||
}
|
||||
fs.writeFileSync('./public/bundle.min.css', minify(css));
|
||||
console.info('Bundled CSS');
|
||||
});
|
||||
}
|
||||
|
||||
function bundleJs() {
|
||||
const browserify = require('browserify');
|
||||
const uglifyjs = require('uglify-js');
|
||||
glob('./static/js/**/*.js', {}, function(er, files) {
|
||||
const outputFile = fs.createWriteStream('./public/bundle.min.js');
|
||||
browserify().add(files).bundle().pipe(outputFile);
|
||||
outputFile.on('finish', function() {
|
||||
const result = uglifyjs.minify('./public/bundle.min.js');
|
||||
fs.writeFileSync('./public/bundle.min.js', result.code);
|
||||
console.info('Bundled JS');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bundleConfig(config) {
|
||||
fs.writeFileSync(
|
||||
'./static/js/.config.autogen.json', JSON.stringify(config));
|
||||
}
|
||||
|
||||
const config = getConfig();
|
||||
bundleConfig(config);
|
||||
bundleHtml();
|
||||
bundleCss();
|
||||
bundleJs();
|
|
@ -1,33 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const ini = require('ini');
|
||||
const merge = require('merge');
|
||||
const camelcaseKeys = require('camelcase-keys');
|
||||
|
||||
function parseIniFile(path) {
|
||||
let result = ini.parse(fs.readFileSync(path, 'utf-8')
|
||||
.replace(/#.+$/gm, '')
|
||||
.replace(/\s+$/gm, ''));
|
||||
Object.keys(result).map((key, _) => {
|
||||
result[key] = camelcaseKeys(result[key]);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
let config = parseIniFile('./config.ini.dist');
|
||||
|
||||
try {
|
||||
const localConfig = parseIniFile('./config.ini');
|
||||
config = merge.recursive(config, localConfig);
|
||||
} catch (e) {
|
||||
console.warn('Local config does not exist, ignoring');
|
||||
}
|
||||
|
||||
delete config.basic.secret;
|
||||
delete config.smtp;
|
||||
delete config.database;
|
||||
config.service.userRanks = config.service.userRanks.split(/,\s*/);
|
||||
config.service.tagCategories = config.service.tagCategories.split(/,\s*/);
|
||||
|
||||
fs.writeFileSync('./static/js/.config.autogen.json', JSON.stringify(config));
|
Loading…
Reference in a new issue