Comparing version 3.0.0-beta-cli.9 to 3.0.0-beta-cli.10
@@ -17,8 +17,16 @@ /// <reference types="node" /> | ||
context?: Ctx; | ||
/** | ||
* A function for generating placeholder migration files. Specify to make sure files generated using `.create` follow team conventions. | ||
* Should return an array of [filepath, content] pairs. Usually, only one pair is needed, but to put `down` migrations in a separate | ||
* file, more than one can be returned. | ||
*/ | ||
template?: (filepath: string) => Array<[string, string]>; | ||
/** Options for file creation */ | ||
create?: { | ||
/** | ||
* A function for generating placeholder migration files. Specify to make sure files generated using `.create` follow team conventions. | ||
* Should return an array of [filepath, content] pairs. Usually, only one pair is needed, but to put `down` migrations in a separate | ||
* file, more than one can be returned. | ||
*/ | ||
template?: (filepath: string) => Array<[string, string]>; | ||
/** | ||
* The default folder that new migration files should be generated in. If this is not specified, the new migration file will be created | ||
* in the same folder as the last existing migration. The value here can be overriden by passing `folder` when calling `create`. | ||
*/ | ||
folder?: string; | ||
}; | ||
} | ||
@@ -25,0 +33,0 @@ /** Serializeable metadata for a migration. The structure returned by the external-facing `pending()` and `executed()` methods. */ |
@@ -168,3 +168,3 @@ "use strict"; | ||
async create(options) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
const isoDate = new Date().toISOString(); | ||
@@ -179,3 +179,2 @@ const prefixes = { | ||
const allowedExtensions = options.allowExtension ? [options.allowExtension] : ['.js', '.ts', '.sql']; | ||
const maybeFolder = options.folder; | ||
const existing = await this.migrations(); | ||
@@ -187,3 +186,3 @@ const last = existing[existing.length - 1]; | ||
} | ||
const folder = maybeFolder || ((last === null || last === void 0 ? void 0 : last.path) && path.dirname(last.path)); | ||
const folder = options.folder || ((_b = this.options.create) === null || _b === void 0 ? void 0 : _b.folder) || ((last === null || last === void 0 ? void 0 : last.path) && path.dirname(last.path)); | ||
if (!folder) { | ||
@@ -193,4 +192,4 @@ throw new Error(`Couldn't infer a directory to generate migration file in. Pass folder explicitly`); | ||
const filepath = path.join(folder, fileBasename); | ||
const writer = (_b = this.options.template) !== null && _b !== void 0 ? _b : Umzug.defaultCreationTemplate; | ||
const toWrite = writer(filepath); | ||
const template = (_d = (_c = this.options.create) === null || _c === void 0 ? void 0 : _c.template) !== null && _d !== void 0 ? _d : Umzug.defaultCreationTemplate; | ||
const toWrite = template(filepath); | ||
if (toWrite.length === 0) { | ||
@@ -211,4 +210,3 @@ toWrite.push([filepath, '']); | ||
fs.writeFileSync(pair[0], pair[1]); | ||
// eslint-disable-next-line no-console | ||
console.log(`Wrote ${pair[0]}`); | ||
this.logging(`Wrote ${pair[0]}`); | ||
}); | ||
@@ -215,0 +213,0 @@ if (!options.skipVerify) { |
{ | ||
"name": "umzug", | ||
"version": "3.0.0-beta-cli.9", | ||
"version": "3.0.0-beta-cli.10", | ||
"description": "Framework-agnostic migration tool for Node", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -705,19 +705,2 @@ # Umzug | ||
By default, placeholder content is included for `.js`, `.ts` and `.sql` migration files. You can override the template content or provide a template for other file types by creating a template module to generate code according to your project's convention. The default export should be a function which receives a filepath and returns an array of `[filepath, content]` pairs. Example: | ||
```javascript | ||
// my-template.js | ||
exports.default = filepath => [ | ||
[filepath, `exports.up = () => console.log('running up migration!');`] | ||
] | ||
``` | ||
Use the template by passing it as a cli parameter: | ||
``` | ||
node my-umzug-migrator create --name my-migration.js --template path/to/my-template.js | ||
``` | ||
This parameter may alternatively be specified via the `UMZUG_MIGRATION_TEMPLATE` environment variable, to avoid having to pass the path explicitly every time. | ||
Use `node my-umzug-migrator create --help` for more options: | ||
@@ -724,0 +707,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1164
113820
758