forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
202a572
commit 0686162
Showing
16 changed files
with
338 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,167 +1,16 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const gulp = require('gulp'); | ||
const ts = require('gulp-typescript'); | ||
const sourcemaps = require('gulp-sourcemaps'); | ||
const clean = require('gulp-clean'); | ||
const deleteEmpty = require('delete-empty'); | ||
const childProcess = require('child_process'); | ||
const log = require('fancy-log'); | ||
const clc = require('cli-color'); | ||
const promiseSeries = require('promise.series'); | ||
|
||
const { promisify } = require('util'); | ||
|
||
const exec = promisify(childProcess.exec); | ||
|
||
const SAMPLE = path.join(__dirname, 'sample'); | ||
'use strict'; | ||
/** | ||
* Load the TypeScript compiler, then load the TypeScript gulpfile which simply loads all | ||
* the tasks. The tasks are really inside tools/gulp/tasks. | ||
*/ | ||
|
||
const packages = { | ||
common: ts.createProject('packages/common/tsconfig.json'), | ||
core: ts.createProject('packages/core/tsconfig.json'), | ||
microservices: ts.createProject('packages/microservices/tsconfig.json'), | ||
websockets: ts.createProject('packages/websockets/tsconfig.json'), | ||
testing: ts.createProject('packages/testing/tsconfig.json'), | ||
'platform-express': ts.createProject( | ||
'packages/platform-express/tsconfig.json', | ||
), | ||
'platform-fastify': ts.createProject( | ||
'packages/platform-fastify/tsconfig.json', | ||
), | ||
'platform-socket.io': ts.createProject( | ||
'packages/platform-socket.io/tsconfig.json', | ||
), | ||
'platform-ws': ts.createProject('packages/platform-ws/tsconfig.json'), | ||
}; | ||
const modules = Object.keys(packages); | ||
const source = 'packages'; | ||
const distId = process.argv.indexOf('--dist'); | ||
const dist = distId < 0 ? source : process.argv[distId + 1]; | ||
|
||
gulp.task('default', function() { | ||
modules.forEach(module => { | ||
gulp.watch( | ||
[`${source}/${module}/**/*.ts`, `${source}/${module}/*.ts`], | ||
[module], | ||
); | ||
}); | ||
}); | ||
|
||
gulp.task('copy-misc', function() { | ||
return gulp | ||
.src(['Readme.md', 'LICENSE', '.npmignore']) | ||
.pipe(gulp.dest(`${source}/common`)) | ||
.pipe(gulp.dest(`${source}/core`)) | ||
.pipe(gulp.dest(`${source}/microservices`)) | ||
.pipe(gulp.dest(`${source}/websockets`)) | ||
.pipe(gulp.dest(`${source}/testing`)) | ||
.pipe(gulp.dest(`${source}/platform-fastify`)) | ||
.pipe(gulp.dest(`${source}/platform-express`)) | ||
.pipe(gulp.dest(`${source}/platform-ws`)) | ||
.pipe(gulp.dest(`${source}/platform-socket.io`)); | ||
}); | ||
|
||
gulp.task('clean:output', function() { | ||
return gulp | ||
.src( | ||
[`${source}/**/*.js`, `${source}/**/*.d.ts`, `${source}/**/*.js.map`], | ||
{ | ||
read: false, | ||
}, | ||
) | ||
.pipe(clean()); | ||
}); | ||
|
||
gulp.task('clean:dirs', function(done) { | ||
deleteEmpty.sync(`${source}/`); | ||
done(); | ||
}); | ||
|
||
gulp.task('clean:bundle', gulp.series('clean:output', 'clean:dirs')); | ||
|
||
modules.forEach(module => { | ||
gulp.task(module, () => { | ||
return packages[module] | ||
.src() | ||
.pipe(packages[module]()) | ||
.pipe(gulp.dest(`${dist}/${module}`)); | ||
}); | ||
}); | ||
|
||
modules.forEach(module => { | ||
gulp.task(module + ':dev', () => { | ||
return packages[module] | ||
.src() | ||
.pipe(sourcemaps.init()) | ||
.pipe(packages[module]()) | ||
.pipe( | ||
sourcemaps.mapSources(sourcePath => './' + sourcePath.split('/').pop()), | ||
) | ||
.pipe(sourcemaps.write('.')) | ||
.pipe(gulp.dest(`${dist}/${module}`)); | ||
}); | ||
}); | ||
|
||
gulp.task('common:dev', gulp.series(modules.map(module => module + ':dev'))); | ||
gulp.task('build', gulp.series(modules)); | ||
gulp.task('build:dev', gulp.series('common:dev')); | ||
|
||
function getFolders(dir) { | ||
return fs.readdirSync(dir).filter(function(file) { | ||
return fs.statSync(path.join(dir, file)).isDirectory(); | ||
}); | ||
} | ||
|
||
const getDirs = base => getFolders(base).map(path => `${base}/${path}`); | ||
|
||
gulp.task('install:samples', async () => { | ||
const directories = getDirs(SAMPLE); | ||
|
||
const promises = directories.map(async dir => { | ||
const dirName = dir.replace(__dirname, ''); | ||
log.info(`Installing dependencies of ${clc.magenta(dirName)}`); | ||
try { | ||
await exec(`npm install --no-shrinkwrap --prefix ${dir}`); | ||
log.info(`Finished installing ${clc.magenta(dirName)}`); | ||
} catch (err) { | ||
log.error(`Failed installing dependencies of ${dirName}`); | ||
throw err; | ||
} | ||
}); | ||
|
||
return await promiseSeries(promises); | ||
}); | ||
|
||
gulp.task('build:samples', async () => { | ||
const directories = getDirs(SAMPLE); | ||
const path = require('path'); | ||
|
||
const promises = directories.map(async dir => { | ||
const dirName = dir.replace(__dirname, ''); | ||
log.info(`Building ${clc.magenta(dirName)}`); | ||
try { | ||
await exec(`npm run build --prefix ${dir}`); | ||
log.info(`Finished building ${clc.magenta(dirName)}`); | ||
} catch (err) { | ||
log.error(`Failed building ${clc.magenta(dirName)}:`); | ||
if (err.stdout) { | ||
log.error(err.stdout); | ||
} | ||
throw err; | ||
} | ||
}); | ||
const projectDir = __dirname; | ||
const tsconfigPath = path.join(projectDir, 'tools/gulp/tsconfig.json'); | ||
|
||
return await promiseSeries(promises); | ||
require('ts-node').register({ | ||
project: tsconfigPath | ||
}); | ||
|
||
gulp.task('move', function() { | ||
const examplesDirs = getDirs('sample'); | ||
const integrationDirs = getDirs('integration'); | ||
const directories = examplesDirs.concat(integrationDirs); | ||
|
||
let stream = gulp.src(['node_modules/@nestjs/**/*']); | ||
|
||
directories.forEach(dir => { | ||
stream = stream.pipe(gulp.dest(dir + '/node_modules/@nestjs')); | ||
}); | ||
return stream; | ||
}); | ||
require('./tools/gulp/gulpfile'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getDirs } from './util/task-helpers'; | ||
|
||
// All paths are related to the base dir | ||
export const source = 'packages'; | ||
export const integrationPath = 'integration'; | ||
export const samplePath = 'sample'; | ||
|
||
export const packagePaths = getDirs(source); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './tasks/copy-misc'; | ||
import './tasks/clean'; | ||
import './tasks/packages'; | ||
import './tasks/move'; | ||
import './tasks/samples'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { task, src, series } from 'gulp'; | ||
import { source } from '../config'; | ||
import * as clean from 'gulp-clean'; | ||
import * as deleteEmpty from 'delete-empty'; | ||
|
||
/** | ||
* Cleans the build output assets from the packages folders | ||
*/ | ||
function cleanOutput() { | ||
return src( | ||
[ | ||
`${source}/**/*.js`, | ||
`${source}/**/*.d.ts`, | ||
`${source}/**/*.js.map`, | ||
`${source}/**/*.d.ts.map`, | ||
], | ||
{ | ||
read: false, | ||
}, | ||
).pipe(clean()); | ||
} | ||
|
||
/** | ||
* Cleans empty dirs | ||
*/ | ||
function cleanDirs(done: () => void) { | ||
deleteEmpty.sync(`${source}/`); | ||
done(); | ||
} | ||
|
||
task('clean:output', cleanOutput); | ||
task('clean:dirs', cleanDirs); | ||
task('clean:bundle', series('clean:output', 'clean:dirs')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { task, src, dest } from 'gulp'; | ||
import { packagePaths } from '../config'; | ||
|
||
/** | ||
* Copies assets like Readme.md or LICENSE from the project base path | ||
* to all the packages. | ||
*/ | ||
function copyMisc(): NodeJS.ReadWriteStream { | ||
const miscFiles = src(['Readme.md', 'LICENSE', '.npmignore']); | ||
// Since `dest()` does not take a string-array, we have to append it | ||
// ourselves | ||
return packagePaths.reduce( | ||
(stream, packagePath) => stream.pipe(dest(packagePath)), | ||
miscFiles, | ||
); | ||
} | ||
|
||
task('copy-misc', copyMisc); |
Oops, something went wrong.