Add createMigration task
This commit is contained in:
parent
3690908918
commit
745834848f
@ -15,13 +15,14 @@ export class Subprocess {
|
|||||||
public readonly stdio: StdioOptions = StdioOptions.PIPE,
|
public readonly stdio: StdioOptions = StdioOptions.PIPE,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async run() {
|
async run(cwd?: string) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
process.stderr.write(`> ${this.command} ${this.args.join(' ')}\n`)
|
process.stderr.write(`> ${this.command} ${this.args.join(' ')}\n`)
|
||||||
const subprocess = spawn(this.command, this.args, {
|
const subprocess = spawn(this.command, this.args, {
|
||||||
shell: false,
|
shell: false,
|
||||||
stdio: this.stdio,
|
stdio: this.stdio,
|
||||||
env: this.environment,
|
env: this.environment,
|
||||||
|
cwd,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.stdio === StdioOptions.PIPE) {
|
if (this.stdio === StdioOptions.PIPE) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import {run} from '../run'
|
import {run} from '../run'
|
||||||
import {join} from 'path'
|
import {join} from 'path'
|
||||||
|
import {findNodeModules} from '../modules'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as p from 'path'
|
import * as p from 'path'
|
||||||
|
|
||||||
@ -38,7 +39,17 @@ export async function exec(file: string) {
|
|||||||
'--project',
|
'--project',
|
||||||
findTsConfig(file),
|
findTsConfig(file),
|
||||||
] : []
|
] : []
|
||||||
return run(command, [...args, file])
|
await run(command, [...args, file])
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createMigration(project: string, name: string) {
|
||||||
|
const typeorm = findNodeModules(project)
|
||||||
|
.map(nm => p.join(nm, 'typeorm'))
|
||||||
|
.find(t => fs.existsSync(t))
|
||||||
|
if (!typeorm) {
|
||||||
|
throw new Error('typeorm not found')
|
||||||
|
}
|
||||||
|
await run('ts-node', [typeorm, 'migration:create', '--name', name], project)
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTsConfig(file: string): string {
|
function findTsConfig(file: string): string {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import {Subprocess} from './Subprocess'
|
import {Subprocess} from './Subprocess'
|
||||||
import {getPathVariable} from './modules'
|
import {getPathVariable} from './modules'
|
||||||
|
|
||||||
export async function run(command: string, args: string[]) {
|
export async function run(command: string, args: string[], cwd?: string) {
|
||||||
return new Subprocess(command, args, {
|
return new Subprocess(command, args, {
|
||||||
...process.env,
|
...process.env,
|
||||||
PATH: getPathVariable(),
|
PATH: getPathVariable(),
|
||||||
})
|
})
|
||||||
.run()
|
.run(cwd)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user