Skip to content

Commit

Permalink
Fix building fail in gulp 4
Browse files Browse the repository at this point in the history
Fix building fail in gulp 4
  • Loading branch information
a161803398 committed Aug 20, 2018
1 parent 7cc4a66 commit 327181c
Show file tree
Hide file tree
Showing 8 changed files with 660 additions and 1,537 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/

#node.js modules
# node.js modules
node_modules/

#nw.js files
# nw.js files
/nwjs/
/nwjs-sdk/

# Build result
/dist

# Dev run files
/chat_logs

# Windows Installer files
*.cab
*.msi
Expand Down
Binary file added doc/ReadMe.pdf
Binary file not shown.
Binary file added doc/使用說明.pdf
Binary file not shown.
65 changes: 43 additions & 22 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,37 @@ const rename = require("gulp-rename");
const htmlreplace = require('gulp-html-replace');
const minifyHTML = require('gulp-minify-html');
const PluginError = require('plugin-error');
const runSequence = require('run-sequence');
const del = require('del');
const fs = require('fs');
const rcedit = require('rcedit')
const install = require("gulp-install");
const childProcess = require('child_process');

gulp.task('clean', ()=>{
return del.sync(['dist']);
return del(['dist']);
});

gulp.task('copy-data', ()=>{
gulp.src('nwjs/**/*').pipe(gulp.dest('dist/bin'));
gulp.src('src/www/**/*').pipe(gulp.dest('dist/bin/www'));
gulp.task('copy-data', (done)=>{
if(fs.existsSync('nwjs/nw.exe')){
gulp.src('nwjs/**/*').pipe(gulp.dest('dist/bin'));
gulp.src('src/www/**/*').pipe(gulp.dest('dist/bin/www'));
done();
}else{
throw noNwjsError;
}
});

gulp.task('copy-doc', (done)=>{
gulp.src('doc/*').pipe(gulp.dest('dist'));
done();
});

gulp.task('install-modules', ()=>{
gulp.task('install-modules', (done)=>{
gulp.src(['src/package.json', 'src/package-lock.json'])
.pipe(gulp.dest('dist/bin').on('end', ()=> {
gulp.src(['dist/bin/package.json', 'dist/bin/package-lock.json']).pipe(install({production: true}));
}));
done();
});

gulp.task('install-newest-modules', ()=>{
Expand All @@ -36,7 +46,7 @@ gulp.task('install-newest-modules', ()=>{
}));
});

gulp.task('wrapper', ()=>{
gulp.task('wrapper', (done)=>{
copyTask = gulp.src('wrapper/nwStart.exe')
.pipe(gulp.dest('dist')).on('end', ()=> {
const packageInfo = JSON.parse(fs.readFileSync('src/package.json', 'utf8'));
Expand Down Expand Up @@ -69,37 +79,48 @@ gulp.task('wrapper', ()=>{
if(e != null) console.log(e);
});
});

done();

});

gulp.task('copy-popup', ()=>{
gulp.task('copy-popup', (done)=>{
gulp.src('popup/**/*').pipe(gulp.dest('dist/popup'));
done();
});

const noNwjsSdkError = new PluginError('Missing nw.js sdk files', 'Please download the sdk version nw.js from https://nwjs.io/ and unzip it to nwjs-sdk folder!!');
gulp.task('run-dev', ()=>{
if(fs.existsSync('nwjs-sdk/nw.exe')){
gulp.src('src/*.*').pipe(install({},()=> {

gulp.task('dev-clean', (done)=>{
return del(['src/node_modules']);
});

gulp.task('run-dev', (done)=>{
if(fs.existsSync('nwjs-sdk/nw.exe')){
function runNW(){
const child = childProcess.spawn(
'nwjs-sdk/nw.exe',
["src"], {
detached: true,
stdio: 'ignore'
});
child.unref();
}));
child.unref();
done();
}

if(fs.existsSync('src/node_modules')){
runNW();
}else{
gulp.src('src/*.*').pipe(install({}, runNW));
}

}else{
throw noNwjsSdkError;
}
});

gulp.task('run-dev-clean', gulp.series('dev-clean', 'run-dev'));

const noNwjsError = new PluginError('Missing nw.js binary files', 'Please download normal version nw.js from https://nwjs.io/ and unzip it to nwjs folder!!');

gulp.task('default', ()=>{
if(fs.existsSync('nwjs/nw.exe')){
runSequence('clean', ['copy-data', 'wrapper', 'install-modules', 'copy-popup']);
}else{
throw noNwjsError;
}
});

gulp.task('build', gulp.parallel('copy-data', 'wrapper', 'install-modules', 'copy-popup', 'copy-doc'));
gulp.task('default', gulp.series('clean', 'build'));
Loading

0 comments on commit 327181c

Please sign in to comment.