pixel-editor/build.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

const fs = require('fs-extra');
const hbs = require('handlebars');
const glob = require('glob');
const sass = require('sass');
const path = require('path');
const gulp = require('gulp');
const include = require('gulp-include');
const BUILDDIR = process.argv[2] || './build/';
2019-03-28 05:19:15 +03:00
const SLUG = 'pixel-editor';
2019-03-27 02:20:54 +03:00
2019-03-28 05:19:15 +03:00
console.log('Building Pixel Editor');
2019-03-27 02:20:54 +03:00
hbs.registerHelper('svg', require('handlebars-helper-svg'));
require('hbs-register-helpers')(hbs,'./_ext/modules/hbs/helpers/**/*.js');
require('hbs-register-partials')(hbs,'./_ext/modules/hbs/_*.hbs');
// empty the build folder, or create it
2019-03-27 02:20:54 +03:00
fs.emptyDirSync(BUILDDIR);
// copy images
fs.copySync('./images',path.join(BUILDDIR, SLUG));
2019-03-27 02:20:54 +03:00
// render js
2019-03-27 02:20:54 +03:00
gulp.src('./js/*.js')
.pipe(include({includePaths: [
'_ext/scripts',
'js',
'!js/_*.js',
]}))
2019-03-27 02:20:54 +03:00
.on('error', console.log)
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
2019-03-27 02:20:54 +03:00
// render css
2019-03-27 02:20:54 +03:00
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);
2019-03-27 02:20:54 +03:00
});
// compile page
var pageTemplate = hbs.compile(fs.readFileSync(path.join('./views/', SLUG + '.hbs'),{encoding: 'utf8'}));
2019-03-27 02:20:54 +03:00
var page = pageTemplate({
projectSlug: SLUG,
title: 'Lospec Pixel Editor',
layout: false,
2019-03-28 05:19:15 +03:00
});
2019-03-27 02:20:54 +03:00
// save output
fs.writeFileSync(path.join(BUILDDIR, 'index.htm'),page);