UNPKG

@strapi/generators

Version:

Interactive API generator.

1 lines 2.07 kB
{"version":3,"file":"migration.mjs","sources":["../../src/plops/migration.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport validateFileNameInput from './utils/validate-file-name-input';\nimport getFormattedDate from './utils/get-formatted-date';\n\nexport default (plop: NodePlopAPI) => {\n // Migration generator\n plop.setGenerator('migration', {\n description: 'Generate a migration',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Migration name',\n validate: (input) => validateFileNameInput(input),\n },\n ],\n actions() {\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n const timestamp = getFormattedDate();\n\n return [\n {\n type: 'add',\n path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,\n templateFile: `templates/${language}/migration.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateFileNameInput","actions","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","timestamp","getFormattedDate","path","templateFile"],"mappings":";;;;AAKA,wBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,WAAa,EAAA;QAC7BC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,gBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,qBAAsBD,CAAAA,KAAAA;AAC7C;AACD,SAAA;AACDE,QAAAA,OAAAA,CAAAA,GAAAA;YACE,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;AACpE,YAAA,MAAMM,SAAYC,GAAAA,gBAAAA,EAAAA;YAElB,OAAO;AACL,gBAAA;oBACEd,IAAM,EAAA,KAAA;AACNe,oBAAAA,IAAAA,EAAM,GAAGR,UAAW,CAAA,qBAAqB,EAAEM,SAAU,CAAA,YAAY,EAAEH,QAAU,CAAA,CAAA;oBAC7EM,YAAc,EAAA,CAAC,UAAU,EAAEN,QAAAA,CAAS,WAAW,EAAEA,QAAAA,CAAS,IAAI;AAChE;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}