Update opn into open, make all build steps gulp based

This commit is contained in:
Theo Cavignac 2020-04-04 17:43:31 +02:00 committed by Théo (Lattay) Cavignac
parent 6f84b5dfc8
commit 24af6b38a3
4 changed files with 2028 additions and 892 deletions

View File

@ -1,57 +1,59 @@
const fs = require('fs-extra'); const fs = require('fs');
const hbs = require('handlebars');
const glob = require('glob');
const sass = require('sass');
const path = require('path'); const path = require('path');
const gulp = require('gulp'); const gulp = require('gulp');
const include = require('gulp-include'); const include = require('gulp-include');
const hb = require('gulp-hb');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const hb_svg = require('handlebars-helper-svg');
const BUILDDIR = process.argv[2] || './build/'; const BUILDDIR = process.argv[2] || './build/';
const SLUG = 'pixel-editor'; const SLUG = 'pixel-editor';
console.log('Building Pixel Editor'); console.log('Building Pixel Editor');
hbs.registerHelper('svg', require('handlebars-helper-svg'));
require('hbs-register-helpers')(hbs,'./_ext/modules/hbs/helpers/**/*.js'); function copy_images(){
require('hbs-register-partials')(hbs,'./_ext/modules/hbs/_*.hbs'); gulp.src('./images/')
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
}
function render_js(){
gulp.src('./js/*.js')
.pipe(include({includePaths: [
'_ext/scripts',
'js',
'!js/_*.js',
]}))
.on('error', console.log)
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
}
function render_css(){
gulp.src('css/*.scss')
.pipe(sass({includePaths: ['css', '_ext/sass', '_ext/modules/css']}))
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
}
function compile_page(){
gulp.src(path.join('./views/', SLUG + '.hbs'))
.pipe(hb({encoding: 'utf8'})
.partials('./_ext/modules/_*.hbs')
.helpers({ svg: hb_svg })
.helpers('./_ext/modules/hbs/helpers/**/*.js')
.data({
projectSlug: SLUG,
title: 'Lospec Pixel Editor',
layout: false,
}))
.pipe(rename('index.htm'))
.pipe(gulp.dest(BUILDDIR));
}
// empty the build folder, or create it // empty the build folder, or create it
fs.emptyDirSync(BUILDDIR); fs.rmdirSync(BUILDDIR, { recursive: true });
fs.mkdirSync(BUILDDIR);
gulp.parallel(copy_images, render_js, render_css, compile_page)();
// copy images
fs.copySync('./images',path.join(BUILDDIR, SLUG));
// render js
gulp.src('./js/*.js')
.pipe(include({includePaths: [
'_ext/scripts',
'js',
'!js/_*.js',
]}))
.on('error', console.log)
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
// render css
var sassFiles = glob.sync('css/*.scss');
sassFiles.forEach((s) => {
var f = sass.renderSync({file: s, outFile: 'test.css', includePaths: ['css', '_ext/sass', '_ext/modules/css']});
console.log('compiling:',path.basename(f.stats.entry));
fs.writeFileSync(path.join(BUILDDIR, SLUG, path.basename(f.stats.entry,'scss') + 'css'), f.css);
});
// compile page
var pageTemplate = hbs.compile(fs.readFileSync(path.join('./views/', SLUG + '.hbs'),{encoding: 'utf8'}));
var page = pageTemplate({
projectSlug: SLUG,
title: 'Lospec Pixel Editor',
layout: false,
});
// save output
fs.writeFileSync(path.join(BUILDDIR, 'index.htm'),page);

2813
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,14 +13,13 @@
"dependencies": { "dependencies": {
"express": "^4.16.4", "express": "^4.16.4",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
"glob": "^7.1.3", "gulp": "^4.0.2",
"gulp": "^4.0.0", "gulp-hb": "^8.0.0",
"gulp-include": "^2.3.1", "gulp-include": "^2.3.1",
"gulp-rename": "^2.0.0",
"gulp-sass": "^4.0.2",
"handlebars-helper-svg": "git+https://bitbucket.org/skeddles/npm-handlebars-helper-svg-lospec-open-source.git", "handlebars-helper-svg": "git+https://bitbucket.org/skeddles/npm-handlebars-helper-svg-lospec-open-source.git",
"hbs": "^4.0.3", "open": "^6.0.0",
"hbs-register-helpers": "git+https://skeddles@bitbucket.org/skeddles/hbs-register-helpers.git",
"hbs-register-partials": "git+https://skeddles@bitbucket.org/skeddles/hbs-register-partials.git",
"opn": "^6.0.0",
"sass": "^1.17.3" "sass": "^1.17.3"
} }
} }

View File

@ -29,7 +29,7 @@ var server = app.listen(PORT, () => {
console.log(`\nTemp server started at http://localhost:${PORT}!`); console.log(`\nTemp server started at http://localhost:${PORT}!`);
//console.log('press ctrl+c to stop '); //console.log('press ctrl+c to stop ');
var opn = require('opn'); var opn = require('open');
// opens the url in the default browser // opens the url in the default browser
opn(`http://localhost:${PORT}`); opn(`http://localhost:${PORT}`);