@strapi/generators 4.7.2-exp.175f7ac70ee76d6c825e4429e15fc85ee78d23bb → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/plopfile.js CHANGED
@@ -8,6 +8,7 @@ const generateContentType = require('./plops/content-type');
8
8
  const generatePlugin = require('./plops/plugin');
9
9
  const generatePolicy = require('./plops/policy');
10
10
  const generateMiddleware = require('./plops/middleware');
11
+ const generateMigration = require('./plops/migration');
11
12
  const generateService = require('./plops/service');
12
13
 
13
14
  module.exports = (plop) => {
@@ -22,5 +23,6 @@ module.exports = (plop) => {
22
23
  generatePlugin(plop);
23
24
  generatePolicy(plop);
24
25
  generateMiddleware(plop);
26
+ generateMigration(plop);
25
27
  generateService(plop);
26
28
  };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const tsUtils = require('@strapi/typescript-utils');
4
+ const validateFileNameInput = require('./utils/validate-file-name-input');
5
+ const getFormattedDate = require('./utils/get-formatted-date');
6
+
7
+ module.exports = (plop) => {
8
+ // Migration generator
9
+ plop.setGenerator('migration', {
10
+ description: 'Generate a migration',
11
+ prompts: [
12
+ {
13
+ type: 'input',
14
+ name: 'name',
15
+ message: 'Migration name',
16
+ validate: (input) => validateFileNameInput(input),
17
+ },
18
+ ],
19
+ actions() {
20
+ const currentDir = process.cwd();
21
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
22
+ const timestamp = getFormattedDate();
23
+
24
+ return [
25
+ {
26
+ type: 'add',
27
+ path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
28
+ templateFile: `templates/${language}/migration.${language}.hbs`,
29
+ },
30
+ ];
31
+ },
32
+ });
33
+ };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports = (date = new Date()) => {
4
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000)
5
+ .toJSON()
6
+ .replace(/[-:]/g, '.')
7
+ .replace(/\....Z/, '');
8
+ };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ module.exports = (input) => {
4
+ const regex = /^[A-Za-z-_0-9]+$/g;
5
+
6
+ if (!input) {
7
+ return 'You must provide an input';
8
+ }
9
+
10
+ return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces";
11
+ };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Migration `{{ name }}`
5
+ */
6
+
7
+ module.exports = {
8
+ /**
9
+ *
10
+ * @param {import('knex').Knex} knex
11
+ */
12
+ async up(knex) {
13
+
14
+ },
15
+ };
@@ -0,0 +1,11 @@
1
+ import type { Knex } from 'knex';
2
+
3
+ /**
4
+ * Migration `{{ name }}`
5
+ */
6
+
7
+ export default {
8
+ up: async (knex: Knex) => {
9
+
10
+ },
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/generators",
3
- "version": "4.7.2-exp.175f7ac70ee76d6c825e4429e15fc85ee78d23bb",
3
+ "version": "4.8.0",
4
4
  "description": "Interactive API generator.",
5
5
  "keywords": [
6
6
  "strapi",
@@ -30,8 +30,8 @@
30
30
  "main": "lib/index.js",
31
31
  "dependencies": {
32
32
  "@sindresorhus/slugify": "1.1.0",
33
- "@strapi/typescript-utils": "4.7.2-exp.175f7ac70ee76d6c825e4429e15fc85ee78d23bb",
34
- "@strapi/utils": "4.7.2-exp.175f7ac70ee76d6c825e4429e15fc85ee78d23bb",
33
+ "@strapi/typescript-utils": "4.8.0",
34
+ "@strapi/utils": "4.8.0",
35
35
  "chalk": "4.1.2",
36
36
  "fs-extra": "10.0.0",
37
37
  "node-plop": "0.26.3",
@@ -42,5 +42,5 @@
42
42
  "node": ">=14.19.1 <=18.x.x",
43
43
  "npm": ">=6.0.0"
44
44
  },
45
- "gitHead": "175f7ac70ee76d6c825e4429e15fc85ee78d23bb"
45
+ "gitHead": "e239e408f99c9e61e6d02b38f01632ce67412f2a"
46
46
  }