Skip to content

Instantly share code, notes, and snippets.

@Hp93
Last active March 13, 2019 12:14
Show Gist options
  • Save Hp93/fa4c08035961ec55edc43e6658acb5e7 to your computer and use it in GitHub Desktop.
Save Hp93/fa4c08035961ec55edc43e6658acb5e7 to your computer and use it in GitHub Desktop.
// Node modules
var fs = require('fs'),
durandalBundler = require('./durandal-bundler'),
gulp = require('gulp'),
concat = require('gulp-concat'),
minifyCSS = require('gulp-minify-css'),
runSequence = require('run-sequence');
var outputFolder = './dev/dist',
destinationFolder = '../v1/dist';
gulp.task('js', function () {
return durandalBundler({
baseDir: './dev/app',
output: './dev/dist/main.js',
paths: { 'requireLib': '../Scripts/require', }, // requirejs is mandatory, path is relative to baseDir
include: ['requireLib'], // requirejs is mandatory
require: true,
// If you want parts of the site to load on demand, remove them from the 'include' list
// above, and group them into bundles here.
// Ex: [ { 'bundle-name': [ 'some/module-1', 'another/module-2' ], } ]
// This will create a new file names "bundle-name", and include module-1 and module-2 inside.
// Use folder/* to include all immediate children inside [folder]
// Use folder/** to include all files and folders inside [folder]
// Bundles will be created by the order in which they were defined
bundles: [
//===============================
{
name: 'client',
modules: [
'client/*',
'dialog/client/*',
],
},
{
name: "supplier",
modules: [
'supplier/*',
'dialog/supplier/*',
'service/supplier/*',
],
},
],
// bundles that will be loaded manually, it's bundle map will be included in it's own built file
dynamicBundles: ['client', 'supplier'],
main: 'main.js', // main js file contains requirejs config
outMain: 'main-built.js', // main built file name
outBaseDir: 'dist', // app directory where built file will be stored
minify: true,
// almond: true,
})
.pipe(gulp.dest(outputFolder));
});
gulp.task('build', ['js', 'css', 'font'], function () { });
gulp.task('clean', function () {
rmDir(outputFolder);
rmDir(destinationFolder);
console.log('Deleted old built');
});
gulp.task('default', function () {
runSequence('clean', 'build', function () {
gulp.src(outputFolder + "/**")
.pipe(gulp.dest(destinationFolder));
console.log('Copied new built to: ' + destinationFolder);
})
});
function rmDir(dirPath, removeSelf) {
try {
if (fs.existsSync(dirPath)) {
var files = fs.readdirSync(dirPath);
} else {
return;
}
}
catch (ex) {
throw ex;
}
if (files.length > 0) {
for (var i = 0; i < files.length; i++) {
var filePath = dirPath + '/' + files[i];
if (fs.statSync(filePath).isFile()) {
fs.unlinkSync(filePath);
}
else {
rmDir(filePath, true);
}
}
}
if (removeSelf) {
fs.rmdirSync(dirPath);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment