Skip to content
This repository was archived by the owner on Jul 4, 2018. It is now read-only.

Commit e550a88

Browse files
authored
Merge pull request #56 from FoalTS/support-shell
Add a shell and move templates into the modules.
2 parents 5ec4125 + 566f119 commit e550a88

File tree

9 files changed

+68
-14
lines changed

9 files changed

+68
-14
lines changed

generators/app/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Welcome to the FoalTS generator! The following questions will help you create yo
5555
type: 'input',
5656
name: 'uri',
5757
message: 'What is your database uri?',
58-
default: database === 'sqlite' ? 'sqlite://database.db' : ''
58+
default: database === 'sqlite' ? 'sqlite://db.sqlite3' : ''
5959
},
6060
{
6161
type: 'confirm',
@@ -116,7 +116,9 @@ Welcome to the FoalTS generator! The following questions will help you create yo
116116
testSecret2: crypto.randomBytes(32).toString('hex'),
117117
}
118118
const paths = [
119+
'src/app/templates/index.html',
119120
'src/app/app.module.ts',
121+
'src/app/app.ts',
120122
'src/app/index-view.service.spec.ts',
121123
'src/app/index-view.service.ts',
122124
'src/config/config.ts',
@@ -126,8 +128,7 @@ Welcome to the FoalTS generator! The following questions will help you create yo
126128
'src/config/test.ts',
127129
'src/main.ts',
128130

129-
'templates/index.html',
130-
131+
'gulpfile.js',
131132
'package.json',
132133
'server.js',
133134
'tsconfig.json',
@@ -141,6 +142,10 @@ Welcome to the FoalTS generator! The following questions will help you create yo
141142
)
142143
}
143144
if (this.authentication) {
145+
this.fs.copy(
146+
this.templatePath('src/app/auth/templates/login-view.html'),
147+
this.destinationPath(`${this.names.kebabName}/src/app/auth/templates/login-view.html`)
148+
)
144149
paths.push(
145150
'src/app/auth/auth.module.ts',
146151
'src/app/auth/authenticator.service.ts',
@@ -149,7 +154,6 @@ Welcome to the FoalTS generator! The following questions will help you create yo
149154
'src/app/auth/login-view.service.ts',
150155
'src/app/shared/user.interface.ts',
151156
'src/app/shared/user.service.ts',
152-
'templates/login-view.html',
153157
);
154158
}
155159
for (let path of paths) {
@@ -192,12 +196,10 @@ Welcome to the FoalTS generator! The following questions will help you create yo
192196
this.npmInstall([], {}, () => {}, { cwd: this.names.kebabName });
193197
this.npmInstall([
194198
'concurrently',
195-
'nodemon',
196199
'mocha',
197200
'chai',
198201
'@types/mocha',
199202
'@types/chai',
200-
'typescript',
201203
'tslint'
202204
], { 'save-dev': true }, () => {}, { cwd: this.names.kebabName });
203205
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const gulp = require('gulp');
2+
const ts = require('gulp-typescript');
3+
const nodemon = require('gulp-nodemon');
4+
const sourcemaps = require('gulp-sourcemaps');
5+
const del = require('del');
6+
7+
const tsProject = ts.createProject('tsconfig.json');
8+
9+
const templateBlob = './src/**/*.html';
10+
11+
gulp.task('clean', () => del('dist'));
12+
13+
gulp.task('compile', function () {
14+
return tsProject.src()
15+
.pipe(sourcemaps.init())
16+
.pipe(tsProject())
17+
.pipe(sourcemaps.write())
18+
.pipe(gulp.dest('dist'));
19+
});
20+
21+
gulp.task('copy-templates', () => {
22+
return gulp.src(templateBlob)
23+
.pipe(gulp.dest('dist'));
24+
});
25+
26+
gulp.task('build', ['compile', 'copy-templates']);
27+
28+
gulp.task('dev:start', ['compile'], () => {
29+
return nodemon({
30+
script: 'server.js',
31+
ext: 'ts',
32+
watch: tsProject.config.include,
33+
tasks: ['compile']
34+
});
35+
});
36+
37+
gulp.task('dev:copy-templates', ['copy-templates'], () => {
38+
return gulp.watch(templateBlob, ['copy-templates']);
39+
});
40+
41+
gulp.task('dev:app', ['dev:start', 'dev:copy-templates'])

generators/app/templates/package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"description": "",
55
"scripts": {
66
"lint": "tslint -c tslint.json -p tsconfig.json",
7-
"build": "tsc",
7+
"build": "gulp clean && gulp build",
8+
"shell": "cd dist/app && node -e \"const { app } = require('./app')\" -i",
89
"test": "mocha -r source-map-support/register \"./dist/**/*.spec.js\"",
910
"start": "node server.js",
10-
"dev:app": "tsc && concurrently -p \"[{name}]\" -n \"BUILD,SERVER\" -c \"bold\" \"tsc -w\" \"nodemon -e js server.js\"",
11+
"dev:app": "gulp clean && gulp dev:app",
1112
"dev:test": "tsc && concurrently -p \"[{name}]\" -n \"BUILD,SERVER\" -c \"bold\" \"tsc -w\" \"mocha -r source-map-support/register -w \"./dist/**/*.spec.js\"\""
1213
},
1314
"engines": {
@@ -27,5 +28,13 @@
2728
"@foal/ejs": "^0.4.0-beta.1",
2829
"@foal/express": "^0.4.0-beta.1",
2930
"source-map-support": "^0.5.1"
31+
},
32+
"devDependencies": {
33+
"del": "^3.0.0",
34+
"gulp": "^3.9.1",
35+
"typescript": "^2.7.2",
36+
"gulp-typescript": "^4.0.1",
37+
"gulp-nodemon": "^2.2.1",
38+
"gulp-sourcemaps": "^2.6.4"
3039
}
3140
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { App } from '@foal/core';
2+
3+
import { AppModule } from './app.module';
4+
5+
export const app = new App(AppModule);

generators/app/templates/src/app/auth/login-view.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { EjsTemplateService } from '@foal/ejs';
44
@Service()
55
export class LoginViewService extends EjsTemplateService {
66
constructor() {
7-
super('./templates/login-view.html');
7+
super(__dirname + '/templates/login-view.html');
88
}
99
}

generators/app/templates/templates/login-view.html renamed to generators/app/templates/src/app/auth/templates/login-view.html

File renamed without changes.

generators/app/templates/src/app/index-view.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { EjsTemplateService } from '@foal/ejs';
44
@Service()
55
export class IndexViewService extends EjsTemplateService {
66
constructor() {
7-
super('./templates/index.html');
7+
super(__dirname + '/templates/index.html');
88
}
99
}
File renamed without changes.

generators/app/templates/src/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { App } from '@foal/core';
21
import { getMiddlewares } from '@foal/express';
32
import * as bodyParser from 'body-parser';
43
import * as csurf from 'csurf';
@@ -8,11 +7,9 @@ import * as helmet from 'helmet';
87
import * as logger from 'morgan';
98
import * as path from 'path';
109

11-
import { AppModule } from './app/app.module';
10+
import { app as foal } from './app/app';
1211
import { config } from './config';
1312

14-
const foal = new App(AppModule);
15-
1613
const app = express();
1714

1815
app.use(logger('[:date] ":method :url HTTP/:http-version" :status - :response-time ms'));

0 commit comments

Comments
 (0)