Add ability to log schema changes with rondo cmd
New command:
rondo schemaLog <path/to/package>
cd path/to/package
rondo schemaLog
Also update migrations index.ts after creating migration:
rondo createMigration [-p path/to/package] <name>
This commit is contained in:
parent
c82967012b
commit
3b7dcd9cb7
@ -1,11 +1,19 @@
|
|||||||
import { getPathVariable } from './modules'
|
import { getPathVariable } from './modules'
|
||||||
import { Subprocess } from './Subprocess'
|
import { Subprocess } from './Subprocess'
|
||||||
|
|
||||||
export async function run(command: string, args: string[], cwd?: string) {
|
export interface RunOptions {
|
||||||
|
cwd?: string
|
||||||
|
env?: Record<string, string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function run(command: string, args: string[], opts?: RunOptions) {
|
||||||
|
const env = opts && opts.env || {}
|
||||||
|
const cwd = opts && opts.cwd
|
||||||
return new Subprocess(command, args, {
|
return new Subprocess(command, args, {
|
||||||
...process.env,
|
...process.env,
|
||||||
PATH: getPathVariable(),
|
PATH: getPathVariable(),
|
||||||
FORCE_COLOR: '1',
|
FORCE_COLOR: '1',
|
||||||
|
...env,
|
||||||
})
|
})
|
||||||
.run(cwd)
|
.run(cwd)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {argparse, arg} from '@rondo.dev/argparse'
|
|||||||
import {findNodeModules} from '../modules'
|
import {findNodeModules} from '../modules'
|
||||||
import {join} from 'path'
|
import {join} from 'path'
|
||||||
import {run} from '../run'
|
import {run} from '../run'
|
||||||
|
import { exportDir } from './exportDir'
|
||||||
|
|
||||||
const tsc = 'ttsc'
|
const tsc = 'ttsc'
|
||||||
|
|
||||||
@ -69,23 +70,49 @@ export async function exec(...argv: string[]) {
|
|||||||
}
|
}
|
||||||
exec.help = 'Execute a js or ts file using node or ts-node'
|
exec.help = 'Execute a js or ts file using node or ts-node'
|
||||||
|
|
||||||
|
function findTypeORM(project: string) {
|
||||||
|
const typeorm = findNodeModules(project)
|
||||||
|
.map(nm => p.join(nm, 'typeorm'))
|
||||||
|
.find(t => fs.existsSync(t))
|
||||||
|
|
||||||
|
if (!typeorm) {
|
||||||
|
throw new Error('typeorm not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeorm
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function schemaLog(...argv: string[]) {
|
||||||
|
const args = argparse({
|
||||||
|
project: arg('string', {positional: true, default: '.'}),
|
||||||
|
}, schemaLog.help)
|
||||||
|
.parse(argv)
|
||||||
|
|
||||||
|
const { project } = args
|
||||||
|
|
||||||
|
const typeorm = findTypeORM(project)
|
||||||
|
await run('ts-node', [typeorm, 'schema:log'], {
|
||||||
|
cwd: project,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
schemaLog.help = 'Logs schema changes'
|
||||||
|
|
||||||
export async function createMigration(...argv: string[]) {
|
export async function createMigration(...argv: string[]) {
|
||||||
const args = argparse({
|
const args = argparse({
|
||||||
name: arg('string', {required: true, positional: true}),
|
name: arg('string', {required: true, positional: true}),
|
||||||
project: arg('string', {alias: 'p', default: '.'}),
|
project: arg('string', {alias: 'p', default: '.'}),
|
||||||
help: arg('boolean', {alias: 'h'}),
|
help: arg('boolean', {alias: 'h'}),
|
||||||
|
log: arg('boolean', {description: 'Only log schema'}),
|
||||||
}, createMigration.help)
|
}, createMigration.help)
|
||||||
.parse(argv)
|
.parse(argv)
|
||||||
|
|
||||||
const {name, project} = args
|
const {name, project} = args
|
||||||
|
|
||||||
const typeorm = findNodeModules(project)
|
const typeorm = findTypeORM(project)
|
||||||
.map(nm => p.join(nm, 'typeorm'))
|
await run('ts-node', [typeorm, 'migration:generate', '--name', name], {
|
||||||
.find(t => fs.existsSync(t))
|
cwd: project,
|
||||||
if (!typeorm) {
|
})
|
||||||
throw new Error('typeorm not found')
|
await exportDir(argv[0], project)
|
||||||
}
|
|
||||||
await run('ts-node', [typeorm, 'migration:generate', '--name', name], project)
|
|
||||||
}
|
}
|
||||||
createMigration.help = 'Generate a new TypeORM migration'
|
createMigration.help = 'Generate a new TypeORM migration'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user