fix(cli): allow creating new migration files with only the "extension" option
This commit is contained in:
parent
b56794a269
commit
a1debba2e1
2 changed files with 19 additions and 8 deletions
5
.changeset/unlucky-files-swim.md
Normal file
5
.changeset/unlucky-files-swim.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@emigrate/cli': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix a logical error that didn't allow creating new migration files with only the "extension" option
|
||||||
|
|
@ -37,24 +37,30 @@ export default async function newCommand({ directory, template, plugins = [], ex
|
||||||
filename = `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.${stripLeadingPeriod(
|
filename = `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.${stripLeadingPeriod(
|
||||||
extension ?? fileExtension,
|
extension ?? fileExtension,
|
||||||
)}`;
|
)}`;
|
||||||
} else if (plugins.length > 0) {
|
}
|
||||||
|
|
||||||
|
let hasGeneratedFile = Boolean(filename && content !== undefined);
|
||||||
|
|
||||||
|
if (plugins.length > 0 && !hasGeneratedFile) {
|
||||||
const generatorPlugin = await getOrLoadPlugin('generator', plugins);
|
const generatorPlugin = await getOrLoadPlugin('generator', plugins);
|
||||||
|
|
||||||
if (!generatorPlugin) {
|
if (generatorPlugin) {
|
||||||
throw new Error('No generator plugin found, please specify a generator plugin using the plugin option');
|
const generated = await generatorPlugin.generateMigration(name);
|
||||||
|
|
||||||
|
filename = generated.filename;
|
||||||
|
content = generated.content;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const generated = await generatorPlugin.generateMigration(name);
|
hasGeneratedFile = Boolean(filename && content !== undefined);
|
||||||
|
|
||||||
filename = generated.filename;
|
if (extension && !hasGeneratedFile) {
|
||||||
content = generated.content;
|
|
||||||
} else if (extension) {
|
|
||||||
content = '';
|
content = '';
|
||||||
filename = `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.${stripLeadingPeriod(extension)}`;
|
filename = `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.${stripLeadingPeriod(extension)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename || content === undefined) {
|
if (!filename || content === undefined) {
|
||||||
throw new Error('Unexpected error, missing filename or content for migration file');
|
throw new ShowUsageError('No generator plugin found, please specify a generator plugin using the plugin option');
|
||||||
}
|
}
|
||||||
|
|
||||||
const directoryPath = path.resolve(process.cwd(), directory);
|
const directoryPath = path.resolve(process.cwd(), directory);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue