diff --git a/packages/midway-bin/lib/cmd/build.js b/packages/midway-bin/lib/cmd/build.js index 422b001140ff..d7ab26c702d9 100644 --- a/packages/midway-bin/lib/cmd/build.js +++ b/packages/midway-bin/lib/cmd/build.js @@ -36,7 +36,7 @@ class BuildCommand extends Command { return 'build application automatically'; } - * run(context) { + async run(context) { const { cwd, argv } = context; const tscCli = require.resolve('typescript/bin/tsc'); @@ -46,10 +46,10 @@ class BuildCommand extends Command { } if (argv.clean) { - yield this.cleanDir(cwd, argv.project); + await this.cleanDir(cwd, argv.project); } - yield this.copyFiles(cwd, argv.project, argv); + await this.copyFiles(cwd, argv.project, argv); const args = []; @@ -57,10 +57,10 @@ class BuildCommand extends Command { args.push('-p'); args.push(argv.project); } - yield this.helper.forkNode(tscCli, args, { cwd }); + await this.helper.forkNode(tscCli, args, { cwd }); } - * cleanDir(cwd, projectFile) { + async cleanDir(cwd, projectFile) { const tsConfig = require(path.join(cwd, projectFile)); // if projectFile extended and without outDir, @@ -70,7 +70,7 @@ class BuildCommand extends Command { !tsConfig.compilerOptions || (tsConfig.compilerOptions && !tsConfig.compilerOptions.outDir) ) { - yield this.cleanDir(cwd, tsConfig.extends); + await this.cleanDir(cwd, tsConfig.extends); return; } } @@ -78,12 +78,12 @@ class BuildCommand extends Command { if (tsConfig && tsConfig.compilerOptions) { const outDir = tsConfig.compilerOptions.outDir; if (outDir) { - yield rimraf(outDir); + await rimraf(outDir); } } } - * copyFiles(cwd, projectFile, argv) { + async copyFiles(cwd, projectFile, argv) { const tsConfig = require(path.join(cwd, projectFile)); // if projectFile extended and without outDir, @@ -93,7 +93,7 @@ class BuildCommand extends Command { !tsConfig.compilerOptions || (tsConfig.compilerOptions && !tsConfig.compilerOptions.outDir) ) { - yield this.copyFiles(cwd, tsConfig.extends, argv); + await this.copyFiles(cwd, tsConfig.extends, argv); return; } } @@ -111,7 +111,7 @@ class BuildCommand extends Command { this.copyFile(srcDir, targetDir, cwd); } else { // 通配符的情况 - const paths = yield globby([].concat(file), { + const paths = await globby([].concat(file), { cwd: path.join(cwd, argv.srcDir), }); for (const p of paths) { diff --git a/packages/midway-bin/lib/cmd/clean.js b/packages/midway-bin/lib/cmd/clean.js index c94c95bbfbf5..4d5bda137cbb 100644 --- a/packages/midway-bin/lib/cmd/clean.js +++ b/packages/midway-bin/lib/cmd/clean.js @@ -16,17 +16,17 @@ class CleanCommand extends Command { return 'clean application temporary files'; } - * run(context) { + async run(context) { const { cwd } = context; if (!fs.existsSync(path.join(cwd, 'package.json'))) { console.log(`[midway-bin] package.json not found in ${cwd}\n`); return; } - yield this.cleanDir(cwd); + await this.cleanDir(cwd); } - * cleanDir(cwd) { - yield new Promise((resolve, reject) => { + async cleanDir(cwd) { + await new Promise((resolve, reject) => { cp.exec('find . -type d -name \'logs\' -or -name \'run\' -or -name \'.nodejs-cache\' | xargs rm -rf', { cwd, }, error => { @@ -43,7 +43,7 @@ class CleanCommand extends Command { const pkg = require(path.join(cwd, 'package.json')); if (pkg['midway-bin-clean'] && pkg['midway-bin-clean'].length) { for (const file of pkg['midway-bin-clean']) { - yield rimraf(path.join(cwd, file)); + await rimraf(path.join(cwd, file)); console.log(`[midway-bin] clean ${file} success!`); } console.log('[midway-bin] clean complete!'); diff --git a/packages/midway-bin/lib/cmd/debug.js b/packages/midway-bin/lib/cmd/debug.js index 5efc59d1f338..353fa477b512 100644 --- a/packages/midway-bin/lib/cmd/debug.js +++ b/packages/midway-bin/lib/cmd/debug.js @@ -7,11 +7,11 @@ class DebugCommand extends require('egg-bin').DebugCommand { this.usage = 'Usage: midway-bin debug [dir] [options]'; } - * run(context) { + async run(context) { if (!context.argv.framework) { context.argv.framework = this.findFramework('midway') || this.findFramework('midway-mirror'); } - yield super.run(context); + await super.run(context); } findFramework(module) { diff --git a/packages/midway-bin/lib/cmd/dev.js b/packages/midway-bin/lib/cmd/dev.js index f97ed8556054..74a9d71107a2 100644 --- a/packages/midway-bin/lib/cmd/dev.js +++ b/packages/midway-bin/lib/cmd/dev.js @@ -8,11 +8,11 @@ class DevCommand extends require('egg-bin/lib/cmd/dev') { this.defaultPort = process.env.PORT || 7001; } - * run(context) { + async run(context) { if (!context.argv.framework) { context.argv.framework = this.findFramework('midway') || this.findFramework('midway-mirror'); } - yield super.run(context); + await super.run(context); } findFramework(module) { diff --git a/packages/midway-bin/lib/cmd/doc.js b/packages/midway-bin/lib/cmd/doc.js index 7742c35102c9..563f2a028503 100644 --- a/packages/midway-bin/lib/cmd/doc.js +++ b/packages/midway-bin/lib/cmd/doc.js @@ -55,7 +55,7 @@ class DocCommand extends Command { return 'generate typescript document by typedoc'; } - * run({ cwd, argv }) { + async run({ cwd, argv }) { let args; if (argv.options) { // if has options args just ignore others @@ -68,7 +68,7 @@ class DocCommand extends Command { } const docBin = require.resolve('typedoc/bin/typedoc'); - yield this.helper.forkNode(docBin, args, { cwd }); + await this.helper.forkNode(docBin, args, { cwd }); } } diff --git a/packages/midway-bin/lib/cmd/test.js b/packages/midway-bin/lib/cmd/test.js index 8d42424f39fe..d82fd15e015d 100644 --- a/packages/midway-bin/lib/cmd/test.js +++ b/packages/midway-bin/lib/cmd/test.js @@ -6,11 +6,11 @@ class TestCommand extends require('egg-bin').TestCommand { this.usage = 'Usage: midway-bin test [files] [options]'; } - * run(context) { + async run(context) { if (!context.env.NODE_ENV) { context.env.NODE_ENV = 'unittest'; } - yield super.run(context); + await super.run(context); } } diff --git a/packages/midway-bin/test/lib/cmd/build.test.js b/packages/midway-bin/test/lib/cmd/build.test.js index 9608c1e2d2df..339bd28fb9e8 100644 --- a/packages/midway-bin/test/lib/cmd/build.test.js +++ b/packages/midway-bin/test/lib/cmd/build.test.js @@ -12,36 +12,36 @@ describe('test/lib/cmd/build.test.js', () => { afterEach(mm.restore); - it('should warn message', function* () { + it('should warn message', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir-without-config'); const child = coffee .fork(midwayBin, [ 'build' ], { cwd }) .expect('stdout', /tsconfig/); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); }); - it('should build success', function* () { + it('should build success', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir'); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); const child = coffee.fork(midwayBin, [ 'build' ], { cwd }); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'dist/a.js'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); - it('should auto clean dir before build', function* () { + it('should auto clean dir before build', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir'); const child = coffee.fork(midwayBin, [ 'build' ], { cwd }); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'dist/a.js'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); - it('should copy assets file to dist dir', function* () { + it('should copy assets file to dist dir', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir-with-assets'); const child = coffee.fork(midwayBin, [ 'build', '-c' ], { cwd }); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'dist/a.js'))); assert(fs.existsSync(path.join(cwd, 'dist/view/index.html'))); assert(fs.existsSync(path.join(cwd, 'dist/public/test.css'))); @@ -51,20 +51,20 @@ describe('test/lib/cmd/build.test.js', () => { assert(fs.existsSync(path.join(cwd, 'dist/lib/a.text'))); assert(fs.existsSync(path.join(cwd, 'dist/pattern/ignore.css'))); assert(fs.existsSync(path.join(cwd, 'dist/pattern/sub/sub_ignore.css'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); - it('should copy assets file and ignore not exists directory', function* () { + it('should copy assets file and ignore not exists directory', async () => { const cwd = path.join( __dirname, '../../fixtures/ts-dir-with-not-exists-file' ); const child = coffee.fork(midwayBin, [ 'build', '-c' ], { cwd }).debug(); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(!fs.existsSync(path.join(cwd, 'dist/view/index.html'))); assert(fs.existsSync(path.join(cwd, 'dist/public/test.css'))); assert(fs.existsSync(path.join(cwd, 'dist/public/test.js'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); }); @@ -73,48 +73,48 @@ describe('test/lib/cmd/build.test.js - with another tsconfig', () => { afterEach(mm.restore); - it('should warn message', function* () { + it('should warn message', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir-without-config'); const child = coffee .fork(midwayBin, [ 'build', '-p', 'tsconfig.prod.json' ], { cwd }) .expect('stdout', /tsconfig/); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); }); - it('should build success with another tsconfig', function* () { + it('should build success with another tsconfig', async () => { const cwd = path.join( __dirname, '../../fixtures/ts-dir-with-another-tsconfig' ); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); const child = coffee.fork( midwayBin, [ 'build', '-p', 'tsconfig.prod.json' ], { cwd } ); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'dist/a.js'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); - it('should auto clean dir before build with another tsconfig', function* () { + it('should auto clean dir before build with another tsconfig', async () => { const cwd = path.join( __dirname, '../../fixtures/ts-dir-with-another-tsconfig' ); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); const child = coffee.fork( midwayBin, [ 'build', '-p', 'tsconfig.prod.json' ], { cwd } ); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'dist/a.js'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); - it('should copy assets file to dist dir with another tsconfig', function* () { + it('should copy assets file to dist dir with another tsconfig', async () => { const cwd = path.join( __dirname, '../../fixtures/ts-dir-with-assets-and-another-tsconfig' @@ -125,7 +125,7 @@ describe('test/lib/cmd/build.test.js - with another tsconfig', () => { [ 'build', '-c', '-p', 'tsconfig.prod.json' ], { cwd } ); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'dist/a.js'))); assert(fs.existsSync(path.join(cwd, 'dist/view/index.html'))); assert(fs.existsSync(path.join(cwd, 'dist/public/test.css'))); @@ -135,6 +135,6 @@ describe('test/lib/cmd/build.test.js - with another tsconfig', () => { assert(fs.existsSync(path.join(cwd, 'dist/lib/a.text'))); assert(fs.existsSync(path.join(cwd, 'dist/pattern/ignore.css'))); assert(fs.existsSync(path.join(cwd, 'dist/pattern/sub/sub_ignore.css'))); - yield rimraf(path.join(cwd, 'dist')); + await rimraf(path.join(cwd, 'dist')); }); }); diff --git a/packages/midway-bin/test/lib/cmd/clean.test.js b/packages/midway-bin/test/lib/cmd/clean.test.js index f664697bec3e..6137df242e55 100644 --- a/packages/midway-bin/test/lib/cmd/clean.test.js +++ b/packages/midway-bin/test/lib/cmd/clean.test.js @@ -12,26 +12,26 @@ describe('test/lib/cmd/clean.test.js', () => { afterEach(mm.restore); - it('should clean dir', function *() { + it('should clean dir', async () => { const cwd = path.join(__dirname, '../../fixtures/clean-dir'); - yield mkdirp(path.join(cwd, 'logs/test.log')); - yield mkdirp(path.join(cwd, '.nodejs-cache/test.log')); - yield mkdirp(path.join(cwd, 'run/a.log')); + await mkdirp(path.join(cwd, 'logs/test.log')); + await mkdirp(path.join(cwd, '.nodejs-cache/test.log')); + await mkdirp(path.join(cwd, 'run/a.log')); const child = coffee.fork(midwayBin, [ 'clean' ], { cwd }); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'a.ts'))); assert(!fs.existsSync(path.join(cwd, '.nodejs-cache'))); assert(!fs.existsSync(path.join(cwd, 'run'))); assert(!fs.existsSync(path.join(cwd, 'logs'))); }); - it('should clean file with config', function *() { + it('should clean file with config', async () => { const cwd = path.join(__dirname, '../../fixtures/clean-dir-config'); - yield mkdirp(path.join(cwd, 'customDir/a.js')); + await mkdirp(path.join(cwd, 'customDir/a.js')); - const child = coffee.fork(midwayBin, [ 'clean'], { cwd }); - yield child.expect('code', 0).end(); + const child = coffee.fork(midwayBin, [ 'clean' ], { cwd }); + await child.expect('code', 0).end(); assert(!fs.existsSync(path.join(cwd, 'customDir'))); }); diff --git a/packages/midway-bin/test/lib/cmd/doc.test.js b/packages/midway-bin/test/lib/cmd/doc.test.js index a3c3fa9e5b0c..87b18d284002 100644 --- a/packages/midway-bin/test/lib/cmd/doc.test.js +++ b/packages/midway-bin/test/lib/cmd/doc.test.js @@ -12,31 +12,31 @@ describe('test/lib/cmd/doc.test.js', () => { afterEach(mm.restore); - it('should generate doc use default value', function *() { + it('should generate doc use default value', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir'); - const child = coffee.fork(midwayBin, [ 'doc'], { cwd }); - yield child.expect('code', 0).end(); + const child = coffee.fork(midwayBin, [ 'doc' ], { cwd }); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'doc/index.html'))); - yield rimraf(path.join(cwd, 'doc')); + await rimraf(path.join(cwd, 'doc')); }); - it('should generate doc use custom value', function *() { + it('should generate doc use custom value', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir'); const child = coffee.fork(midwayBin, [ 'doc', '-o', 'api' ], { cwd }); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'api/index.html'))); - yield rimraf(path.join(cwd, 'api')); + await rimraf(path.join(cwd, 'api')); }); - it('should generate doc', function *() { + it('should generate doc', async () => { const cwd = path.join(__dirname, '../../fixtures/ts-dir-doc-options'); const child = coffee.fork(midwayBin, [ 'doc', '--options', 'typedoc.js' ], { cwd }); - yield child.expect('code', 0).end(); + await child.expect('code', 0).end(); assert(fs.existsSync(path.join(cwd, 'docs/api/index.html'))); - yield rimraf(path.join(cwd, 'docs')); + await rimraf(path.join(cwd, 'docs')); }); }); diff --git a/packages/midway-bin/test/lib/cmd/index.test.js b/packages/midway-bin/test/lib/cmd/index.test.js index 5ce7846cfadc..975de1e62381 100644 --- a/packages/midway-bin/test/lib/cmd/index.test.js +++ b/packages/midway-bin/test/lib/cmd/index.test.js @@ -8,9 +8,9 @@ const midwayBin = require.resolve('../../../bin/midway-bin.js'); describe('test/lib/cmd/index.test.js', () => { describe('autod command', () => { - it('should stdout', function* () { + it('should stdout', async () => { const cwd = path.join(__dirname); - yield coffee.fork(midwayBin, ['autod', '-h'], {cwd}) + await coffee.fork(midwayBin, [ 'autod', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0) @@ -19,9 +19,9 @@ describe('test/lib/cmd/index.test.js', () => { }); describe('cov command', () => { - it('should stdout', function* () { + it('should stdout', async () => { const cwd = path.join(__dirname); - yield coffee.fork(midwayBin, ['cov', '-h'], {cwd}) + await coffee.fork(midwayBin, [ 'cov', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0) @@ -30,9 +30,9 @@ describe('test/lib/cmd/index.test.js', () => { }); describe('debug command', () => { - it('should stdout', function* () { + it('should stdout', async () => { const cwd = path.join(__dirname); - yield coffee.fork(midwayBin, ['debug', '-h'], {cwd}) + await coffee.fork(midwayBin, [ 'debug', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0) @@ -41,9 +41,9 @@ describe('test/lib/cmd/index.test.js', () => { }); describe('dev command', () => { - it('should stdout', function* () { + it('should stdout', async () => { const cwd = path.join(__dirname); - yield coffee.fork(midwayBin, ['dev', '-h'], {cwd}) + await coffee.fork(midwayBin, [ 'dev', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0) @@ -52,9 +52,9 @@ describe('test/lib/cmd/index.test.js', () => { }); describe('pkg command', () => { - it('should stdout', function* () { + it('should stdout', async () => { const cwd = path.join(__dirname); - yield coffee.fork(midwayBin, ['pkgfiles', '-h'], {cwd}) + await coffee.fork(midwayBin, [ 'pkgfiles', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0) @@ -63,9 +63,9 @@ describe('test/lib/cmd/index.test.js', () => { }); describe('test command', () => { - it('should stdout', function* () { + it('should stdout', async () => { const cwd = path.join(__dirname); - yield coffee.fork(midwayBin, ['test', '-h'], {cwd}) + await coffee.fork(midwayBin, [ 'test', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0) @@ -74,9 +74,9 @@ describe('test/lib/cmd/index.test.js', () => { }); describe('build command', () => { - it('should build ts file', (done) => { + it('should build ts file', done => { const cwd = path.join(__dirname); - coffee.fork(midwayBin, ['build', '-h'], {cwd}) + coffee.fork(midwayBin, [ 'build', '-h' ], { cwd }) // .debug() .expect('stdout', /midway/) .expect('code', 0)