Skip to content

Commit 6bbfd7b

Browse files
Merge pull request nestjs#2527 from BrunnerLivio/ci/build-samples
ci(): build samples in pipeline
2 parents fc3dd67 + 64e69cd commit 6bbfd7b

16 files changed

Lines changed: 97 additions & 16 deletions

File tree

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ jobs:
5656
script: npm run lint
5757
node_js: 12
5858

59+
- stage: "Test"
60+
name: "Build samples"
61+
script: npm run build:samples
62+
node_js: 12
63+

gulpfile.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ const ts = require('gulp-typescript');
55
const sourcemaps = require('gulp-sourcemaps');
66
const clean = require('gulp-clean');
77
const deleteEmpty = require('delete-empty');
8+
const childProcess = require('child_process');
9+
const log = require('fancy-log');
10+
const clc = require('cli-color');
11+
12+
const { promisify } = require('util');
13+
14+
const exec = promisify(childProcess.exec);
15+
16+
const SAMPLE = path.join(__dirname, 'sample');
817

918
const packages = {
1019
common: ts.createProject('packages/common/tsconfig.json'),
@@ -101,9 +110,49 @@ function getFolders(dir) {
101110
return fs.statSync(path.join(dir, file)).isDirectory();
102111
});
103112
}
104-
gulp.task('move', function() {
105-
const getDirs = base => getFolders(base).map(path => `${base}/${path}`);
106113

114+
const getDirs = base => getFolders(base).map(path => `${base}/${path}`);
115+
116+
gulp.task('install:samples', async () => {
117+
const directories = getDirs(SAMPLE);
118+
119+
const promises = directories.map(async dir => {
120+
log.info(
121+
`Installing dependencies of ${clc.magenta(dir.replace(__dirname, ''))}`,
122+
);
123+
try {
124+
await exec(`npm install --no-shrinkwrap --prefix ${dir}`);
125+
} catch (err) {
126+
log.error(`Failed installing dependencies of ${dir}`);
127+
throw err;
128+
}
129+
});
130+
131+
await Promise.all(promises);
132+
});
133+
134+
gulp.task('build:samples', async () => {
135+
const directories = getDirs(SAMPLE);
136+
137+
const promises = directories.map(async dir => {
138+
log.info(
139+
`Building ${clc.magenta(dir.replace(__dirname, ''))}`,
140+
);
141+
try {
142+
await exec(`npm run build --prefix ${dir}`);
143+
} catch (err) {
144+
log.error(`Failed building ${clc.magenta(dir)}:`);
145+
if(err.stdout) {
146+
log.error(err.stdout);
147+
}
148+
throw err;
149+
}
150+
});
151+
152+
return await Promise.all(promises);
153+
});
154+
155+
gulp.task('move', function() {
107156
const examplesDirs = getDirs('sample');
108157
const integrationDirs = getDirs('integration');
109158
const directories = examplesDirs.concat(integrationDirs);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "npm run clean && gulp build",
1313
"prebuild:dev": "rm -rf node_modules/@nestjs",
1414
"build:dev": "gulp build --dist node_modules/@nestjs && gulp move",
15+
"build:samples": "gulp install:samples && npm run build:dev && gulp build:samples",
1516
"postinstall": "opencollective",
1617
"prerelease": "gulp copy-misc && gulp build --dist node_modules/@nestjs",
1718
"publish": "npm run prerelease && npm run build && ./node_modules/.bin/lerna publish --force-publish --access public --exact -m \"chore(@nestjs) publish %s release\"",
@@ -103,6 +104,7 @@
103104
"coveralls": "3.0.4",
104105
"csv-write-stream": "2.0.0",
105106
"delete-empty": "3.0.0",
107+
"fancy-log": "^1.3.3",
106108
"fastify-static": "2.5.0",
107109
"gulp": "4.0.1",
108110
"gulp-clang-format": "1.0.27",

sample/01-cats-app/src/common/middleware/logger.middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Injectable, NestMiddleware } from '@nestjs/common';
33
@Injectable()
44
export class LoggerMiddleware implements NestMiddleware {
55
use(req: any, res: any, next: () => void) {
6-
console.log(`[${context}] Request...`);
6+
console.log(`Request...`);
77
next();
88
}
99
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
33
"include": ["src/**/*"],
4-
"exclude": ["node_modules", "**/*.spec.ts"]
4+
"exclude": ["node_modules", "**/*.spec.ts"],
5+
"compilerOptions": {
6+
"types": []
7+
}
58
}

sample/02-gateways/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
"class-validator": "0.9.1",
2121
"reflect-metadata": "0.1.13",
2222
"rxjs": "6.5.2",
23+
"socket.io-redis": "5.2.0",
2324
"typescript": "3.5.3"
2425
},
2526
"devDependencies": {
2627
"@types/node": "7.10.6",
2728
"@types/socket.io": "2.1.2",
29+
"@types/socket.io-redis": "1.0.25",
2830
"@types/ws": "6.0.1",
2931
"ts-node": "8.3.0",
3032
"tslint": "5.18.0"

sample/08-webpack/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"license": "MIT",
66
"scripts": {
77
"start": "node dist/server",
8-
"webpack": "webpack --config webpack.config.js"
8+
"dev": "webpack --config webpack.config.js --watch",
9+
"build": "webpack --config webpack.config.js"
910
},
1011
"dependencies": {
1112
"@nestjs/common": "6.5.2",
@@ -16,7 +17,7 @@
1617
"typescript": "3.5.3"
1718
},
1819
"devDependencies": {
19-
"@types/node": "10.14.12",
20+
"@types/node": "12.6.0",
2021
"ts-loader": "6.0.4",
2122
"ts-node": "8.3.0",
2223
"tslint": "5.18.0",

sample/08-webpack/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const nodeExternals = require('webpack-node-externals');
44

55
module.exports = {
66
entry: ['webpack/hot/poll?100', './src/main.ts'],
7-
watch: true,
87
target: 'node',
98
externals: [
109
nodeExternals({

sample/12-graphql-apollo/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"target": "es6",
1212
"sourceMap": true,
1313
"outDir": "./dist",
14-
"baseUrl": "./"
14+
"baseUrl": "./",
15+
"skipLibCheck": true
1516
},
1617
"exclude": ["node_modules"]
1718
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
33
"include": ["src/**/*"],
4-
"exclude": ["node_modules", "**/*.spec.ts"]
4+
"exclude": ["node_modules", "**/*.spec.ts"],
5+
"compilerOptions": {
6+
"skipLibCheck": true
7+
},
58
}

0 commit comments

Comments
 (0)