Previously, I had set up a json server and used the following code to start it: I found guidance in this GitHub repository.
Starting angular2 project with gulp
gulp-live-server.js
var gulpCore = require('gulp');
var gulpParam = require('gulp-param');
var gulpExpressServer = require('gulp-express');
var gulp = gulpParam(gulpCore, process.argv);
//server will be running on port 3100 if not explicitly specified as below
gulp.task('server', function (port,env, package) {
console.log('IN LIVVEEEEEEEEE SERVERRRRR --->>'+' port passed:' + port+ ' command line args:' + process.argv+ ' package:' +package+' env:' +env );
var expressPort = isNaN(port + '') ? 3200 : port || 3200;
var jsonServerStarter = 'server/json-server-starter.js';
gulpExpressServer.run([jsonServerStarter], { env: { expressPort: expressPort } });
gulp.watch(['db.json'], function (event) {
console.log('abt to notify for db.json');
//gulpExpressServer.notify(event);
});
});
gulp.task('default', ['server']);
Now, as I am working on an Angular2 app, I need to start the json-server using gulpfile.ts
. Currently, my setup looks like this:
import * as gulp from 'gulp';
import * as runSequence from 'run-sequence';
import { PROJECT_TASKS_DIR, SEED_TASKS_DIR } from './tools/config';
import { loadTasks } from './tools/utils';
loadTasks(SEED_TASKS_DIR);
loadTasks(PROJECT_TASKS_DIR);
// --------------
// Build dev.
gulp.task('build.dev', (done: any) =>
runSequence(//'clean.dev',
// 'tslint',
// 'css-lint',
'build.assets.dev',
'build.html_css',
'build.js.dev',
'build.index.dev',
done));
// --------------
// Build dev watch.
gulp.task('build.dev.watch', (done: any) =>
runSequence('build.dev',
'watch.dev',
done));
// --------------
// Build prod.
gulp.task('build.prod', (done: any) =>
runSequence('clean.prod',
'tslint',
'css-lint',
'build.assets.prod',
'build.html_css',
'copy.js.prod',
'build.js.prod',
'build.bundles',
'build.bundles.app',
'build.index.prod',
done));
// --------------
// Serve dev
gulp.task('serve.dev', (done: any) =>
runSequence('build.dev',
'server.start',
'watch.dev',
done));
// --------------
// Serve prod
gulp.task('serve.prod', (done: any) =>
runSequence('build.prod',
'server.prod',
done));
//---------------
//json server
//not sure how to configure json-server here.
However, I am uncertain about how to configure the json-server in TypeScript. Any suggestions?