Skip to content

Commit

Permalink
feat(build): add copy:config:server
Browse files Browse the repository at this point in the history
  • Loading branch information
klarkc committed Mar 25, 2018
1 parent 49f48c5 commit 661ee6f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
17 changes: 15 additions & 2 deletions template/gulp-tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import babelify from 'babelify';
import modulesify from 'css-modulesify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import {argv} from 'yargs';
import {dirs} from './config';
import {customSass} from './compilers';

Expand All @@ -21,7 +22,7 @@ gulp.task('build:test', () => gulp.src([
.pipe(sourcemaps.write())
.pipe(gulp.dest(dirs.buildTest)));

gulp.task('build:client', ['copy:client'], () => {
gulp.task('build:client', ['copy:client', 'copy:config:server'], () => {
vueify.compiler.applyConfig({
sass: {
includePaths: [
Expand Down Expand Up @@ -58,6 +59,18 @@ gulp.task('build:client', ['copy:client'], () => {
},
});

if (argv.production) {
b.transform(aliasify, {
replacements: {
'(.+)server/config.json$': path.resolve(
dirs.buildServer,
'config.json',
),
},
verbose: true,
});
}

return b.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
Expand All @@ -74,7 +87,7 @@ gulp.task('build:common', () => {
.pipe(gulp.dest(dirs.buildCommon));
});

gulp.task('build:server', ['copy:server'], () => {
gulp.task('build:server', ['copy:server', 'copy:config:server'], () => {
return gulp.src(path.resolve(dirs.srcServer, '**/*.js'))
.pipe(sourcemaps.init())
.pipe(babel())
Expand Down
6 changes: 6 additions & 0 deletions template/gulp-tasks/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ dirs.testServer = path.resolve(dirs.test, 'server');
dirs.srcClient = path.resolve(dirs.root, 'client');
dirs.srcCommon = path.resolve(dirs.root, 'common');
dirs.srcServer = path.resolve(dirs.root, 'server');

// Set here production build settings
export const prod = {
host: '0.0.0.0',
port: 80,
};
29 changes: 28 additions & 1 deletion template/gulp-tasks/copy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable arrow-body-style */
import gulp from 'gulp';
import path from 'path';
import {dirs} from './config';
import fs from 'fs';
import {argv} from 'yargs';
import {dirs, prod} from './config';


gulp.task('copy:client:fa', () => {
return gulp
Expand All @@ -24,3 +27,27 @@ gulp.task('copy:server', () => {
return gulp.src(`${dirs.srcServer}/**/*.json`)
.pipe(gulp.dest(path.resolve(dirs.buildServer)));
});

gulp.task('copy:config:server', ['copy:server'], (done) => {
if (argv.production) {
const configPath = path.resolve(
dirs.srcServer,
'config.json'
);

fs.readFile(configPath, (err, data) => {
if (err) done(err);

fs.writeFile(
path.resolve(dirs.buildServer, 'config.json'),
JSON.stringify({
...JSON.parse(data),
...prod,
}),
done
);
});
} else {
done();
}
});

0 comments on commit 661ee6f

Please sign in to comment.