mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-26 00:51:24 +08:00
Found the round npm module to get rollup working in gulp
This commit is contained in:
parent
90ee39b114
commit
8b1a7f39df
11 changed files with 72 additions and 143 deletions
|
@ -6,8 +6,6 @@ const { assets } = require('./tasks/assets');
|
|||
const { js, jsLint } = require('./tasks/js');
|
||||
const { css, cssLint } = require('./tasks/css');
|
||||
const { vendors } = require('./tasks/vendors');
|
||||
const { watchCss } = require('./tasks/watch');
|
||||
const { snappymail } = require('./tasks/snappymail');
|
||||
|
||||
const clean = gulp.series(cleanStatic);
|
||||
|
||||
|
@ -22,8 +20,3 @@ exports.css = css;
|
|||
exports.lint = lint;
|
||||
exports.build = build;
|
||||
exports.default = build;
|
||||
|
||||
exports.watchCss = watchCss;
|
||||
|
||||
exports.snappymail = gulp.series(build, snappymail);
|
||||
exports.all = gulp.series(exports.snappymail);
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
"gulp": "4.0.2",
|
||||
"gulp-autoprefixer": "7.0.1",
|
||||
"gulp-cached": "1.1.1",
|
||||
"gulp-chmod": "3.0.0",
|
||||
"gulp-clean-css": "4.3.0",
|
||||
"gulp-concat-util": "0.5.5",
|
||||
"gulp-eol": "0.2.0",
|
||||
|
@ -69,12 +68,12 @@
|
|||
"gulp-stripbom": "1.0.5",
|
||||
"gulp-terser": "^1.4.0",
|
||||
"gulp-util": "3.0.8",
|
||||
"gulp-zip": "5.0.1",
|
||||
"node-fs": "0.1.7",
|
||||
"openpgp": "2.6.2",
|
||||
"rimraf": "3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"gulp-rollup-2": "^1.2.1",
|
||||
"rollup": "^2.38.0",
|
||||
"rollup-plugin-babel": "^4.4.0",
|
||||
"rollup-plugin-external-globals": "^0.6.1",
|
||||
|
|
|
@ -30,10 +30,12 @@ if ($return_var) {
|
|||
exit("gulp failed with error code {$return_var}\n");
|
||||
}
|
||||
|
||||
/*
|
||||
passthru("{$rollup} -c", $return_var);
|
||||
if ($return_var) {
|
||||
exit("rollup failed with error code {$return_var}\n");
|
||||
}
|
||||
*/
|
||||
|
||||
$cmddir = escapeshellcmd(__DIR__) . '/snappymail/v/0.0.0/static';
|
||||
|
||||
|
|
|
@ -91,5 +91,5 @@ export default [{
|
|||
html({
|
||||
include: '**/*.html'
|
||||
})
|
||||
],
|
||||
]
|
||||
}];
|
||||
|
|
|
@ -12,12 +12,6 @@ exports.copy = (sFile, sNewFile, done) => {
|
|||
done();
|
||||
};
|
||||
|
||||
exports.zip = (srcDir, destDir, fileName) =>
|
||||
gulp
|
||||
.src(srcDir + '**/*')
|
||||
.pipe(require('gulp-zip')(fileName))
|
||||
.pipe(gulp.dest(destDir));
|
||||
|
||||
exports.getHead = () => config.head.agpl;
|
||||
|
||||
exports.cleanStatic = () => exports.del(config.paths.static);
|
||||
|
|
|
@ -7,12 +7,9 @@ const config = {
|
|||
agpl: '/* SnappyMail Webmail (c) SnappyMail | Licensed under AGPL v3 */'
|
||||
},
|
||||
devVersion: '0.0.0',
|
||||
releasesPath: 'build/dist/releases',
|
||||
|
||||
destPath: '',
|
||||
cleanPath: '',
|
||||
zipSrcPath: '',
|
||||
zipFile: '',
|
||||
|
||||
paths: {}
|
||||
};
|
||||
|
|
38
tasks/css.js
38
tasks/css.js
|
@ -51,30 +51,6 @@ const cssMainBuild = () => {
|
|||
.pipe(livereload());
|
||||
};
|
||||
|
||||
const cssAdminBuild = () => {
|
||||
const autoprefixer = require('gulp-autoprefixer'),
|
||||
less = require('gulp-less'),
|
||||
lessFilter = filter('**/*.less', { restore: true }),
|
||||
src = config.paths.less.admin.src;
|
||||
|
||||
return gulp
|
||||
.src(src)
|
||||
.pipe(expect.real({ errorOnFailure: true }, src))
|
||||
.pipe(lessFilter)
|
||||
.pipe(
|
||||
less({
|
||||
'paths': config.paths.less.main.options.paths
|
||||
})
|
||||
)
|
||||
.pipe(lessFilter.restore)
|
||||
.pipe(concat(config.paths.css.admin.name))
|
||||
.pipe(autoprefixer())
|
||||
.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
|
||||
.pipe(eol('\n', true))
|
||||
.pipe(gulp.dest(config.paths.staticCSS))
|
||||
.pipe(livereload());
|
||||
};
|
||||
|
||||
const cssBootMin = () => {
|
||||
const cleanCss = require('gulp-clean-css');
|
||||
return gulp
|
||||
|
@ -95,18 +71,8 @@ const cssMainMin = () => {
|
|||
.pipe(gulp.dest(config.paths.staticCSS));
|
||||
};
|
||||
|
||||
const cssAdminMin = () => {
|
||||
const cleanCss = require('gulp-clean-css');
|
||||
return gulp
|
||||
.src(config.paths.staticCSS + config.paths.css.admin.name)
|
||||
.pipe(cleanCss())
|
||||
.pipe(rename({ suffix: '.min' }))
|
||||
.pipe(eol('\n', true))
|
||||
.pipe(gulp.dest(config.paths.staticCSS));
|
||||
};
|
||||
|
||||
const cssBuild = gulp.parallel(cssBootBuild, cssMainBuild/*, cssAdminBuild*/);
|
||||
const cssMin = gulp.parallel(cssBootMin, cssMainMin, cssAdminMin);
|
||||
const cssBuild = gulp.parallel(cssBootBuild, cssMainBuild);
|
||||
const cssMin = gulp.parallel(cssBootMin, cssMainMin);
|
||||
|
||||
const cssLint = (done) => done();
|
||||
|
||||
|
|
18
tasks/js.js
18
tasks/js.js
|
@ -16,7 +16,7 @@ const concat = require('gulp-concat-util'),
|
|||
const { config } = require('./config');
|
||||
const { del, getHead } = require('./common');
|
||||
|
||||
//const { rollupJS } = require('./rollup');
|
||||
const { rollupJS } = require('./rollup');
|
||||
|
||||
const jsClean = () => del(config.paths.staticJS + '/**/*.{js,map}');
|
||||
|
||||
|
@ -61,17 +61,17 @@ const jsLibs = () => {
|
|||
};
|
||||
|
||||
// app
|
||||
const jsApp = () =>
|
||||
gulp
|
||||
.src(config.paths.staticJS + config.paths.js.app.name)
|
||||
const jsApp = async () =>
|
||||
(await rollupJS(config.paths.js.app.name))
|
||||
// .pipe(sourcemaps.write('.'))
|
||||
.pipe(header(getHead() + '\n'))
|
||||
.pipe(eol('\n', true))
|
||||
.pipe(gulp.dest(config.paths.staticJS))
|
||||
.on('error', gutil.log);
|
||||
|
||||
const jsAdmin = () =>
|
||||
gulp
|
||||
.src(config.paths.staticJS + config.paths.js.admin.name)
|
||||
const jsAdmin = async () =>
|
||||
(await rollupJS(config.paths.js.admin.name))
|
||||
// .pipe(sourcemaps.write('.'))
|
||||
.pipe(header(getHead() + '\n'))
|
||||
.pipe(eol('\n', true))
|
||||
.pipe(gulp.dest(config.paths.staticJS))
|
||||
|
@ -128,8 +128,8 @@ const jsLint = () =>
|
|||
.pipe(eslint.failAfterError());
|
||||
|
||||
const jsState1 = gulp.series(jsLint);
|
||||
const jsState3 = gulp.parallel(jsBoot, jsServiceWorker, jsOpenPGP, jsOpenPGPWorker, jsLibs/*, jsApp, jsAdmin*/);
|
||||
const jsState2 = gulp.series(jsClean/*, rollupJS('app.js'), rollupJS('admin.js')*/, jsState3, jsMin);
|
||||
const jsState3 = gulp.parallel(jsBoot, jsServiceWorker, jsOpenPGP, jsOpenPGPWorker, jsLibs, jsApp, jsAdmin);
|
||||
const jsState2 = gulp.series(jsClean, jsState3, jsMin);
|
||||
|
||||
exports.jsLint = jsLint;
|
||||
exports.js = gulp.parallel(jsState1, jsState2);
|
||||
|
|
57
tasks/rollup.js
Normal file
57
tasks/rollup.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* SnappyMail Webmail (c) SnappyMail Team | Licensed under AGPL 3 */
|
||||
const rollup2 = require('gulp-rollup-2');
|
||||
const babel = require('rollup-plugin-babel');
|
||||
const includePaths = require('rollup-plugin-includepaths');
|
||||
const externalGlobals = require('rollup-plugin-external-globals');
|
||||
const html = require('rollup-plugin-html');
|
||||
const { config } = require('./config');
|
||||
|
||||
let includePathOptions = {
|
||||
include: {},
|
||||
paths: ['dev'],
|
||||
external: [],
|
||||
extensions: ['.js', '.html']
|
||||
};
|
||||
|
||||
let babelConfig = {
|
||||
exclude: 'node_modules/**',
|
||||
babelrc: false,
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: {"chrome": "60"},
|
||||
loose: true,
|
||||
modules: false
|
||||
}
|
||||
]
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
'@babel/plugin-proposal-decorators',
|
||||
{
|
||||
legacy: true
|
||||
}
|
||||
],
|
||||
'@babel/plugin-proposal-class-properties'
|
||||
]
|
||||
};
|
||||
|
||||
exports.rollupJS = (inputFile) =>
|
||||
rollup2.src({
|
||||
external: ['ko'],
|
||||
input: 'dev/' + inputFile,
|
||||
output: [
|
||||
{file: config.paths.staticJS + inputFile, format: 'iife'}
|
||||
],
|
||||
plugins: [
|
||||
babel(babelConfig),
|
||||
includePaths(includePathOptions),
|
||||
externalGlobals({
|
||||
ko: 'ko'
|
||||
}),
|
||||
html({
|
||||
include: '**/*.html'
|
||||
})
|
||||
]
|
||||
});
|
|
@ -1,67 +0,0 @@
|
|||
/* SnappyMail Webmail (c) SnappyMail | Licensed under AGPL 3 */
|
||||
/* eslint-disable consistent-return */
|
||||
const gulp = require('gulp');
|
||||
const fs = require('node-fs');
|
||||
const chmod = require('gulp-chmod');
|
||||
|
||||
const pkg = require('../package.json');
|
||||
const { config } = require('./config');
|
||||
const { copy, zip, del } = require('./common');
|
||||
|
||||
const snappymailCopy = () => {
|
||||
const versionFull = pkg.version,
|
||||
dist = config.releasesPath + '/webmail/' + versionFull + '/src/';
|
||||
fs.mkdirSync(dist, '0777', true);
|
||||
fs.mkdirSync(dist + 'data');
|
||||
fs.mkdirSync(dist + 'snappymail/v/' + versionFull, '0777', true);
|
||||
|
||||
return gulp
|
||||
.src('snappymail/v/' + config.devVersion + '/**/*', { base: 'snappymail/v/' + config.devVersion })
|
||||
.pipe(chmod(0o644, 0o755))
|
||||
.pipe(gulp.dest(dist + 'snappymail/v/' + versionFull));
|
||||
};
|
||||
|
||||
const snappymailSetup = (done) => {
|
||||
const versionFull = pkg.version,
|
||||
dist = config.releasesPath + '/webmail/' + versionFull + '/src/';
|
||||
fs.writeFileSync(dist + 'data/VERSION', versionFull);
|
||||
fs.writeFileSync(dist + 'data/EMPTY', versionFull);
|
||||
|
||||
fs.writeFileSync(
|
||||
dist + 'index.php',
|
||||
fs
|
||||
.readFileSync('index.php', 'utf8')
|
||||
.replace("'APP_VERSION', '0.0.0'", "'APP_VERSION', '" + versionFull + "'")
|
||||
);
|
||||
|
||||
fs.writeFileSync(dist + 'snappymail/v/' + versionFull + '/index.php.root', fs.readFileSync(dist + 'index.php'));
|
||||
|
||||
config.destPath = config.releasesPath + '/webmail/' + versionFull + '/';
|
||||
config.cleanPath = dist;
|
||||
config.zipSrcPath = dist;
|
||||
config.zipFile = 'snappymail-' + versionFull + '.zip';
|
||||
|
||||
config.snappymailBuilded = true;
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
const snappymailZip = (done) => {
|
||||
if (config.destPath && config.zipSrcPath && config.zipFile) {
|
||||
return zip(config.zipSrcPath, config.destPath, config.zipFile);
|
||||
}
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
const snappymailClean = (done) => {
|
||||
if (config.cleanPath) {
|
||||
return del(config.cleanPath);
|
||||
}
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
exports.snappymailBuild = gulp.series(snappymailCopy, snappymailSetup);
|
||||
|
||||
exports.snappymail = gulp.series(exports.snappymailBuild, snappymailZip, snappymailClean);
|
|
@ -1,12 +0,0 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under AGPL 3 */
|
||||
const gulp = require('gulp');
|
||||
|
||||
const { config } = require('./config');
|
||||
const { cssBuild } = require('./css');
|
||||
|
||||
const watchCss = gulp.series(cssBuild, (cb) => {
|
||||
gulp.watch(config.paths.less.main.watch, { interval: config.watchInterval }, cssBuild);
|
||||
cb();
|
||||
});
|
||||
|
||||
exports.watchCss = watchCss;
|
Loading…
Reference in a new issue