From b32e68c9f1dc764b952431ee631d16f2dd39ddb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= Date: Wed, 18 Aug 2021 18:10:24 +0200 Subject: [PATCH 01/26] Create new plop generator --- .../core/strapi/lib/commands/generate-plop.js | 0 .../generators/generate-plop/package.json | 10 ++++++++ packages/generators/generate-plop/plopfile.js | 24 +++++++++++++++++++ .../generate-plop/templates/service.js.hbs | 11 +++++++++ 4 files changed, 45 insertions(+) create mode 100644 packages/core/strapi/lib/commands/generate-plop.js create mode 100644 packages/generators/generate-plop/package.json create mode 100644 packages/generators/generate-plop/plopfile.js create mode 100644 packages/generators/generate-plop/templates/service.js.hbs diff --git a/packages/core/strapi/lib/commands/generate-plop.js b/packages/core/strapi/lib/commands/generate-plop.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/generators/generate-plop/package.json b/packages/generators/generate-plop/package.json new file mode 100644 index 0000000000..900c86e010 --- /dev/null +++ b/packages/generators/generate-plop/package.json @@ -0,0 +1,10 @@ +{ + "name": "service-plop", + "version": "3.6.6", + "description": "Generate a service for a Strapi API.", + "main": "index.js", + "license": "MIT", + "dependencies": { + "plop": "2.7.4" + } +} diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js new file mode 100644 index 0000000000..4ee8f1f733 --- /dev/null +++ b/packages/generators/generate-plop/plopfile.js @@ -0,0 +1,24 @@ +'use strict'; + +const { join } = require('path'); + +module.exports = function(plop) { + // Service generator + plop.setGenerator('service', { + description: 'application service logic', + prompts: [ + { + type: 'input', + name: 'id', + message: 'service name please', + }, + ], + actions: [ + { + type: 'add', + path: join(process.cwd(), 'api/{{id}}/services/{{id}}.js'), + templateFile: 'templates/service.js.hbs', + }, + ], + }); +}; diff --git a/packages/generators/generate-plop/templates/service.js.hbs b/packages/generators/generate-plop/templates/service.js.hbs new file mode 100644 index 0000000000..13861b3c1d --- /dev/null +++ b/packages/generators/generate-plop/templates/service.js.hbs @@ -0,0 +1,11 @@ +'use strict'; + +/** + * {{id}} service. + */ + +module.exports = { + // exampleService: (arg1, arg2) => { + // return isUserOnline(arg1, arg2); + // } +}; From 4e19ff006fd53beebf31929e5989970e700afb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= Date: Thu, 19 Aug 2021 11:49:55 +0200 Subject: [PATCH 02/26] Prompt wording --- packages/generators/generate-plop/plopfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js index 4ee8f1f733..4e59a228ae 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate-plop/plopfile.js @@ -5,12 +5,12 @@ const { join } = require('path'); module.exports = function(plop) { // Service generator plop.setGenerator('service', { - description: 'application service logic', + description: 'Generate a service for an API', prompts: [ { type: 'input', name: 'id', - message: 'service name please', + message: 'Service name', }, ], actions: [ From e9d19733201b203486eb382ec2be011e503215ce Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Thu, 19 Aug 2021 14:15:25 +0200 Subject: [PATCH 03/26] add models --- .../core/strapi/lib/commands/generate-plop.js | 0 packages/generators/generate-plop/plopfile.js | 29 +++++++++++++++++++ .../generate-plop/templates/model.js.hbs | 8 +++++ .../templates/model.settings.json.hbs | 13 +++++++++ 4 files changed, 50 insertions(+) delete mode 100644 packages/core/strapi/lib/commands/generate-plop.js create mode 100644 packages/generators/generate-plop/templates/model.js.hbs create mode 100644 packages/generators/generate-plop/templates/model.settings.json.hbs diff --git a/packages/core/strapi/lib/commands/generate-plop.js b/packages/core/strapi/lib/commands/generate-plop.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js index 4e59a228ae..92a59437ac 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate-plop/plopfile.js @@ -21,4 +21,33 @@ module.exports = function(plop) { }, ], }); + + // Model generator + plop.setGenerator('model', { + description: 'application model logic', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Model name', + }, + { + type: 'confirm', + name: 'useDraftAndPublish', + message: 'Use draft and publish?', + }, + ], + actions: [ + { + type: 'add', + path: join(process.cwd(), 'api/{{id}}/models/{{id}}.js'), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(process.cwd(), 'api/{{id}}/models/{{id}}.settings.json'), + templateFile: 'templates/model.settings.json.hbs', + }, + ], + }); }; diff --git a/packages/generators/generate-plop/templates/model.js.hbs b/packages/generators/generate-plop/templates/model.js.hbs new file mode 100644 index 0000000000..dd847efdda --- /dev/null +++ b/packages/generators/generate-plop/templates/model.js.hbs @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/concepts/models.html#lifecycle-hooks) + * to customize this model + */ + +module.exports = {}; diff --git a/packages/generators/generate-plop/templates/model.settings.json.hbs b/packages/generators/generate-plop/templates/model.settings.json.hbs new file mode 100644 index 0000000000..8e685c01da --- /dev/null +++ b/packages/generators/generate-plop/templates/model.settings.json.hbs @@ -0,0 +1,13 @@ + +{ + "kind": "collectionType", + "collectionName": "{{id}}", + "info": { + "name": "{{id}}" + }, + "options": { + "draftAndPublish": {{useDraftAndPublish}}, + "comment": "" + }, + "attributes": {} +} \ No newline at end of file From 63be221944552faf0bc80d38270d4bac01974e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= Date: Thu, 19 Aug 2021 17:05:16 +0200 Subject: [PATCH 04/26] Add policy and controller generators (#10760) --- packages/generators/generate-plop/plopfile.js | 38 +++++++++++++++++++ .../generate-plop/templates/controller.js.hbs | 15 ++++++++ .../generate-plop/templates/policy.js.hbs | 12 ++++++ 3 files changed, 65 insertions(+) create mode 100644 packages/generators/generate-plop/templates/controller.js.hbs create mode 100644 packages/generators/generate-plop/templates/policy.js.hbs diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js index 92a59437ac..d3d469b8ff 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate-plop/plopfile.js @@ -50,4 +50,42 @@ module.exports = function(plop) { }, ], }); + + // Controller generator + plop.setGenerator('controller', { + description: 'Generate a controller for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Controller name', + }, + ], + actions: [ + { + type: 'add', + path: join(process.cwd(), 'api/{{id}}/controllers/{{id}}.js'), + templateFile: 'templates/controller.js.hbs', + }, + ], + }); + + // Policy generator + plop.setGenerator('policy', { + description: 'Generate a policy', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Policy name', + }, + ], + actions: [ + { + type: 'add', + path: join(process.cwd(), 'config/policies/{{id}}.js'), + templateFile: 'templates/policy.js.hbs', + }, + ], + }); }; diff --git a/packages/generators/generate-plop/templates/controller.js.hbs b/packages/generators/generate-plop/templates/controller.js.hbs new file mode 100644 index 0000000000..e8d1615d32 --- /dev/null +++ b/packages/generators/generate-plop/templates/controller.js.hbs @@ -0,0 +1,15 @@ +'use strict'; + +/** + * A set of functions called "actions" for `{{id}}` + */ + +module.exports = { + // exampleAction: async (ctx, next) => { + // try { + // ctx.body = 'ok'; + // } catch (err) { + // ctx.body = err; + // } + // } +}; diff --git a/packages/generators/generate-plop/templates/policy.js.hbs b/packages/generators/generate-plop/templates/policy.js.hbs new file mode 100644 index 0000000000..ae641e82d1 --- /dev/null +++ b/packages/generators/generate-plop/templates/policy.js.hbs @@ -0,0 +1,12 @@ +'use strict'; + +/** + * `{{id}}` policy. + */ + +module.exports = async (ctx, next) => { + // Add your own logic here. + console.log('In {{id}} policy.'); + + await next(); +}; From 10bf5d39879a47b15fbbd155f58ccbd9828ca765 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Thu, 19 Aug 2021 16:42:48 +0200 Subject: [PATCH 05/26] add plugin generator --- .../files/admin/src/containers/App/index.js | 25 +++++ .../admin/src/containers/HomePage/index.js | 20 ++++ .../admin/src/containers/Initializer/index.js | 26 +++++ .../generate-plop/files/admin/src/index.js | 62 +++++++++++ .../generate-plop/files/admin/src/pluginId.js | 5 + .../files/admin/src/translations/en.json | 1 + .../files/admin/src/translations/fr.json | 1 + .../files/admin/src/utils/getTrad.js | 5 + .../generators/generate-plop/package.json | 1 + packages/generators/generate-plop/plopfile.js | 69 ++++++++++-- .../generate-plop/templates/.editorconfig | 7 ++ .../generate-plop/templates/.gitattributes | 103 ++++++++++++++++++ .../generate-plop/templates/.gitignore | 10 ++ .../generate-plop/templates/README.md.hbs | 3 + .../templates/plugin-package.json.hbs | 28 +++++ .../generate-plop/templates/routes.json.hbs | 12 ++ 16 files changed, 371 insertions(+), 7 deletions(-) create mode 100644 packages/generators/generate-plop/files/admin/src/containers/App/index.js create mode 100644 packages/generators/generate-plop/files/admin/src/containers/HomePage/index.js create mode 100644 packages/generators/generate-plop/files/admin/src/containers/Initializer/index.js create mode 100644 packages/generators/generate-plop/files/admin/src/index.js create mode 100644 packages/generators/generate-plop/files/admin/src/pluginId.js create mode 100644 packages/generators/generate-plop/files/admin/src/translations/en.json create mode 100644 packages/generators/generate-plop/files/admin/src/translations/fr.json create mode 100644 packages/generators/generate-plop/files/admin/src/utils/getTrad.js create mode 100644 packages/generators/generate-plop/templates/.editorconfig create mode 100644 packages/generators/generate-plop/templates/.gitattributes create mode 100644 packages/generators/generate-plop/templates/.gitignore create mode 100644 packages/generators/generate-plop/templates/README.md.hbs create mode 100644 packages/generators/generate-plop/templates/plugin-package.json.hbs create mode 100644 packages/generators/generate-plop/templates/routes.json.hbs diff --git a/packages/generators/generate-plop/files/admin/src/containers/App/index.js b/packages/generators/generate-plop/files/admin/src/containers/App/index.js new file mode 100644 index 0000000000..b2d80ef744 --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/containers/App/index.js @@ -0,0 +1,25 @@ +/** + * + * This component is the skeleton around the actual pages, and should only + * contain code that should be seen on all pages. (e.g. navigation bar) + * + */ + +import React from 'react'; +import { Switch, Route } from 'react-router-dom'; +import { NotFound } from '@strapi/helper-plugin'; +import pluginId from '../../pluginId'; +import HomePage from '../HomePage'; + +const App = () => { + return ( +
+ + + + +
+ ); +}; + +export default App; diff --git a/packages/generators/generate-plop/files/admin/src/containers/HomePage/index.js b/packages/generators/generate-plop/files/admin/src/containers/HomePage/index.js new file mode 100644 index 0000000000..05c5a6a377 --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/containers/HomePage/index.js @@ -0,0 +1,20 @@ +/* + * + * HomePage + * + */ + +import React, { memo } from 'react'; +// import PropTypes from 'prop-types'; +import pluginId from '../../pluginId'; + +const HomePage = () => { + return ( +
+

{pluginId}'s HomePage

+

Happy coding

+
+ ); +}; + +export default memo(HomePage); diff --git a/packages/generators/generate-plop/files/admin/src/containers/Initializer/index.js b/packages/generators/generate-plop/files/admin/src/containers/Initializer/index.js new file mode 100644 index 0000000000..71dc50e94c --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/containers/Initializer/index.js @@ -0,0 +1,26 @@ +/** + * + * Initializer + * + */ + +import { useEffect, useRef } from 'react'; +import PropTypes from 'prop-types'; +import pluginId from '../../pluginId'; + +const Initializer = ({ setPlugin }) => { + const ref = useRef(); + ref.current = setPlugin; + + useEffect(() => { + ref.current(pluginId); + }, []); + + return null; +}; + +Initializer.propTypes = { + setPlugin: PropTypes.func.isRequired, +}; + +export default Initializer; diff --git a/packages/generators/generate-plop/files/admin/src/index.js b/packages/generators/generate-plop/files/admin/src/index.js new file mode 100644 index 0000000000..704e4277d8 --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/index.js @@ -0,0 +1,62 @@ +import { prefixPluginTranslations } from '@strapi/helper-plugin'; +import pluginPkg from '../../package.json'; +import pluginId from './pluginId'; +import App from './containers/App'; +import Initializer from './containers/Initializer'; + +const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; +const icon = pluginPkg.strapi.icon; +const name = pluginPkg.strapi.name; + +export default { + register(app) { + app.addMenuLink({ + to: `/plugins/${pluginId}`, + icon, + intlLabel: { + id: `${pluginId}.plugin.name`, + defaultMessage: name, + }, + Component: App, + permissions: [ + // Uncomment to set the permissions of the plugin here + // { + // action: '', // the action name should be plugins::plugin-name.actionType + // subject: null, + // }, + ], + }); + app.registerPlugin({ + description: pluginDescription, + icon, + id: pluginId, + initializer: Initializer, + isReady: false, + isRequired: pluginPkg.strapi.required || false, + name, + }); + }, + // eslint-disable-next-line + bootstrap(app) {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import(`./translations/${locale}.json`) + .then(({ default: data }) => { + return { + data: prefixPluginTranslations(data, pluginId), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, +}; diff --git a/packages/generators/generate-plop/files/admin/src/pluginId.js b/packages/generators/generate-plop/files/admin/src/pluginId.js new file mode 100644 index 0000000000..f604a009da --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/pluginId.js @@ -0,0 +1,5 @@ +const pluginPkg = require('../../package.json'); + +const pluginId = pluginPkg.name.replace(/^@strapi\/plugin-/i, ''); + +module.exports = pluginId; diff --git a/packages/generators/generate-plop/files/admin/src/translations/en.json b/packages/generators/generate-plop/files/admin/src/translations/en.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/translations/en.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/generators/generate-plop/files/admin/src/translations/fr.json b/packages/generators/generate-plop/files/admin/src/translations/fr.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/translations/fr.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/generators/generate-plop/files/admin/src/utils/getTrad.js b/packages/generators/generate-plop/files/admin/src/utils/getTrad.js new file mode 100644 index 0000000000..a2b8632a8d --- /dev/null +++ b/packages/generators/generate-plop/files/admin/src/utils/getTrad.js @@ -0,0 +1,5 @@ +import pluginId from '../pluginId'; + +const getTrad = id => `${pluginId}.${id}`; + +export default getTrad; diff --git a/packages/generators/generate-plop/package.json b/packages/generators/generate-plop/package.json index 900c86e010..d241f5842d 100644 --- a/packages/generators/generate-plop/package.json +++ b/packages/generators/generate-plop/package.json @@ -5,6 +5,7 @@ "main": "index.js", "license": "MIT", "dependencies": { + "fs-extra": "10.0.0", "plop": "2.7.4" } } diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js index d3d469b8ff..2640a23c7f 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate-plop/plopfile.js @@ -1,8 +1,12 @@ 'use strict'; const { join } = require('path'); +const fs = require('fs-extra'); module.exports = function(plop) { + const rootDir = process.cwd(); + plop.setWelcomeMessage('Strapi Generators'); + // Service generator plop.setGenerator('service', { description: 'Generate a service for an API', @@ -16,7 +20,7 @@ module.exports = function(plop) { actions: [ { type: 'add', - path: join(process.cwd(), 'api/{{id}}/services/{{id}}.js'), + path: join(rootDir, 'api/{{id}}/services/{{id}}.js'), templateFile: 'templates/service.js.hbs', }, ], @@ -24,7 +28,7 @@ module.exports = function(plop) { // Model generator plop.setGenerator('model', { - description: 'application model logic', + description: 'Generate a model for an API', prompts: [ { type: 'input', @@ -40,12 +44,12 @@ module.exports = function(plop) { actions: [ { type: 'add', - path: join(process.cwd(), 'api/{{id}}/models/{{id}}.js'), + path: join(rootDir, 'api/{{id}}/models/{{id}}.js'), templateFile: 'templates/model.js.hbs', }, { type: 'add', - path: join(process.cwd(), 'api/{{id}}/models/{{id}}.settings.json'), + path: join(rootDir, 'api/{{id}}/models/{{id}}.settings.json'), templateFile: 'templates/model.settings.json.hbs', }, ], @@ -64,7 +68,7 @@ module.exports = function(plop) { actions: [ { type: 'add', - path: join(process.cwd(), 'api/{{id}}/controllers/{{id}}.js'), + path: join(rootDir, 'api/{{id}}/controllers/{{id}}.js'), templateFile: 'templates/controller.js.hbs', }, ], @@ -72,7 +76,7 @@ module.exports = function(plop) { // Policy generator plop.setGenerator('policy', { - description: 'Generate a policy', + description: 'Generate a policy for an API', prompts: [ { type: 'input', @@ -83,9 +87,60 @@ module.exports = function(plop) { actions: [ { type: 'add', - path: join(process.cwd(), 'config/policies/{{id}}.js'), + path: join(rootDir, 'config/policies/{{id}}.js'), templateFile: 'templates/policy.js.hbs', }, ], }); + + // Plugin generator + plop.setGenerator('plugin', { + description: 'Generate a basic plugin', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Plugin name', + }, + ], + actions: data => { + fs.copySync(join(__dirname, 'files', 'admin'), join(rootDir, 'plugins', data.id, 'admin')); + + return [ + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/services/{{id}}.js'), + templateFile: 'templates/service.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/controllers/{{id}}.js'), + templateFile: 'templates/controller.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/config/routes.json'), + templateFile: 'templates/routes.json.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/README.md'), + templateFile: 'templates/README.md.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/package.json'), + templateFile: 'templates/plugin-package.json.hbs', + }, + { + destination: join(rootDir, 'plugins/{{id}}'), + type: 'addMany', + templateFiles: 'templates/.*', + globOptions: { + dot: true, + }, + }, + ]; + }, + }); }; diff --git a/packages/generators/generate-plop/templates/.editorconfig b/packages/generators/generate-plop/templates/.editorconfig new file mode 100644 index 0000000000..d4eed8406b --- /dev/null +++ b/packages/generators/generate-plop/templates/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = false +indent_style = space +indent_size = 2 diff --git a/packages/generators/generate-plop/templates/.gitattributes b/packages/generators/generate-plop/templates/.gitattributes new file mode 100644 index 0000000000..065a11c71d --- /dev/null +++ b/packages/generators/generate-plop/templates/.gitattributes @@ -0,0 +1,103 @@ +# From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes + +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +* text=auto + +# +# The above will handle all files NOT found below +# + +# +## These files are text and should be normalized (Convert crlf => lf) +# + +# source code +*.php text +*.css text +*.sass text +*.scss text +*.less text +*.styl text +*.js text eol=lf +*.coffee text +*.json text +*.htm text +*.html text +*.xml text +*.svg text +*.txt text +*.ini text +*.inc text +*.pl text +*.rb text +*.py text +*.scm text +*.sql text +*.sh text +*.bat text + +# templates +*.ejs text +*.hbt text +*.jade text +*.haml text +*.hbs text +*.dot text +*.tmpl text +*.phtml text + +# git config +.gitattributes text +.gitignore text +.gitconfig text + +# code analysis config +.jshintrc text +.jscsrc text +.jshintignore text +.csslintrc text + +# misc config +*.yaml text +*.yml text +.editorconfig text + +# build config +*.npmignore text +*.bowerrc text + +# Heroku +Procfile text +.slugignore text + +# Documentation +*.md text +LICENSE text +AUTHORS text + + +# +## These files are binary and should be left untouched +# + +# (binary is a macro for -text -diff) +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.mov binary +*.mp4 binary +*.mp3 binary +*.flv binary +*.fla binary +*.swf binary +*.gz binary +*.zip binary +*.7z binary +*.ttf binary +*.eot binary +*.woff binary +*.pyc binary +*.pdf binary diff --git a/packages/generators/generate-plop/templates/.gitignore b/packages/generators/generate-plop/templates/.gitignore new file mode 100644 index 0000000000..afe256bf30 --- /dev/null +++ b/packages/generators/generate-plop/templates/.gitignore @@ -0,0 +1,10 @@ +# Don't check auto-generated stuff into git +coverage +node_modules +stats.json +package-lock.json + +# Cruft +.DS_Store +npm-debug.log +.idea diff --git a/packages/generators/generate-plop/templates/README.md.hbs b/packages/generators/generate-plop/templates/README.md.hbs new file mode 100644 index 0000000000..c0073e2006 --- /dev/null +++ b/packages/generators/generate-plop/templates/README.md.hbs @@ -0,0 +1,3 @@ +# Strapi plugin {{id}} + +A quick description of {{id}}. diff --git a/packages/generators/generate-plop/templates/plugin-package.json.hbs b/packages/generators/generate-plop/templates/plugin-package.json.hbs new file mode 100644 index 0000000000..75bec5a029 --- /dev/null +++ b/packages/generators/generate-plop/templates/plugin-package.json.hbs @@ -0,0 +1,28 @@ +{ + "name": "strapi-plugin-{{id}}", + "version": "0.0.0", + "description": "This is the description of the plugin.", + "strapi": { + "name": "{{id}}", + "icon": "plug", + "description": "Description of {{id}} plugin." + }, + "dependencies": {}, + "author": { + "name": "A Strapi developer", + "email": "", + "url": "" + }, + "maintainers": [ + { + "name": "A Strapi developer", + "email": "", + "url": "" + } + ], + "engines": { + "node": ">=12.x. <=14.x.x", + "npm": ">=6.0.0" + }, + "license": "MIT" +} \ No newline at end of file diff --git a/packages/generators/generate-plop/templates/routes.json.hbs b/packages/generators/generate-plop/templates/routes.json.hbs new file mode 100644 index 0000000000..1de66cd215 --- /dev/null +++ b/packages/generators/generate-plop/templates/routes.json.hbs @@ -0,0 +1,12 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/", + "handler": "{{id}}.index", + "config": { + "policies": [] + } + } + ] +} \ No newline at end of file From ef028c983d453aaaaeee7e0e7e7d0de279d28612 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 20 Aug 2021 09:36:40 +0200 Subject: [PATCH 06/26] move dot files to files folder --- .../{templates => files/plugin}/.editorconfig | 0 .../{templates => files/plugin}/.gitattributes | 0 .../{templates => files/plugin}/.gitignore | 0 .../{ => plugin}/admin/src/containers/App/index.js | 0 .../admin/src/containers/HomePage/index.js | 0 .../admin/src/containers/Initializer/index.js | 0 .../files/{ => plugin}/admin/src/index.js | 0 .../files/{ => plugin}/admin/src/pluginId.js | 0 .../files/{ => plugin}/admin/src/translations/en.json | 0 .../files/{ => plugin}/admin/src/translations/fr.json | 0 .../files/{ => plugin}/admin/src/utils/getTrad.js | 0 packages/generators/generate-plop/plopfile.js | 10 +--------- 12 files changed, 1 insertion(+), 9 deletions(-) rename packages/generators/generate-plop/{templates => files/plugin}/.editorconfig (100%) rename packages/generators/generate-plop/{templates => files/plugin}/.gitattributes (100%) rename packages/generators/generate-plop/{templates => files/plugin}/.gitignore (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/containers/App/index.js (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/containers/HomePage/index.js (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/containers/Initializer/index.js (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/index.js (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/pluginId.js (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/translations/en.json (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/translations/fr.json (100%) rename packages/generators/generate-plop/files/{ => plugin}/admin/src/utils/getTrad.js (100%) diff --git a/packages/generators/generate-plop/templates/.editorconfig b/packages/generators/generate-plop/files/plugin/.editorconfig similarity index 100% rename from packages/generators/generate-plop/templates/.editorconfig rename to packages/generators/generate-plop/files/plugin/.editorconfig diff --git a/packages/generators/generate-plop/templates/.gitattributes b/packages/generators/generate-plop/files/plugin/.gitattributes similarity index 100% rename from packages/generators/generate-plop/templates/.gitattributes rename to packages/generators/generate-plop/files/plugin/.gitattributes diff --git a/packages/generators/generate-plop/templates/.gitignore b/packages/generators/generate-plop/files/plugin/.gitignore similarity index 100% rename from packages/generators/generate-plop/templates/.gitignore rename to packages/generators/generate-plop/files/plugin/.gitignore diff --git a/packages/generators/generate-plop/files/admin/src/containers/App/index.js b/packages/generators/generate-plop/files/plugin/admin/src/containers/App/index.js similarity index 100% rename from packages/generators/generate-plop/files/admin/src/containers/App/index.js rename to packages/generators/generate-plop/files/plugin/admin/src/containers/App/index.js diff --git a/packages/generators/generate-plop/files/admin/src/containers/HomePage/index.js b/packages/generators/generate-plop/files/plugin/admin/src/containers/HomePage/index.js similarity index 100% rename from packages/generators/generate-plop/files/admin/src/containers/HomePage/index.js rename to packages/generators/generate-plop/files/plugin/admin/src/containers/HomePage/index.js diff --git a/packages/generators/generate-plop/files/admin/src/containers/Initializer/index.js b/packages/generators/generate-plop/files/plugin/admin/src/containers/Initializer/index.js similarity index 100% rename from packages/generators/generate-plop/files/admin/src/containers/Initializer/index.js rename to packages/generators/generate-plop/files/plugin/admin/src/containers/Initializer/index.js diff --git a/packages/generators/generate-plop/files/admin/src/index.js b/packages/generators/generate-plop/files/plugin/admin/src/index.js similarity index 100% rename from packages/generators/generate-plop/files/admin/src/index.js rename to packages/generators/generate-plop/files/plugin/admin/src/index.js diff --git a/packages/generators/generate-plop/files/admin/src/pluginId.js b/packages/generators/generate-plop/files/plugin/admin/src/pluginId.js similarity index 100% rename from packages/generators/generate-plop/files/admin/src/pluginId.js rename to packages/generators/generate-plop/files/plugin/admin/src/pluginId.js diff --git a/packages/generators/generate-plop/files/admin/src/translations/en.json b/packages/generators/generate-plop/files/plugin/admin/src/translations/en.json similarity index 100% rename from packages/generators/generate-plop/files/admin/src/translations/en.json rename to packages/generators/generate-plop/files/plugin/admin/src/translations/en.json diff --git a/packages/generators/generate-plop/files/admin/src/translations/fr.json b/packages/generators/generate-plop/files/plugin/admin/src/translations/fr.json similarity index 100% rename from packages/generators/generate-plop/files/admin/src/translations/fr.json rename to packages/generators/generate-plop/files/plugin/admin/src/translations/fr.json diff --git a/packages/generators/generate-plop/files/admin/src/utils/getTrad.js b/packages/generators/generate-plop/files/plugin/admin/src/utils/getTrad.js similarity index 100% rename from packages/generators/generate-plop/files/admin/src/utils/getTrad.js rename to packages/generators/generate-plop/files/plugin/admin/src/utils/getTrad.js diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js index 2640a23c7f..642fc6ac0d 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate-plop/plopfile.js @@ -104,7 +104,7 @@ module.exports = function(plop) { }, ], actions: data => { - fs.copySync(join(__dirname, 'files', 'admin'), join(rootDir, 'plugins', data.id, 'admin')); + fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', data.id)); return [ { @@ -132,14 +132,6 @@ module.exports = function(plop) { path: join(rootDir, 'plugins/{{id}}/package.json'), templateFile: 'templates/plugin-package.json.hbs', }, - { - destination: join(rootDir, 'plugins/{{id}}'), - type: 'addMany', - templateFiles: 'templates/.*', - globOptions: { - dot: true, - }, - }, ]; }, }); From 439103e4cf56576bf3b2586c7ab52ec1476b4f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= Date: Fri, 20 Aug 2021 13:26:43 +0200 Subject: [PATCH 07/26] Add API plop generator (#10769) --- .../generators/generate-plop/package.json | 3 +- packages/generators/generate-plop/plopfile.js | 50 ++++++++++++++++++- .../templates/api-routes.json.hbs | 44 ++++++++++++++++ ...routes.json.hbs => plugin-routes.json.hbs} | 0 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 packages/generators/generate-plop/templates/api-routes.json.hbs rename packages/generators/generate-plop/templates/{routes.json.hbs => plugin-routes.json.hbs} (100%) diff --git a/packages/generators/generate-plop/package.json b/packages/generators/generate-plop/package.json index d241f5842d..679e3e99c1 100644 --- a/packages/generators/generate-plop/package.json +++ b/packages/generators/generate-plop/package.json @@ -6,6 +6,7 @@ "license": "MIT", "dependencies": { "fs-extra": "10.0.0", - "plop": "2.7.4" + "plop": "2.7.4", + "pluralize": "8.0.0" } } diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate-plop/plopfile.js index 642fc6ac0d..a1bc2f1634 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate-plop/plopfile.js @@ -2,11 +2,14 @@ const { join } = require('path'); const fs = require('fs-extra'); +const pluralize = require('pluralize'); module.exports = function(plop) { const rootDir = process.cwd(); plop.setWelcomeMessage('Strapi Generators'); + plop.addHelper('pluralize', text => pluralize(text)); + // Service generator plop.setGenerator('service', { description: 'Generate a service for an API', @@ -93,6 +96,50 @@ module.exports = function(plop) { ], }); + // API generator + plop.setGenerator('api', { + description: 'Generate a basic API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'API name', + }, + { + type: 'confirm', + name: 'useDraftAndPublish', + message: 'Use draft and publish?', + }, + ], + actions: [ + { + type: 'add', + path: join(rootDir, 'api/{{id}}/config/routes.json'), + templateFile: 'templates/api-routes.json.hbs', + }, + { + type: 'add', + path: join(rootDir, 'api/{{id}}/controllers/{{id}}.js'), + templateFile: 'templates/controller.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'api/{{id}}/models/{{id}}.js'), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'api/{{id}}/models/{{id}}.settings.json'), + templateFile: 'templates/model.settings.json.hbs', + }, + { + type: 'add', + path: join(rootDir, 'api/{{id}}/services/{{id}}.js'), + templateFile: 'templates/service.js.hbs', + }, + ], + }); + // Plugin generator plop.setGenerator('plugin', { description: 'Generate a basic plugin', @@ -105,7 +152,6 @@ module.exports = function(plop) { ], actions: data => { fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', data.id)); - return [ { type: 'add', @@ -120,7 +166,7 @@ module.exports = function(plop) { { type: 'add', path: join(rootDir, 'plugins/{{id}}/config/routes.json'), - templateFile: 'templates/routes.json.hbs', + templateFile: 'templates/plugin-routes.json.hbs', }, { type: 'add', diff --git a/packages/generators/generate-plop/templates/api-routes.json.hbs b/packages/generators/generate-plop/templates/api-routes.json.hbs new file mode 100644 index 0000000000..f5c6b78c71 --- /dev/null +++ b/packages/generators/generate-plop/templates/api-routes.json.hbs @@ -0,0 +1,44 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/{{pluralize id}}", + "handler": "{{id}}.find", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/{{pluralize id}}/:id", + "handler": "{{id}}.findOne", + "config": { + "policies": [] + } + }, + { + "method": "POST", + "path": "/{{pluralize id}}", + "handler": "{{id}}.create", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/{{pluralize id}}/:id", + "handler": "{{id}}.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/{{pluralize id}}/:id", + "handler": "{{id}}.delete", + "config": { + "policies": [] + } + } + ] +} diff --git a/packages/generators/generate-plop/templates/routes.json.hbs b/packages/generators/generate-plop/templates/plugin-routes.json.hbs similarity index 100% rename from packages/generators/generate-plop/templates/routes.json.hbs rename to packages/generators/generate-plop/templates/plugin-routes.json.hbs From b1ff616fd59cce291ec2d607519f6d4e3d1afd9e Mon Sep 17 00:00:00 2001 From: markkaylor Date: Mon, 23 Aug 2021 16:08:20 +0200 Subject: [PATCH 08/26] add generators to cli (#10779) * add generators to cli * add strapi generate comment * remove old generators * rename generator-cli -> generate * list generators alphabetically * update package description * add check for strapi app in cwd --- examples/getstarted/package.json | 2 +- .../core/content-type-builder/package.json | 1 - packages/core/strapi/bin/strapi.js | 61 +--- packages/core/strapi/lib/commands/generate.js | 76 ----- packages/core/strapi/package.json | 9 +- packages/generators/api/.editorconfig | 16 - packages/generators/api/.gitignore | 102 ------ packages/generators/api/.npmignore | 109 ------ packages/generators/api/.snyk | 9 - packages/generators/api/LICENSE | 22 -- packages/generators/api/README.md | 25 -- packages/generators/api/jest.config.js | 7 - packages/generators/api/json/routes.json.js | 108 ------ packages/generators/api/lib/before.js | 138 -------- packages/generators/api/lib/index.js | 51 --- .../api/templates/controller.template | 8 - .../api/templates/model.settings.template | 1 - .../generators/api/templates/model.template | 8 - .../generators/api/templates/service.template | 8 - packages/generators/controller/.editorconfig | 16 - packages/generators/controller/.gitignore | 104 ------ packages/generators/controller/.npmignore | 109 ------ packages/generators/controller/.snyk | 9 - packages/generators/controller/LICENSE | 22 -- packages/generators/controller/README.md | 31 -- packages/generators/controller/lib/before.js | 56 --- packages/generators/controller/lib/index.js | 22 -- .../controller/templates/controller.template | 15 - .../generators/generate-plop/package.json | 12 - packages/generators/generate/.editorconfig | 16 - packages/generators/generate/.gitignore | 104 ------ packages/generators/generate/.npmignore | 109 ------ packages/generators/generate/.snyk | 9 - packages/generators/generate/LICENSE | 22 -- packages/generators/generate/README.md | 25 -- .../files/plugin/.editorconfig | 0 .../files/plugin/.gitattributes | 0 .../files/plugin/.gitignore | 0 .../plugin/admin/src/containers/App/index.js | 0 .../admin/src/containers/HomePage/index.js | 0 .../admin/src/containers/Initializer/index.js | 0 .../files/plugin/admin/src/index.js | 0 .../files/plugin/admin/src/pluginId.js | 0 .../plugin/admin/src/translations/en.json | 0 .../plugin/admin/src/translations/fr.json | 0 .../files/plugin/admin/src/utils/getTrad.js | 0 packages/generators/generate/index.js | 10 + packages/generators/generate/lib/generate.js | 188 ----------- .../generate/lib/helpers/copy/index.js | 45 --- .../generate/lib/helpers/file/index.js | 68 ---- .../generate/lib/helpers/folder/index.js | 77 ----- .../generate/lib/helpers/jsonfile/index.js | 66 ---- .../generate/lib/helpers/template/index.js | 72 ---- packages/generators/generate/lib/index.js | 67 ---- packages/generators/generate/lib/target.js | 318 ------------------ packages/generators/generate/lib/util.js | 62 ---- packages/generators/generate/package.json | 54 +-- .../{generate-plop => generate}/plopfile.js | 172 +++++----- .../templates/README.md.hbs | 0 .../templates/api-routes.json.hbs | 0 .../templates/controller.js.hbs | 0 .../templates/model.js.hbs | 0 .../templates/model.settings.json.hbs | 0 .../templates/plugin-package.json.hbs | 0 .../templates/plugin-routes.json.hbs | 0 .../templates/policy.js.hbs | 0 .../templates/service.js.hbs | 0 packages/generators/model/.editorconfig | 16 - packages/generators/model/.gitignore | 104 ------ packages/generators/model/.npmignore | 109 ------ packages/generators/model/.snyk | 9 - packages/generators/model/LICENSE | 22 -- packages/generators/model/README.md | 31 -- packages/generators/model/lib/before.js | 139 -------- packages/generators/model/lib/index.js | 25 -- .../model/templates/model.settings.template | 1 - .../generators/model/templates/model.template | 8 - packages/generators/plugin/.editorconfig | 16 - packages/generators/plugin/.gitignore | 104 ------ packages/generators/plugin/.npmignore | 109 ------ packages/generators/plugin/.snyk | 9 - packages/generators/plugin/LICENSE | 22 -- packages/generators/plugin/README.md | 25 -- .../files/admin/src/containers/App/index.js | 25 -- .../admin/src/containers/HomePage/index.js | 20 -- .../admin/src/containers/Initializer/index.js | 26 -- .../plugin/files/admin/src/index.js | 61 ---- .../plugin/files/admin/src/pluginId.js | 5 - .../files/admin/src/translations/en.json | 1 - .../files/admin/src/translations/fr.json | 1 - .../plugin/files/admin/src/utils/getTrad.js | 5 - .../generators/plugin/json/package.json.js | 45 --- .../generators/plugin/json/routes.json.js | 24 -- packages/generators/plugin/lib/before.js | 52 --- packages/generators/plugin/lib/index.js | 63 ---- .../generators/plugin/templates/README.md | 3 - .../plugin/templates/controller.template | 25 -- .../generators/plugin/templates/editorconfig | 7 - .../generators/plugin/templates/gitattributes | 103 ------ .../generators/plugin/templates/gitignore | 10 - .../plugin/templates/service.template | 11 - packages/generators/policy/.editorconfig | 16 - packages/generators/policy/.gitignore | 104 ------ packages/generators/policy/.npmignore | 109 ------ packages/generators/policy/.snyk | 9 - packages/generators/policy/LICENSE | 22 -- packages/generators/policy/README.md | 31 -- packages/generators/policy/lib/before.js | 48 --- packages/generators/policy/lib/index.js | 22 -- .../policy/templates/policy.template | 12 - packages/generators/service/.editorconfig | 16 - packages/generators/service/.gitignore | 104 ------ packages/generators/service/.npmignore | 109 ------ packages/generators/service/.snyk | 9 - packages/generators/service/LICENSE | 22 -- packages/generators/service/README.md | 31 -- packages/generators/service/lib/before.js | 55 --- packages/generators/service/lib/index.js | 22 -- .../service/templates/service.template | 11 - yarn.lock | 55 +-- 120 files changed, 124 insertions(+), 4560 deletions(-) delete mode 100644 packages/core/strapi/lib/commands/generate.js delete mode 100644 packages/generators/api/.editorconfig delete mode 100644 packages/generators/api/.gitignore delete mode 100644 packages/generators/api/.npmignore delete mode 100644 packages/generators/api/.snyk delete mode 100644 packages/generators/api/LICENSE delete mode 100644 packages/generators/api/README.md delete mode 100644 packages/generators/api/jest.config.js delete mode 100644 packages/generators/api/json/routes.json.js delete mode 100644 packages/generators/api/lib/before.js delete mode 100644 packages/generators/api/lib/index.js delete mode 100644 packages/generators/api/templates/controller.template delete mode 100644 packages/generators/api/templates/model.settings.template delete mode 100644 packages/generators/api/templates/model.template delete mode 100644 packages/generators/api/templates/service.template delete mode 100644 packages/generators/controller/.editorconfig delete mode 100644 packages/generators/controller/.gitignore delete mode 100644 packages/generators/controller/.npmignore delete mode 100644 packages/generators/controller/.snyk delete mode 100644 packages/generators/controller/LICENSE delete mode 100644 packages/generators/controller/README.md delete mode 100644 packages/generators/controller/lib/before.js delete mode 100644 packages/generators/controller/lib/index.js delete mode 100644 packages/generators/controller/templates/controller.template delete mode 100644 packages/generators/generate-plop/package.json delete mode 100644 packages/generators/generate/.editorconfig delete mode 100644 packages/generators/generate/.gitignore delete mode 100644 packages/generators/generate/.npmignore delete mode 100644 packages/generators/generate/.snyk delete mode 100644 packages/generators/generate/LICENSE delete mode 100644 packages/generators/generate/README.md rename packages/generators/{generate-plop => generate}/files/plugin/.editorconfig (100%) rename packages/generators/{generate-plop => generate}/files/plugin/.gitattributes (100%) rename packages/generators/{generate-plop => generate}/files/plugin/.gitignore (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/containers/App/index.js (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/containers/HomePage/index.js (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/containers/Initializer/index.js (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/index.js (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/pluginId.js (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/translations/en.json (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/translations/fr.json (100%) rename packages/generators/{generate-plop => generate}/files/plugin/admin/src/utils/getTrad.js (100%) create mode 100644 packages/generators/generate/index.js delete mode 100644 packages/generators/generate/lib/generate.js delete mode 100644 packages/generators/generate/lib/helpers/copy/index.js delete mode 100644 packages/generators/generate/lib/helpers/file/index.js delete mode 100644 packages/generators/generate/lib/helpers/folder/index.js delete mode 100644 packages/generators/generate/lib/helpers/jsonfile/index.js delete mode 100644 packages/generators/generate/lib/helpers/template/index.js delete mode 100644 packages/generators/generate/lib/index.js delete mode 100644 packages/generators/generate/lib/target.js delete mode 100644 packages/generators/generate/lib/util.js rename packages/generators/{generate-plop => generate}/plopfile.js (100%) rename packages/generators/{generate-plop => generate}/templates/README.md.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/api-routes.json.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/controller.js.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/model.js.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/model.settings.json.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/plugin-package.json.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/plugin-routes.json.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/policy.js.hbs (100%) rename packages/generators/{generate-plop => generate}/templates/service.js.hbs (100%) delete mode 100644 packages/generators/model/.editorconfig delete mode 100644 packages/generators/model/.gitignore delete mode 100644 packages/generators/model/.npmignore delete mode 100644 packages/generators/model/.snyk delete mode 100644 packages/generators/model/LICENSE delete mode 100644 packages/generators/model/README.md delete mode 100644 packages/generators/model/lib/before.js delete mode 100644 packages/generators/model/lib/index.js delete mode 100644 packages/generators/model/templates/model.settings.template delete mode 100644 packages/generators/model/templates/model.template delete mode 100644 packages/generators/plugin/.editorconfig delete mode 100644 packages/generators/plugin/.gitignore delete mode 100644 packages/generators/plugin/.npmignore delete mode 100644 packages/generators/plugin/.snyk delete mode 100644 packages/generators/plugin/LICENSE delete mode 100644 packages/generators/plugin/README.md delete mode 100644 packages/generators/plugin/files/admin/src/containers/App/index.js delete mode 100644 packages/generators/plugin/files/admin/src/containers/HomePage/index.js delete mode 100644 packages/generators/plugin/files/admin/src/containers/Initializer/index.js delete mode 100644 packages/generators/plugin/files/admin/src/index.js delete mode 100644 packages/generators/plugin/files/admin/src/pluginId.js delete mode 100644 packages/generators/plugin/files/admin/src/translations/en.json delete mode 100644 packages/generators/plugin/files/admin/src/translations/fr.json delete mode 100644 packages/generators/plugin/files/admin/src/utils/getTrad.js delete mode 100644 packages/generators/plugin/json/package.json.js delete mode 100644 packages/generators/plugin/json/routes.json.js delete mode 100644 packages/generators/plugin/lib/before.js delete mode 100644 packages/generators/plugin/lib/index.js delete mode 100644 packages/generators/plugin/templates/README.md delete mode 100644 packages/generators/plugin/templates/controller.template delete mode 100644 packages/generators/plugin/templates/editorconfig delete mode 100644 packages/generators/plugin/templates/gitattributes delete mode 100644 packages/generators/plugin/templates/gitignore delete mode 100644 packages/generators/plugin/templates/service.template delete mode 100644 packages/generators/policy/.editorconfig delete mode 100644 packages/generators/policy/.gitignore delete mode 100644 packages/generators/policy/.npmignore delete mode 100644 packages/generators/policy/.snyk delete mode 100644 packages/generators/policy/LICENSE delete mode 100644 packages/generators/policy/README.md delete mode 100644 packages/generators/policy/lib/before.js delete mode 100644 packages/generators/policy/lib/index.js delete mode 100644 packages/generators/policy/templates/policy.template delete mode 100644 packages/generators/service/.editorconfig delete mode 100644 packages/generators/service/.gitignore delete mode 100644 packages/generators/service/.npmignore delete mode 100644 packages/generators/service/.snyk delete mode 100644 packages/generators/service/LICENSE delete mode 100644 packages/generators/service/README.md delete mode 100644 packages/generators/service/lib/before.js delete mode 100644 packages/generators/service/lib/index.js delete mode 100644 packages/generators/service/templates/service.template diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index 6c513a4a4d..a0e0acb288 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -40,4 +40,4 @@ "npm": ">=6.0.0" }, "license": "SEE LICENSE IN LICENSE" -} +} \ No newline at end of file diff --git a/packages/core/content-type-builder/package.json b/packages/core/content-type-builder/package.json index d1903647ab..b12df5586f 100644 --- a/packages/core/content-type-builder/package.json +++ b/packages/core/content-type-builder/package.json @@ -10,7 +10,6 @@ "dependencies": { "@sindresorhus/slugify": "1.1.0", "@strapi/generate": "3.6.7", - "@strapi/generate-api": "3.6.7", "@strapi/helper-plugin": "3.6.7", "@strapi/utils": "3.6.7", "fs-extra": "^9.1.0", diff --git a/packages/core/strapi/bin/strapi.js b/packages/core/strapi/bin/strapi.js index 2930fc11b0..c16a7c31db 100755 --- a/packages/core/strapi/bin/strapi.js +++ b/packages/core/strapi/bin/strapi.js @@ -118,68 +118,21 @@ program .description('Start your Strapi application in development mode') .action(getLocalScript('develop')); -// `$ strapi generate:api` +// $ strapi generate program - .command('generate:api [attributes...]') - .option('-a, --api ', 'API name to generate the files in') - .option('-p, --plugin ', 'Name of the local plugin') - .option('-e, --extend ', 'Name of the plugin to extend') - .option('--draft-and-publish', 'Enable draft/publish', false) - .description('Generate a basic API') - .action((id, attributes, cliArguments) => { - cliArguments.attributes = attributes; - getLocalScript('generate')(id, cliArguments); + .command('generate') + .description('Launch interactive API generator') + .action(() => { + checkCwdIsStrapiApp('generate'); + require('@strapi/generate')(); }); -// `$ strapi generate:controller` -program - .command('generate:controller ') - .option('-a, --api ', 'API name to generate the files in') - .option('-p, --plugin ', 'Name of the local plugin') - .option('-e, --extend ', 'Name of the plugin to extend') - .description('Generate a controller for an API') - .action(getLocalScript('generate')); - -// `$ strapi generate:model` -program - .command('generate:model [attributes...]') - .option('-a, --api ', 'API name to generate a sub API') - .option('-p, --plugin ', 'plugin name') - .option('--draft-and-publish', 'Enable draft/publish', false) - .description('Generate a model for an API') - .action((id, attributes, cliArguments) => { - cliArguments.attributes = attributes; - getLocalScript('generate')(id, cliArguments); - }); - -// `$ strapi generate:policy` -program - .command('generate:policy ') - .option('-a, --api ', 'API name') - .option('-p, --plugin ', 'plugin name') - .description('Generate a policy for an API') - .action(getLocalScript('generate')); - -// `$ strapi generate:service` -program - .command('generate:service ') - .option('-a, --api ', 'API name') - .option('-p, --plugin ', 'plugin name') - .description('Generate a service for an API') - .action(getLocalScript('generate')); - -// `$ strapi generate:plugin` -program - .command('generate:plugin ') - .option('-n, --name ', 'Plugin name') - .description('Generate a basic plugin') - .action(getLocalScript('generate')); - // `$ strapi generate:template ` program .command('generate:template ') .description('Generate template from Strapi project') .action(getLocalScript('generate-template')); + program .command('build') .option('--clean', 'Remove the build and .cache folders', false) diff --git a/packages/core/strapi/lib/commands/generate.js b/packages/core/strapi/lib/commands/generate.js deleted file mode 100644 index 11c5d7fb87..0000000000 --- a/packages/core/strapi/lib/commands/generate.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// FIXME -/* eslint-disable import/extensions */ - -// Node.js core. -const path = require('path'); - -// Master of ceremonies for generators. -const generate = require('@strapi/generate'); - -// Logger. -const { createLogger } = require('@strapi/logger'); - -// Configuration -const loadConfiguration = require('../core/app-configuration'); - -// Local Strapi dependencies. -const packageJSON = require('../../package.json'); - -/** - * `$ strapi generate` - * - * Scaffolding for the application in our working directory. - */ - -module.exports = function(id, cliArguments) { - const dir = process.cwd(); - const config = loadConfiguration(dir); - const logger = createLogger(config.get('logger', {})); - - // Build initial scope. - const scope = { - rootPath: process.cwd(), - strapiRoot: path.resolve(__dirname, '..'), - id: id, - args: cliArguments, - strapiPackageJSON: packageJSON, - }; - - scope.generatorType = process.argv[2].split(':')[1]; - - // Show usage if no generator type is defined. - if (!scope.generatorType) { - return logger.error('Write `$ strapi generate:something` instead.'); - } - - return generate(scope, { - // Log and exit the REPL in case there is an error - // while we were trying to generate the requested generator. - error(msg) { - logger.error(msg); - process.exit(1); - }, - - // Log and exit the REPL in case of success - // but first make sure we have all the info we need. - success() { - if (!scope.outputPath && scope.filename && scope.destDir) { - scope.outputPath = scope.destDir + scope.filename; - } - - if (scope.generatorType !== 'new') { - logger.info( - `Generated a new ${scope.generatorType} \`${scope.name}\` at \`${scope.filePath}\`.` - ); - } - - process.exit(0); - }, - }); -}; diff --git a/packages/core/strapi/package.json b/packages/core/strapi/package.json index 3a53f3e1bb..03e89e1bca 100644 --- a/packages/core/strapi/package.json +++ b/packages/core/strapi/package.json @@ -16,13 +16,7 @@ "@strapi/admin": "3.6.7", "@strapi/database": "3.6.7", "@strapi/generate": "3.6.7", - "@strapi/generate-api": "3.6.7", - "@strapi/generate-controller": "3.6.7", - "@strapi/generate-model": "3.6.7", "@strapi/generate-new": "3.6.7", - "@strapi/generate-plugin": "3.6.7", - "@strapi/generate-policy": "3.6.7", - "@strapi/generate-service": "3.6.7", "@strapi/logger": "3.6.7", "@strapi/utils": "3.6.7", "async": "^2.1.2", @@ -63,6 +57,7 @@ "open": "8.2.1", "ora": "^5.4.0", "package-json": "6.5.0", + "plop": "2.7.4", "qs": "^6.10.1", "resolve-cwd": "^3.0.0", "rimraf": "^3.0.2", @@ -138,4 +133,4 @@ "reactjs" ], "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} +} \ No newline at end of file diff --git a/packages/generators/api/.editorconfig b/packages/generators/api/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/api/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/api/.gitignore b/packages/generators/api/.gitignore deleted file mode 100644 index 1681516f06..0000000000 --- a/packages/generators/api/.gitignore +++ /dev/null @@ -1,102 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/api/.npmignore b/packages/generators/api/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/api/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/api/.snyk b/packages/generators/api/.snyk deleted file mode 100644 index dad193f2df..0000000000 --- a/packages/generators/api/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:35:54.864Z -patch: {} diff --git a/packages/generators/api/LICENSE b/packages/generators/api/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/api/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/api/README.md b/packages/generators/api/README.md deleted file mode 100644 index 3781ae6973..0000000000 --- a/packages/generators/api/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# strapi-generate-api - -[![npm version](https://img.shields.io/npm/v/strapi-generate-api.svg)](https://www.npmjs.org/package/strapi-generate-api) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate-api.svg)](https://www.npmjs.org/package/strapi-generate-api) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate-api.svg)](https://david-dm.org/strapi/strapi-generate-api) -[![Build status](https://travis-ci.org/strapi/strapi-generate-api.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate-api) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -This Strapi generator contains all the default files for a new API. - -This generator can be called with: - -```bash -$ strapi generate:api apiName -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/api/jest.config.js b/packages/generators/api/jest.config.js deleted file mode 100644 index e7d225f24d..0000000000 --- a/packages/generators/api/jest.config.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports = { - name: 'generate-api', - displayName: 'Generated API', - testMatch: ['**/test/?(*.)+(spec|test).js'], -}; diff --git a/packages/generators/api/json/routes.json.js b/packages/generators/api/json/routes.json.js deleted file mode 100644 index 8b063eb370..0000000000 --- a/packages/generators/api/json/routes.json.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const fs = require('fs'); - -// Public node modules. -const _ = require('lodash'); - -function generateSingleTypeRoutes({ route, name }) { - return [ - { - method: 'GET', - path: '/' + route, - handler: name + '.find', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/' + route, - handler: name + '.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/' + route, - handler: name + '.delete', - config: { - policies: [], - }, - }, - ]; -} - -function generateCollectionTypeRoutes({ route, name }) { - return [ - { - method: 'GET', - path: '/' + route, - handler: name + '.find', - config: { - policies: [], - }, - }, - { - method: 'GET', - path: '/' + route + '/:id', - handler: name + '.findOne', - config: { - policies: [], - }, - }, - { - method: 'POST', - path: '/' + route, - handler: name + '.create', - config: { - policies: [], - }, - }, - { - method: 'PUT', - path: '/' + route + '/:id', - handler: name + '.update', - config: { - policies: [], - }, - }, - { - method: 'DELETE', - path: '/' + route + '/:id', - handler: name + '.delete', - config: { - policies: [], - }, - }, - ]; -} - -/** - * Expose main routes of the generated API - */ - -module.exports = scope => { - let routes = []; - if (!scope.args.plugin) { - routes = - scope.contentTypeKind === 'singleType' - ? generateSingleTypeRoutes({ route: scope.route, name: scope.name }) - : generateCollectionTypeRoutes({ route: scope.route, name: scope.name }); - } - - // if routes.json already exists, then merge - if (fs.existsSync(scope.rootPath)) { - let current = require(scope.rootPath); - fs.unlinkSync(scope.rootPath); - routes = _.concat(routes, _.differenceWith(current.routes, routes, _.isEqual)); - } - - return { routes }; -}; diff --git a/packages/generators/api/lib/before.js b/packages/generators/api/lib/before.js deleted file mode 100644 index 43ed03a70b..0000000000 --- a/packages/generators/api/lib/before.js +++ /dev/null @@ -1,138 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); -const pluralize = require('pluralize'); -const { nameToSlug } = require('@strapi/utils'); - -/** - * This `before` function is run before generating targets. - * Validate, configure defaults, get extra dependencies, etc. - * - * @param {Object} scope - * @param {Function} cb - */ - -module.exports = (scope, cb) => { - if (!scope.rootPath || !scope.id) { - return cb.invalid('Usage: `$ strapi generate:api apiName`'); - } - - // Format `id`. - const name = scope.name || nameToSlug(scope.id); - - scope.contentTypeKind = scope.args.kind || 'collectionType'; - - // `scope.args` are the raw command line arguments. - _.defaults(scope, { - name, - route: - scope.contentTypeKind === 'singleType' - ? _.kebabCase(scope.id) - : _.kebabCase(pluralize(scope.id)), - }); - - let filePath; - if (scope.args.api) { - filePath = `./api/${scope.args.api}`; - } else if (scope.args.plugin) { - filePath = `./plugins/${scope.args.plugin}`; - } else if (scope.args.extend) { - filePath = `./extensions/${scope.args.extend}`; - } else { - filePath = `./api/${name}`; - } - - // Take another pass to take advantage of the defaults absorbed in previous passes. - _.defaults(scope, { - filename: `${name}.js`, - filenameSettings: `${name}.settings.json`, - filePath, - }); - - // Validate optional attribute arguments. - const invalidAttributes = []; - - if (_.isPlainObject(scope.args.attributes)) { - scope.attributes = scope.args.attributes; - } else { - // Map attributes and split them for CLI. - scope.attributes = scope.args.attributes.map(attribute => { - if (_.isString(attribute)) { - const parts = attribute.split(':'); - - parts[1] = parts[1] || 'string'; - - // Handle invalid attributes. - if (!parts[1] || !parts[0]) { - invalidAttributes.push('Error: Invalid attribute notation `' + attribute + '`.'); - return; - } - - return { - name: _.trim(_.deburr(parts[0].toLowerCase())), - params: { - type: _.trim(_.deburr(parts[1].toLowerCase())), - }, - }; - } else { - return _.has(attribute, 'params.type') ? attribute : undefined; - } - }); - - scope.attributes = _.compact(scope.attributes); - - // Handle invalid action arguments. - // Send back invalidActions. - if (invalidAttributes.length) { - return cb.invalid(invalidAttributes); - } - - // Make sure there aren't duplicates. - if ( - _(scope.attributes.map(attribute => attribute.name)) - .uniq() - .valueOf().length !== scope.attributes.length - ) { - return cb.invalid('Duplicate attributes not allowed!'); - } - - // Render some stringified code from the action template - // and make it available in our scope for use later on. - scope.attributes = scope.attributes.reduce((acc, attribute) => { - acc[attribute.name] = attribute.params; - return acc; - }, {}); - } - // Set collectionName - scope.collectionName = _.has(scope.args, 'collectionName') - ? scope.args.collectionName - : _.snakeCase(pluralize(name)); - - // Set description - scope.description = _.has(scope.args, 'description') ? scope.args.description : ''; - - scope.schema = JSON.stringify( - { - collectionName: scope.collectionName, - info: { - name: scope.args.displayName || scope.id, - description: scope.description, - }, - options: { - draftAndPublish: scope.args.draftAndPublish === 'true', - comment: '', - }, - attributes: scope.attributes, - }, - null, - 2 - ); - - // Trigger callback with no error to proceed. - return cb.success(); -}; diff --git a/packages/generators/api/lib/index.js b/packages/generators/api/lib/index.js deleted file mode 100644 index cdcbe909db..0000000000 --- a/packages/generators/api/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// FIXME -/* eslint-disable import/extensions */ - -// Local dependencies. -const routesJSON = require('../json/routes.json.js'); - -/** - * Generate a core API - */ - -module.exports = { - templatesDirectory: path.resolve(__dirname, '..', 'templates'), - before: require('./before'), - targets: { - // Use the default `controller` file as a template for - // every generated controller. - ':filePath/controllers/:filename': { - template: 'controller.template', - }, - - // every generated controller. - ':filePath/services/:filename': { - template: 'service.template', - }, - - // Copy an empty JavaScript model where every functions will be. - ':filePath/models/:filename': { - template: 'model.template', - }, - - // Copy the generated JSON model for the connection, - // schema and attributes. - ':filePath/models/:filenameSettings': { - template: 'model.settings.template', - }, - - // Generate routes. - ':filePath/config/routes.json': { - jsonfile: routesJSON, - }, - }, -}; diff --git a/packages/generators/api/templates/controller.template b/packages/generators/api/templates/controller.template deleted file mode 100644 index e860895393..0000000000 --- a/packages/generators/api/templates/controller.template +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -/** - * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers) - * to customize this controller - */ - -module.exports = {}; diff --git a/packages/generators/api/templates/model.settings.template b/packages/generators/api/templates/model.settings.template deleted file mode 100644 index ae62b4b5c5..0000000000 --- a/packages/generators/api/templates/model.settings.template +++ /dev/null @@ -1 +0,0 @@ -<%= schema %> diff --git a/packages/generators/api/templates/model.template b/packages/generators/api/templates/model.template deleted file mode 100644 index 0054d33c1e..0000000000 --- a/packages/generators/api/templates/model.template +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -/** - * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) - * to customize this model - */ - -module.exports = {}; diff --git a/packages/generators/api/templates/service.template b/packages/generators/api/templates/service.template deleted file mode 100644 index 6538a8c86b..0000000000 --- a/packages/generators/api/templates/service.template +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -/** - * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) - * to customize this service - */ - -module.exports = {}; diff --git a/packages/generators/controller/.editorconfig b/packages/generators/controller/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/controller/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/controller/.gitignore b/packages/generators/controller/.gitignore deleted file mode 100644 index 47e0ea73cc..0000000000 --- a/packages/generators/controller/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - - - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/controller/.npmignore b/packages/generators/controller/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/controller/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/controller/.snyk b/packages/generators/controller/.snyk deleted file mode 100644 index 21c1b06e09..0000000000 --- a/packages/generators/controller/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:35:57.351Z -patch: {} diff --git a/packages/generators/controller/LICENSE b/packages/generators/controller/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/controller/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/controller/README.md b/packages/generators/controller/README.md deleted file mode 100644 index 5f3737add8..0000000000 --- a/packages/generators/controller/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# strapi-generate-controller - -[![npm version](https://img.shields.io/npm/v/strapi-generate-controller.svg)](https://www.npmjs.org/package/strapi-generate-controller) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate-controller.svg)](https://www.npmjs.org/package/strapi-generate-controller) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate-controller.svg)](https://david-dm.org/strapi/strapi-generate-controller) -[![Build status](https://travis-ci.org/strapi/strapi-generate-controller.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate-controller) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -This Strapi generator contains the default files for a controller. - -This generator can be called with: - -```bash -$ strapi generate:controller controllerName apiName -``` - -For example if you want to generate a `group` controller for the `user` API: - -```bash -$ strapi generate:controller group user -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/controller/lib/before.js b/packages/generators/controller/lib/before.js deleted file mode 100644 index 8ffc5e5ab0..0000000000 --- a/packages/generators/controller/lib/before.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); -const { nameToSlug } = require('@strapi/utils'); -/* eslint-disable prefer-template */ -/** - * This `before` function is run before generating targets. - * Validate, configure defaults, get extra dependencies, etc. - * - * @param {Object} scope - * @param {Function} cb - */ - -module.exports = (scope, cb) => { - if (!scope.rootPath || !scope.id) { - return cb.invalid( - 'Usage: `$ strapi generate:controller controllerName --api apiName --plugin pluginName`' - ); - } - - // Format `id`. - const name = scope.name || nameToSlug(scope.id); - - // `scope.args` are the raw command line arguments. - _.defaults(scope, { - name, - api: scope.id, - }); - - // Determine the destination path. - let filePath; - if (scope.args.api) { - filePath = `./api/${scope.args.api}/controllers`; - } else if (scope.args.plugin) { - filePath = `./plugins/${scope.args.plugin}/controllers`; - } else if (scope.args.extend) { - filePath = `./extensions/${scope.args.extend}/controllers`; - } else { - filePath = `./api/${name}/controllers`; - } - - // Take another pass to take advantage of the defaults absorbed in previous passes. - _.defaults(scope, { - rootPath: scope.rootPath, - filePath, - filename: `${name}.js`, - }); - - // Trigger callback with no error to proceed. - return cb(); -}; diff --git a/packages/generators/controller/lib/index.js b/packages/generators/controller/lib/index.js deleted file mode 100644 index 778338ace0..0000000000 --- a/packages/generators/controller/lib/index.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -/** - * Generate a core API - */ - -module.exports = { - templatesDirectory: path.resolve(__dirname, '..', 'templates'), - before: require('./before'), - targets: { - ':filePath/:filename': { - template: 'controller.template', - }, - }, -}; diff --git a/packages/generators/controller/templates/controller.template b/packages/generators/controller/templates/controller.template deleted file mode 100644 index 929ca9ff11..0000000000 --- a/packages/generators/controller/templates/controller.template +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -/** - * A set of functions called "actions" for `<%= name %>` - */ - -module.exports = { - // exampleAction: async (ctx, next) => { - // try { - // ctx.body = 'ok'; - // } catch (err) { - // ctx.body = err; - // } - // } -}; diff --git a/packages/generators/generate-plop/package.json b/packages/generators/generate-plop/package.json deleted file mode 100644 index 679e3e99c1..0000000000 --- a/packages/generators/generate-plop/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "service-plop", - "version": "3.6.6", - "description": "Generate a service for a Strapi API.", - "main": "index.js", - "license": "MIT", - "dependencies": { - "fs-extra": "10.0.0", - "plop": "2.7.4", - "pluralize": "8.0.0" - } -} diff --git a/packages/generators/generate/.editorconfig b/packages/generators/generate/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/generate/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/generate/.gitignore b/packages/generators/generate/.gitignore deleted file mode 100644 index 47e0ea73cc..0000000000 --- a/packages/generators/generate/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - - - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/generate/.npmignore b/packages/generators/generate/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/generate/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/generate/.snyk b/packages/generators/generate/.snyk deleted file mode 100644 index 537461afdd..0000000000 --- a/packages/generators/generate/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:35:22.585Z -patch: {} diff --git a/packages/generators/generate/LICENSE b/packages/generators/generate/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/generate/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/generate/README.md b/packages/generators/generate/README.md deleted file mode 100644 index 1946bede6a..0000000000 --- a/packages/generators/generate/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# strapi-generate - -[![npm version](https://img.shields.io/npm/v/strapi-generate.svg)](https://www.npmjs.org/package/strapi-generate) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate.svg)](https://www.npmjs.org/package/strapi-generate) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate.svg)](https://david-dm.org/strapi/strapi-generate) -[![Build status](https://travis-ci.org/strapi/strapi-generate.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -Master of ceremonies for generators in the Strapi CLI. - -Usage: - -```bash -$ strapi generate:something -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/generate-plop/files/plugin/.editorconfig b/packages/generators/generate/files/plugin/.editorconfig similarity index 100% rename from packages/generators/generate-plop/files/plugin/.editorconfig rename to packages/generators/generate/files/plugin/.editorconfig diff --git a/packages/generators/generate-plop/files/plugin/.gitattributes b/packages/generators/generate/files/plugin/.gitattributes similarity index 100% rename from packages/generators/generate-plop/files/plugin/.gitattributes rename to packages/generators/generate/files/plugin/.gitattributes diff --git a/packages/generators/generate-plop/files/plugin/.gitignore b/packages/generators/generate/files/plugin/.gitignore similarity index 100% rename from packages/generators/generate-plop/files/plugin/.gitignore rename to packages/generators/generate/files/plugin/.gitignore diff --git a/packages/generators/generate-plop/files/plugin/admin/src/containers/App/index.js b/packages/generators/generate/files/plugin/admin/src/containers/App/index.js similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/containers/App/index.js rename to packages/generators/generate/files/plugin/admin/src/containers/App/index.js diff --git a/packages/generators/generate-plop/files/plugin/admin/src/containers/HomePage/index.js b/packages/generators/generate/files/plugin/admin/src/containers/HomePage/index.js similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/containers/HomePage/index.js rename to packages/generators/generate/files/plugin/admin/src/containers/HomePage/index.js diff --git a/packages/generators/generate-plop/files/plugin/admin/src/containers/Initializer/index.js b/packages/generators/generate/files/plugin/admin/src/containers/Initializer/index.js similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/containers/Initializer/index.js rename to packages/generators/generate/files/plugin/admin/src/containers/Initializer/index.js diff --git a/packages/generators/generate-plop/files/plugin/admin/src/index.js b/packages/generators/generate/files/plugin/admin/src/index.js similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/index.js rename to packages/generators/generate/files/plugin/admin/src/index.js diff --git a/packages/generators/generate-plop/files/plugin/admin/src/pluginId.js b/packages/generators/generate/files/plugin/admin/src/pluginId.js similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/pluginId.js rename to packages/generators/generate/files/plugin/admin/src/pluginId.js diff --git a/packages/generators/generate-plop/files/plugin/admin/src/translations/en.json b/packages/generators/generate/files/plugin/admin/src/translations/en.json similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/translations/en.json rename to packages/generators/generate/files/plugin/admin/src/translations/en.json diff --git a/packages/generators/generate-plop/files/plugin/admin/src/translations/fr.json b/packages/generators/generate/files/plugin/admin/src/translations/fr.json similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/translations/fr.json rename to packages/generators/generate/files/plugin/admin/src/translations/fr.json diff --git a/packages/generators/generate-plop/files/plugin/admin/src/utils/getTrad.js b/packages/generators/generate/files/plugin/admin/src/utils/getTrad.js similarity index 100% rename from packages/generators/generate-plop/files/plugin/admin/src/utils/getTrad.js rename to packages/generators/generate/files/plugin/admin/src/utils/getTrad.js diff --git a/packages/generators/generate/index.js b/packages/generators/generate/index.js new file mode 100644 index 0000000000..d1cf30d16f --- /dev/null +++ b/packages/generators/generate/index.js @@ -0,0 +1,10 @@ +'use strict'; + +process.argv.splice(2, 1); + +const { join } = require('path'); +const { Plop, run } = require('plop'); + +module.exports = () => { + Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, run); +}; diff --git a/packages/generators/generate/lib/generate.js b/packages/generators/generate/lib/generate.js deleted file mode 100644 index d47ed93544..0000000000 --- a/packages/generators/generate/lib/generate.js +++ /dev/null @@ -1,188 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); -const util = require('util'); - -// Public node modules. -const _ = require('lodash'); -const async = require('async'); -const reportback = require('reportback')(); - -// Local dependencies. -const pathRegexp = require('./util').pathRegexp; -const generateTarget = require('./target'); - -/** - * Run a generator given an existing scope - * - * @param {Object} generator - * @param {Object} scope - * @param {Switchback} cb - */ - -/* eslint-disable prefer-template */ -function generate(generator, scope, cb) { - const sb = reportback.extend(cb, { - error: cb.error, - invalid: cb.invalid, - alreadyExists: 'error', - }); - - // Resolve string shorthand for generator defs - // to `{ generator: 'originalDef' }`. - if (typeof generator === 'string') { - const generatorName = generator; - generator = { - generator: generatorName, - }; - } - - // Run the generator's `before()` method proceeding. - generator.before( - scope, - reportback.extend({ - error: sb.error, - invalid: sb.invalid, - success: () => { - // Process all of the generator's targets concurrently. - async.each( - Object.keys(generator.targets), - (keyPath, asyncEachCb) => { - const asyncEachSb = reportback.extend(asyncEachCb); - - // Create a new scope object for this target, - // with references to the important bits of the original - // (depth will be passed-by-value, but that's what we want). - // Then generate the target, passing along a reference to - // the base `generate` method to allow for recursive generators. - const target = generator.targets[keyPath]; - if (!target) { - return asyncEachSb( - new Error( - 'Error: Invalid target: {"' + keyPath + '": ' + util.inspect(target) + '}' - ) - ); - } - - // Input tolerance. - if (keyPath === '') { - keyPath = '.'; - } - - // Interpret `keyPath` using Express's parameterized route conventions, - // first parsing params, then replacing them with their proper values from scope. - const params = []; - pathRegexp(keyPath, params); - let err; - const parsedKeyPath = _.reduce( - params, - (memoKeyPath, param) => { - if (err) { - return false; - } - - try { - const paramMatchExpr = ':' + param.name; - let actualParamValue = scope[param.name]; - if (!actualParamValue) { - err = new Error( - 'generator error:\n' + - 'A scope variable (`' + - param.name + - '`) was referenced in target: `' + - memoKeyPath + - '`,\n' + - 'but `' + - param.name + - "` does not exist in the generator's scope." - ); - return false; - } - actualParamValue = String(actualParamValue); - - return memoKeyPath.replace(paramMatchExpr, actualParamValue); - } catch (e) { - err = new Error('Error: Could not parse target key ' + memoKeyPath); - err.message = e; - return false; - } - }, - keyPath - ); - if (!parsedKeyPath) { - return asyncEachSb(err); - } - - // Create path from `rootPath` to `keyPath` to use as the `rootPath` - // for any generators or helpers in this target - // (use a copy so that child generators don't mutate the scope). - const targetScope = _.merge({}, scope, { - rootPath: path.resolve(scope.rootPath, parsedKeyPath), - - // Include reference to original keypath for error reporting. - keyPath, - }); - - // If `target` is an array, run each item. - if (_.isArray(target)) { - async.eachSeries( - target, - (targetItem, asyncEachSeriesCb) => { - generateTarget( - { - target: targetItem, - parent: generator, - scope: _.cloneDeep(targetScope), - recursiveGenerate: generate, - }, - asyncEachSeriesCb - ); - }, - asyncEachSb - ); - return; - } - - // Otherwise, just run the single target generator/helper. - generateTarget( - { - target, - parent: generator, - scope: targetScope, - recursiveGenerate: generate, - }, - asyncEachSb - ); - }, - - err => { - // Expose a `error` handler in generators. - if (err) { - const errorFn = - generator.error || - function defaultError(err, scope, _cb) { - return _cb(err); - }; - return errorFn(err, scope, sb); - } - - // Expose a `after` handler in generators (on success only). - const afterFn = - generator.after || - function defaultAfter(scope, _cb) { - return _cb(); - }; - return afterFn(scope, sb); - } - ); - }, - }) - ); -} - -module.exports = generate; diff --git a/packages/generators/generate/lib/helpers/copy/index.js b/packages/generators/generate/lib/helpers/copy/index.js deleted file mode 100644 index 59d3c58377..0000000000 --- a/packages/generators/generate/lib/helpers/copy/index.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// Public node modules. -const _ = require('lodash'); -const fs = require('fs-extra'); -const reportback = require('reportback')(); - -// Local dependencies. -const fileHelper = require('../file'); - -/** - * Copy file from one place to another - */ - -module.exports = function(options, cb) { - cb = reportback.extend(cb, { - alreadyExists: 'error', - invalid: 'error', - }); - - // Compute the canonical path to copy from - // given its relative path from its source generator's - // `templates` directory. - const absSrcPath = path.resolve(options.templatesDirectory, options.templatePath); - - fs.readFile(absSrcPath, 'utf8', (err, contents) => { - if (err) { - return cb.error(err); - } - - return fileHelper( - _.merge(options, { - contents, - }), - cb - ); - }); -}; diff --git a/packages/generators/generate/lib/helpers/file/index.js b/packages/generators/generate/lib/helpers/file/index.js deleted file mode 100644 index f6a53ea2f8..0000000000 --- a/packages/generators/generate/lib/helpers/file/index.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// Public node modules. -const _ = require('lodash'); -const async = require('async'); -const fs = require('fs-extra'); -const reportback = require('reportback')(); - -/** - * Generate a file using the specified string - */ - -/* eslint-disable prefer-template */ -module.exports = function(options, cb) { - // Provide default values for switchback. - cb = reportback.extend(cb, { - alreadyExists: 'error', - }); - - // Provide defaults and validate required options. - _.defaults(options, { - force: false, - }); - - const missingOpts = _.difference(['contents', 'rootPath'], Object.keys(options)); - - if (missingOpts.length) { - return cb.invalid(missingOpts); - } - - // In case we ended up here with a relative path, - // resolve it using the process's CWD - const rootPath = path.resolve(process.cwd(), options.rootPath); - - // Only override an existing file if `options.force` is true. - fs.exists(rootPath, exists => { - if (exists && !options.force) { - return cb.alreadyExists('Something else already exists at `' + rootPath + '`.'); - } - - // Don't actually write the file if this is a dry run. - if (options.dry) { - return cb.success(); - } - - async.series( - [ - function deleteExistingFileIfNecessary(cb) { - if (!exists) { - return cb(); - } - return fs.remove(rootPath, cb); - }, - function writeToDisk(cb) { - fs.outputFile(rootPath, options.contents, cb); - }, - ], - cb - ); - }); -}; diff --git a/packages/generators/generate/lib/helpers/folder/index.js b/packages/generators/generate/lib/helpers/folder/index.js deleted file mode 100644 index 47b10d6460..0000000000 --- a/packages/generators/generate/lib/helpers/folder/index.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// Public node modules. -const _ = require('lodash'); -const fs = require('fs-extra'); -const reportback = require('reportback')(); - -/** - * Generate a folder - */ -/* eslint-disable prefer-template */ -module.exports = function(options, cb) { - // Provide default values for cb. - cb = reportback.extend(cb, { - alreadyExists: 'error', - invalid: 'error', - }); - - // Provide defaults and validate required options. - _.defaults(options, { - force: false, - gitkeep: false, - }); - - const missingOpts = _.difference(['rootPath'], Object.keys(options)); - - if (missingOpts.length) { - return cb.invalid(missingOpts); - } - - const rootPath = path.resolve(process.cwd(), options.rootPath); - - // Only override an existing folder if `options.force` is true. - fs.lstat(rootPath, err => { - const exists = !(err && err.code === 'ENOENT'); - if (exists && err) { - return cb.error(err); - } - - if (exists && !options.force) { - return cb.alreadyExists('Something else already exists at `' + rootPath + '`.'); - } - - if (exists) { - fs.remove(rootPath, err => { - if (err) { - return cb.error(err); - } - _afterwards_(); - }); - } else { - _afterwards_(); - } - - function _afterwards_() { - // Don't actually write the directory if this is a dry run. - if (options.dry) { - return cb.success(); - } - - // Create the directory. - fs.mkdirs(rootPath, err => { - if (err) { - return cb.error(err); - } - return cb.success(); - }); - } - }); -}; diff --git a/packages/generators/generate/lib/helpers/jsonfile/index.js b/packages/generators/generate/lib/helpers/jsonfile/index.js deleted file mode 100644 index 1df9f1ef89..0000000000 --- a/packages/generators/generate/lib/helpers/jsonfile/index.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// Public node modules. -const _ = require('lodash'); -const fs = require('fs-extra'); -const reportback = require('reportback')(); - -/** - * Generate a JSON file - */ - -/* eslint-disable prefer-template */ -module.exports = function(options, handlers) { - // Provide default values for handlers. - handlers = reportback.extend(handlers, { - alreadyExists: 'error', - }); - - // Provide defaults and validate required options. - _.defaults(options, { - force: false, - }); - - const missingOpts = _.difference(['rootPath', 'data'], Object.keys(options)); - - if (missingOpts.length) { - return handlers.invalid(missingOpts); - } - - const rootPath = path.resolve(process.cwd(), options.rootPath); - - // Only override an existing file if `options.force` is true. - fs.exists(rootPath, exists => { - if (exists && !options.force) { - return handlers.alreadyExists('Something else already exists at `' + rootPath + '`.'); - } - - if (exists) { - fs.remove(rootPath, err => { - if (err) { - return handlers.error(err); - } - _afterwards_(); - }); - } else { - _afterwards_(); - } - - function _afterwards_() { - fs.outputJSON(rootPath, options.data, { spaces: 2 }, err => { - if (err) { - return handlers.error(err); - } else { - handlers.success(); - } - }); - } - }); -}; diff --git a/packages/generators/generate/lib/helpers/template/index.js b/packages/generators/generate/lib/helpers/template/index.js deleted file mode 100644 index 4cb7c03798..0000000000 --- a/packages/generators/generate/lib/helpers/template/index.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// Public node modules. -const _ = require('lodash'); -const fs = require('fs-extra'); -const reportback = require('reportback')(); - -// Local dependencies. -const fileHelper = require('../file'); - -/** - * Read a dynamic template, compile it using scope. - * Then use `file` helper to write it to its destination. - */ - -module.exports = function(options, cb) { - cb = reportback.extend(cb, { - noTemplate: 'error', - alreadyExists: 'error', - }); - - // Compute the canonical path to a template - // given its relative path from its source generator's - // `templates` directory. - if (_.isFunction(options.templatesDirectory)) { - options.templatesDirectory = options.templatesDirectory(options); - } - - const absTemplatePath = path.resolve(options.templatesDirectory, options.templatePath); - - fs.readFile(absTemplatePath, 'utf8', (err, contents) => { - if (err) { - err = err instanceof Error ? err : new Error(err); - err.message = `Template error: ${err.message}`; - err.path = absTemplatePath; - if (err.code === 'ENOENT') { - return cb.noTemplate(err); - } else { - return cb(err); - } - } - - try { - const compiled = _.template(contents, { - interpolate: /<%=([\s\S]+?)%>/g, - }); - contents = compiled(options); - - // With Lodash templates, HTML entities are escaped by default. - // Default assumption is we don't want that, so we'll reverse it. - if (!options.escapeHTMLEntities) { - contents = _.unescape(contents); - } - } catch (e) { - return cb(e); - } - - return fileHelper( - _.merge(options, { - contents, - }), - cb - ); - }); -}; diff --git a/packages/generators/generate/lib/index.js b/packages/generators/generate/lib/index.js deleted file mode 100644 index 8607e3c5cd..0000000000 --- a/packages/generators/generate/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const reportback = require('reportback')(); - -// Logger. -const logger = require('@strapi/utils').logger; - -// Local dependencies. -const generate = require('./generate'); -const generateTarget = require('./target'); - -/* eslint-disable prefer-template */ -/** - * Generate module(s) - * - * @param {Object} scope - * @param {Function} cb - * - * @return {[Type]} - */ - -module.exports = (scope, cb) => { - cb = cb || {}; - cb = reportback.extend(cb, { - error: cb.error, - success: () => {}, - notStrapiApp: () => {}, - alreadyExists: () => { - return cb.error(); - }, - }); - - // Use configured module name for this `generatorType` if applicable. - const module = '@strapi/generate-' + scope.generatorType; - let generator; - - function throwIfModuleNotFoundError(error, module) { - const isModuleNotFoundError = - error && error.code === 'MODULE_NOT_FOUND' && error.message.match(new RegExp(module)); - if (!isModuleNotFoundError) { - logger.error('Invalid `' + scope.generatorType + '` generator.'); - throw error; - } else { - return error; - } - } - - // Try to require the module or throw if error. - try { - generator = require(module); - } catch (error) { - throwIfModuleNotFoundError(error, module); - } - - if (!generator) { - return logger.error('No generator called `' + scope.generatorType + '` found.'); - } - - generate(generator, scope, cb); -}; - -module.exports.generateTarget = generateTarget; diff --git a/packages/generators/generate/lib/target.js b/packages/generators/generate/lib/target.js deleted file mode 100644 index 57787462e0..0000000000 --- a/packages/generators/generate/lib/target.js +++ /dev/null @@ -1,318 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -/* eslint-disable prefer-template */ -// Node.js core. -const path = require('path'); -const util = require('util'); - -// Public node modules. -const _ = require('lodash'); -const async = require('async'); -const report = require('reportback')(); - -// Local dependencies. -const folderHelper = require('./helpers/folder'); -const templateHelper = require('./helpers/template'); -const jsonFileHelper = require('./helpers/jsonfile'); -const copyHelper = require('./helpers/copy'); - -/** - * generateTarget() - * - * @param {Object} options - */ - -function generateTarget(options, cb) { - const sb = report.extend(cb); - - // Options. - let target = options.target; - let scope = options.scope; - const parentGenerator = options.parent; - const recursiveGenerate = options.recursiveGenerate; - - const maxResolves = 5; - let _resolves = 0; - - async.until( - () => { - return isValidTarget(target) || ++_resolves > maxResolves; - }, - asyncCb => { - parseTarget(target, scope, (err, resolvedTarget) => { - if (err) { - return asyncCb(err); - } - target = resolvedTarget; - return asyncCb(); - }); - }, - err => { - if (err) { - return sb(err); - } - if (!isValidTarget(target)) { - return sb( - new Error( - 'Generator Error :: Could not resolve target `' + - scope.rootPath + - '` (probably a recursive loop)' - ) - ); - } - - // Pass down parent Generator's template directory abs path. - scope.templatesDirectory = parentGenerator.templatesDirectory; - - if (target.copy) { - scope = mergeSubtargetScope( - scope, - typeof target.copy === 'string' - ? { - templatePath: target.copy, - } - : target.copy - ); - return copyHelper(scope, sb); - } - - if (target.folder) { - scope = mergeSubtargetScope(scope, target.folder); - return folderHelper(scope, sb); - } - - if (target.template) { - scope = mergeSubtargetScope( - scope, - typeof target.template === 'string' - ? { - templatePath: target.template, - } - : target.template - ); - - return templateHelper(scope, sb); - } - - if (target.jsonfile) { - if (typeof target.jsonfile === 'object') { - scope = mergeSubtargetScope(scope, target.jsonfile); - } else if (typeof target.jsonfile === 'function') { - scope = _.merge(scope, { - data: target.jsonfile(scope), - }); - } - return jsonFileHelper(scope, sb); - } - - // If we made it here, this must be a recursive generator. - // Now that the generator definition has been resolved, - // call this method recursively on it, passing along our - // callback. - if (++scope._depth > scope.maxHops) { - return sb( - new Error( - '`maxHops` (' + - scope.maxHops + - ') exceeded! There is probably a recursive loop in one of your generators.' - ) - ); - } - return recursiveGenerate(target, scope, sb); - } - ); -} - -module.exports = generateTarget; - -/** - * @param {[Type]} scope Description - * @param {[Type]} subtarget Description - * @return {[Type]} Description - */ - -function mergeSubtargetScope(scope, subtarget) { - return _.merge(scope, _.isObject(subtarget) ? subtarget : {}); -} - -/** - * Known helpers - * - * @type {Array} - */ - -const knownHelpers = ['folder', 'template', 'jsonfile', 'file', 'copy']; - -function targetIsHelper(target) { - return _.some(target, (subTarget, key) => { - return _.includes(knownHelpers, key); - }); -} - -/** - * @param {String|Object} target Description - * @param {Object} scope Description - * @param {Function} cb Description - * @return {[type]} Description - */ - -function parseTarget(target, scope, cb) { - if (typeof target === 'string') { - target = { - generator: target, - }; - } - - // Interpret generator definition. - if (targetIsHelper(target)) { - return cb(null, target); - } - - if (target.generator) { - // Normalize the subgenerator reference. - let subGeneratorRef; - if (typeof target.generator === 'string') { - subGeneratorRef = { - module: target.generator, - }; - } else if (typeof target.generator === 'object') { - subGeneratorRef = target.generator; - } - - if (!subGeneratorRef) { - return cb( - new Error( - 'Generator Error :: Invalid subgenerator referenced for target `' + scope.rootPath + '`' - ) - ); - } - - // Now normalize the sub-generator. - let subGenerator; - - // No `module` means we'll treat this subgenerator as an inline generator definition. - if (!subGeneratorRef.module) { - subGenerator = subGeneratorRef; - if (subGenerator) { - return cb(null, subGenerator); - } - } - - // Otherwise, we'll attempt to load this subgenerator. - if (typeof subGeneratorRef.module === 'string') { - // Lookup the generator by name if a `module` was specified - // This allows the module for a given generator to be - // overridden. - const configuredReference = scope.modules && scope.modules[subGeneratorRef.module]; - - // Refers to a configured module. - // If this generator type is explicitly set to `false`, - // disable the generator. - if (configuredReference) { - return cb(null, configuredReference); - } else if (configuredReference === false) { - return cb(null); - } - - // If `configuredReference` is undefined, continue on - // and try to require the module. - } - - // At this point, `subGeneratorRef.module` should be a string, - // and the best guess at the generator module we're going - // to get. - const module = subGeneratorRef.module; - let requireError; - - // Try requiring it directly as a path. - try { - subGenerator = require(module); - } catch (e0) { - requireError = e0; - } - - // Try the scope's `rootPath`. - if (!subGenerator) { - try { - const asDependencyInRootPath = path.resolve(scope.rootPath, 'node_modules', module); - subGenerator = require(asDependencyInRootPath); - } catch (e1) { - requireError = e1; - } - } - - // Try the current working directory. - if (!subGenerator) { - try { - subGenerator = require(path.resolve(process.cwd(), 'node_modules', module)); - } catch (e1) { - requireError = e1; - } - } - - // If we couldn't find a generator using the configured module, - // try requiring `@strapi/generate-` to get the core generator. - if (!subGenerator && !module.match(/^@strapi\/generate-/)) { - try { - if (process.mainModule.filename.indexOf('yarn') !== -1) { - subGenerator = require(path.resolve( - process.mainModule.paths[2], - '@strapi/generate-' + module - )); - } else { - subGenerator = require(path.resolve( - process.mainModule.paths[1], - '@strapi/generate-' + module - )); - } - } catch (e1) { - requireError = e1; - } - } - - // If we were able to find it, send it back! - if (subGenerator) { - return cb(null, subGenerator); - } - - // But if we still can't find it, give up. - return cb( - new Error( - 'Error: Failed to load `' + - subGeneratorRef.module + - '`...' + - (requireError ? ' (' + requireError + ')' : '') + - '' - ) - ); - } - - return cb( - new Error( - 'Unrecognized generator syntax in `targets["' + - scope.keyPath + - '"]` ::\n' + - util.inspect(target) - ) - ); -} - -/** - * - * @param {[Type]} target Description - * @return {Boolean} Description - */ - -function isValidTarget(target) { - let ok = typeof target === 'object'; - - // Is using a helper. - // Or is another generator def. - ok = ok && (targetIsHelper(target) || _.has(target, 'targets')); - - return ok; -} diff --git a/packages/generators/generate/lib/util.js b/packages/generators/generate/lib/util.js deleted file mode 100644 index 0c1ac3468a..0000000000 --- a/packages/generators/generate/lib/util.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -/** - * From Express core: (MIT License) - * - * Normalize the given path string, - * returning a regular expression. - * - * An empty array should be passed, - * which will contain the placeholder - * key names. For example "/user/:id" will - * then contain ["id"]. - * - * @param {String|RegExp|Array} path - * @param {Array} keys - * @param {Boolean} sensitive - * @param {Boolean} strict - * @return {RegExp} - * @api private - */ - -/* eslint-disable prefer-template */ -/* eslint-disable no-useless-escape */ -const pathRegexp = (path, keys, sensitive, strict) => { - if (toString.call(path) === '[object RegExp]') { - return path; - } - if (Array.isArray(path)) { - path = '(' + path.join('|') + ')'; - } - path = path - .concat(strict ? '' : '/?') - .replace(/\/\(/g, '(?:/') - .replace( - /(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, - (_, slash, format, key, capture, optional, star) => { - keys.push({ - name: key, - optional: !!optional, - }); - slash = slash || ''; - return ( - '' + - (optional ? '' : slash) + - '(?:' + - (optional ? slash : '') + - (format || '') + - (capture || (format && '([^/.]+?)') || '([^/]+?)') + - ')' + - (optional || '') + - (star ? '(/*)?' : '') - ); - } - ) - .replace(/([\/.])/g, '\\$1') - .replace(/\*/g, '(.*)'); - return new RegExp('^' + path + '$', sensitive ? '' : 'i'); -}; - -module.exports = { - pathRegexp, -}; diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index 706ea8f8b4..7f0dd09cf5 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -1,50 +1,12 @@ { "name": "@strapi/generate", - "version": "3.6.7", - "description": "Master of ceremonies for the Strapi generators.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, + "version": "3.6.6", + "description": "Interactive API generator.", + "main": "index.js", + "license": "MIT", "dependencies": { - "async": "^2.6.2", - "fs-extra": "^9.1.0", - "lodash": "4.17.21", - "reportback": "^2.0.2", - "@strapi/utils": "3.6.7" - }, - "author": { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" + "fs-extra": "10.0.0", + "plop": "2.7.4", + "pluralize": "8.0.0" + } } diff --git a/packages/generators/generate-plop/plopfile.js b/packages/generators/generate/plopfile.js similarity index 100% rename from packages/generators/generate-plop/plopfile.js rename to packages/generators/generate/plopfile.js index a1bc2f1634..b7c27b8fb6 100644 --- a/packages/generators/generate-plop/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -10,92 +10,6 @@ module.exports = function(plop) { plop.addHelper('pluralize', text => pluralize(text)); - // Service generator - plop.setGenerator('service', { - description: 'Generate a service for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Service name', - }, - ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/services/{{id}}.js'), - templateFile: 'templates/service.js.hbs', - }, - ], - }); - - // Model generator - plop.setGenerator('model', { - description: 'Generate a model for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Model name', - }, - { - type: 'confirm', - name: 'useDraftAndPublish', - message: 'Use draft and publish?', - }, - ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/models/{{id}}.js'), - templateFile: 'templates/model.js.hbs', - }, - { - type: 'add', - path: join(rootDir, 'api/{{id}}/models/{{id}}.settings.json'), - templateFile: 'templates/model.settings.json.hbs', - }, - ], - }); - - // Controller generator - plop.setGenerator('controller', { - description: 'Generate a controller for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Controller name', - }, - ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/controllers/{{id}}.js'), - templateFile: 'templates/controller.js.hbs', - }, - ], - }); - - // Policy generator - plop.setGenerator('policy', { - description: 'Generate a policy for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Policy name', - }, - ], - actions: [ - { - type: 'add', - path: join(rootDir, 'config/policies/{{id}}.js'), - templateFile: 'templates/policy.js.hbs', - }, - ], - }); - // API generator plop.setGenerator('api', { description: 'Generate a basic API', @@ -140,6 +54,54 @@ module.exports = function(plop) { ], }); + // Controller generator + plop.setGenerator('controller', { + description: 'Generate a controller for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Controller name', + }, + ], + actions: [ + { + type: 'add', + path: join(rootDir, 'api/{{id}}/controllers/{{id}}.js'), + templateFile: 'templates/controller.js.hbs', + }, + ], + }); + + // Model generator + plop.setGenerator('model', { + description: 'Generate a model for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Model name', + }, + { + type: 'confirm', + name: 'useDraftAndPublish', + message: 'Use draft and publish?', + }, + ], + actions: [ + { + type: 'add', + path: join(rootDir, 'api/{{id}}/models/{{id}}.js'), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'api/{{id}}/models/{{id}}.settings.json'), + templateFile: 'templates/model.settings.json.hbs', + }, + ], + }); + // Plugin generator plop.setGenerator('plugin', { description: 'Generate a basic plugin', @@ -181,4 +143,42 @@ module.exports = function(plop) { ]; }, }); + + // Policy generator + plop.setGenerator('policy', { + description: 'Generate a policy for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Policy name', + }, + ], + actions: [ + { + type: 'add', + path: join(rootDir, 'config/policies/{{id}}.js'), + templateFile: 'templates/policy.js.hbs', + }, + ], + }); + + // Service generator + plop.setGenerator('service', { + description: 'Generate a service for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Service name', + }, + ], + actions: [ + { + type: 'add', + path: join(rootDir, 'api/{{id}}/services/{{id}}.js'), + templateFile: 'templates/service.js.hbs', + }, + ], + }); }; diff --git a/packages/generators/generate-plop/templates/README.md.hbs b/packages/generators/generate/templates/README.md.hbs similarity index 100% rename from packages/generators/generate-plop/templates/README.md.hbs rename to packages/generators/generate/templates/README.md.hbs diff --git a/packages/generators/generate-plop/templates/api-routes.json.hbs b/packages/generators/generate/templates/api-routes.json.hbs similarity index 100% rename from packages/generators/generate-plop/templates/api-routes.json.hbs rename to packages/generators/generate/templates/api-routes.json.hbs diff --git a/packages/generators/generate-plop/templates/controller.js.hbs b/packages/generators/generate/templates/controller.js.hbs similarity index 100% rename from packages/generators/generate-plop/templates/controller.js.hbs rename to packages/generators/generate/templates/controller.js.hbs diff --git a/packages/generators/generate-plop/templates/model.js.hbs b/packages/generators/generate/templates/model.js.hbs similarity index 100% rename from packages/generators/generate-plop/templates/model.js.hbs rename to packages/generators/generate/templates/model.js.hbs diff --git a/packages/generators/generate-plop/templates/model.settings.json.hbs b/packages/generators/generate/templates/model.settings.json.hbs similarity index 100% rename from packages/generators/generate-plop/templates/model.settings.json.hbs rename to packages/generators/generate/templates/model.settings.json.hbs diff --git a/packages/generators/generate-plop/templates/plugin-package.json.hbs b/packages/generators/generate/templates/plugin-package.json.hbs similarity index 100% rename from packages/generators/generate-plop/templates/plugin-package.json.hbs rename to packages/generators/generate/templates/plugin-package.json.hbs diff --git a/packages/generators/generate-plop/templates/plugin-routes.json.hbs b/packages/generators/generate/templates/plugin-routes.json.hbs similarity index 100% rename from packages/generators/generate-plop/templates/plugin-routes.json.hbs rename to packages/generators/generate/templates/plugin-routes.json.hbs diff --git a/packages/generators/generate-plop/templates/policy.js.hbs b/packages/generators/generate/templates/policy.js.hbs similarity index 100% rename from packages/generators/generate-plop/templates/policy.js.hbs rename to packages/generators/generate/templates/policy.js.hbs diff --git a/packages/generators/generate-plop/templates/service.js.hbs b/packages/generators/generate/templates/service.js.hbs similarity index 100% rename from packages/generators/generate-plop/templates/service.js.hbs rename to packages/generators/generate/templates/service.js.hbs diff --git a/packages/generators/model/.editorconfig b/packages/generators/model/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/model/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/model/.gitignore b/packages/generators/model/.gitignore deleted file mode 100644 index 47e0ea73cc..0000000000 --- a/packages/generators/model/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - - - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/model/.npmignore b/packages/generators/model/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/model/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/model/.snyk b/packages/generators/model/.snyk deleted file mode 100644 index c9ec6ce334..0000000000 --- a/packages/generators/model/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:35:59.679Z -patch: {} diff --git a/packages/generators/model/LICENSE b/packages/generators/model/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/model/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/model/README.md b/packages/generators/model/README.md deleted file mode 100644 index 39a36505b7..0000000000 --- a/packages/generators/model/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# strapi-generate-model - -[![npm version](https://img.shields.io/npm/v/strapi-generate-model.svg)](https://www.npmjs.org/package/strapi-generate-model) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate-model.svg)](https://www.npmjs.org/package/strapi-generate-model) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate-model.svg)](https://david-dm.org/strapi/strapi-generate-model) -[![Build status](https://travis-ci.org/strapi/strapi-generate-model.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate-model) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -This Strapi generator contains the default files for a model. - -This generator can be called with: - -```bash -$ strapi generate:model modelName apiName -``` - -For example if you want to generate a `group` model for the `user` API: - -```bash -$ strapi generate:model group user -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/model/lib/before.js b/packages/generators/model/lib/before.js deleted file mode 100644 index e169804b8c..0000000000 --- a/packages/generators/model/lib/before.js +++ /dev/null @@ -1,139 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); -const pluralize = require('pluralize'); -const { nameToSlug, nameToCollectionName } = require('@strapi/utils'); - -/* eslint-disable prefer-template */ - -/** - * This `before` function is run before generating targets. - * Validate, configure defaults, get extra dependencies, etc. - * - * @param {Object} scope - * @param {Function} cb - */ - -module.exports = (scope, cb) => { - if (!scope.rootPath || !scope.id) { - return cb.invalid( - 'Usage: `$ strapi generate:model modelName --api apiName --plugin pluginName`' - ); - } - - // Format `id`. - const name = scope.name || nameToSlug(scope.id); - - // `scope.args` are the raw command line arguments. - _.defaults(scope, { - name, - environment: process.env.NODE_ENV || 'development', - }); - - // Determine the destination path. - let filePath; - if (scope.args.api) { - filePath = `./api/${scope.args.api}/models`; - } else if (scope.args.plugin) { - filePath = `./plugins/${scope.args.plugin}/models`; - } else { - filePath = `./api/${name}/models`; - } - - // Take another pass to take advantage of the defaults absorbed in previous passes. - _.defaults(scope, { - rootPath: scope.rootPath, - filePath, - filename: `${name}.js`, - filenameSettings: `${name}.settings.json`, - }); - - // Validate optional attribute arguments. - const invalidAttributes = []; - - if (_.isPlainObject(scope.args.attributes)) { - scope.attributes = scope.args.attributes; - } else { - // Map attributes and split them for CLI. - scope.attributes = scope.args.attributes.map(attribute => { - if (_.isString(attribute)) { - const parts = attribute.split(':'); - - parts[1] = parts[1] || 'string'; - - // Handle invalid attributes. - if (!parts[1] || !parts[0]) { - invalidAttributes.push('Error: Invalid attribute notation `' + attribute + '`.'); - return; - } - - return { - name: _.trim(_.deburr(parts[0].toLowerCase())), - params: { - type: _.trim(_.deburr(parts[1].toLowerCase())), - }, - }; - } else { - return _.has(attribute, 'params.type') ? attribute : undefined; - } - }); - - scope.attributes = _.compact(scope.attributes); - - // Handle invalid action arguments. - // Send back invalidActions. - if (invalidAttributes.length) { - return cb.invalid(invalidAttributes); - } - - // Make sure there aren't duplicates. - if ( - _(scope.attributes.map(attribute => attribute.name)) - .uniq() - .valueOf().length !== scope.attributes.length - ) { - return cb.invalid('Duplicate attributes not allowed!'); - } - - // Render some stringified code from the action template - // and make it available in our scope for use later on. - scope.attributes = scope.attributes.reduce((acc, attribute) => { - acc[attribute.name] = attribute.params; - return acc; - }, {}); - } - - // Set collectionName - scope.collectionName = _.has(scope.args, 'collectionName') - ? scope.args.collectionName - : nameToCollectionName(pluralize(scope.id)); - - // Set description - scope.description = _.has(scope.args, 'description') ? scope.args.description : undefined; - - scope.schema = JSON.stringify( - { - kind: 'collectionType', - collectionName: scope.collectionName, - info: { - name: scope.id, - description: scope.description, - }, - options: { - draftAndPublish: scope.args.draftAndPublish === 'true', - comment: '', - }, - attributes: scope.attributes, - }, - null, - 2 - ); - - // Trigger callback with no error to proceed. - return cb(); -}; diff --git a/packages/generators/model/lib/index.js b/packages/generators/model/lib/index.js deleted file mode 100644 index 1c2a0ef626..0000000000 --- a/packages/generators/model/lib/index.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -/** - * Generate a core API - */ - -module.exports = { - templatesDirectory: path.resolve(__dirname, '..', 'templates'), - before: require('./before'), - targets: { - ':filePath/:filename': { - template: 'model.template', - }, - ':filePath/:filenameSettings': { - template: 'model.settings.template', - }, - }, -}; diff --git a/packages/generators/model/templates/model.settings.template b/packages/generators/model/templates/model.settings.template deleted file mode 100644 index ae62b4b5c5..0000000000 --- a/packages/generators/model/templates/model.settings.template +++ /dev/null @@ -1 +0,0 @@ -<%= schema %> diff --git a/packages/generators/model/templates/model.template b/packages/generators/model/templates/model.template deleted file mode 100644 index dd847efdda..0000000000 --- a/packages/generators/model/templates/model.template +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -/** - * Read the documentation (https://strapi.io/documentation/developer-docs/latest/concepts/models.html#lifecycle-hooks) - * to customize this model - */ - -module.exports = {}; diff --git a/packages/generators/plugin/.editorconfig b/packages/generators/plugin/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/plugin/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/plugin/.gitignore b/packages/generators/plugin/.gitignore deleted file mode 100644 index 47e0ea73cc..0000000000 --- a/packages/generators/plugin/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - - - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/plugin/.npmignore b/packages/generators/plugin/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/plugin/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/plugin/.snyk b/packages/generators/plugin/.snyk deleted file mode 100644 index 49d166c9c1..0000000000 --- a/packages/generators/plugin/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:36:06.569Z -patch: {} diff --git a/packages/generators/plugin/LICENSE b/packages/generators/plugin/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/plugin/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/plugin/README.md b/packages/generators/plugin/README.md deleted file mode 100644 index 08dbf84cc7..0000000000 --- a/packages/generators/plugin/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# strapi-generate-plugin - -[![npm version](https://img.shields.io/npm/v/strapi-generate-plugin.svg)](https://www.npmjs.org/package/strapi-generate-plugin) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate-plugin.svg)](https://www.npmjs.org/package/strapi-generate-plugin) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate-plugin.svg)](https://david-dm.org/strapi/strapi-generate-plugin) -[![Build status](https://travis-ci.org/strapi/strapi-generate-plugin.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate-plugin) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -This Strapi generator contains all the default files for a new plugin. - -This generator can be called with: - -```bash -$ strapi generate:plugin pluginName -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/plugin/files/admin/src/containers/App/index.js b/packages/generators/plugin/files/admin/src/containers/App/index.js deleted file mode 100644 index b2d80ef744..0000000000 --- a/packages/generators/plugin/files/admin/src/containers/App/index.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * This component is the skeleton around the actual pages, and should only - * contain code that should be seen on all pages. (e.g. navigation bar) - * - */ - -import React from 'react'; -import { Switch, Route } from 'react-router-dom'; -import { NotFound } from '@strapi/helper-plugin'; -import pluginId from '../../pluginId'; -import HomePage from '../HomePage'; - -const App = () => { - return ( -
- - - - -
- ); -}; - -export default App; diff --git a/packages/generators/plugin/files/admin/src/containers/HomePage/index.js b/packages/generators/plugin/files/admin/src/containers/HomePage/index.js deleted file mode 100644 index 05c5a6a377..0000000000 --- a/packages/generators/plugin/files/admin/src/containers/HomePage/index.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * - * HomePage - * - */ - -import React, { memo } from 'react'; -// import PropTypes from 'prop-types'; -import pluginId from '../../pluginId'; - -const HomePage = () => { - return ( -
-

{pluginId}'s HomePage

-

Happy coding

-
- ); -}; - -export default memo(HomePage); diff --git a/packages/generators/plugin/files/admin/src/containers/Initializer/index.js b/packages/generators/plugin/files/admin/src/containers/Initializer/index.js deleted file mode 100644 index 71dc50e94c..0000000000 --- a/packages/generators/plugin/files/admin/src/containers/Initializer/index.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * - * Initializer - * - */ - -import { useEffect, useRef } from 'react'; -import PropTypes from 'prop-types'; -import pluginId from '../../pluginId'; - -const Initializer = ({ setPlugin }) => { - const ref = useRef(); - ref.current = setPlugin; - - useEffect(() => { - ref.current(pluginId); - }, []); - - return null; -}; - -Initializer.propTypes = { - setPlugin: PropTypes.func.isRequired, -}; - -export default Initializer; diff --git a/packages/generators/plugin/files/admin/src/index.js b/packages/generators/plugin/files/admin/src/index.js deleted file mode 100644 index ebacea2e5e..0000000000 --- a/packages/generators/plugin/files/admin/src/index.js +++ /dev/null @@ -1,61 +0,0 @@ -import { prefixPluginTranslations } from '@strapi/helper-plugin'; -import pluginPkg from '../../package.json'; -import pluginId from './pluginId'; -import App from './containers/App'; -import Initializer from './containers/Initializer'; - -const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; -const icon = pluginPkg.strapi.icon; -const name = pluginPkg.strapi.name; - -export default { - register(app) { - app.addMenuLink({ - to: `/plugins/${pluginId}`, - icon, - intlLabel: { - id: `${pluginId}.plugin.name`, - defaultMessage: name, - }, - Component: App, - permissions: [ - // Uncomment to set the permissions of the plugin here - // { - // action: '', // the action name should be plugins::plugin-name.actionType - // subject: null, - // }, - ], - }); - app.registerPlugin({ - description: pluginDescription, - icon, - id: pluginId, - initializer: Initializer, - isReady: false, - isRequired: pluginPkg.strapi.required || false, - name, - }); - }, - bootstrap(app) {}, - async registerTrads({ locales }) { - const importedTrads = await Promise.all( - locales.map(locale => { - return import(`./translations/${locale}.json`) - .then(({ default: data }) => { - return { - data: prefixPluginTranslations(data, pluginId), - locale, - }; - }) - .catch(() => { - return { - data: {}, - locale, - }; - }); - }) - ); - - return Promise.resolve(importedTrads); - }, -}; diff --git a/packages/generators/plugin/files/admin/src/pluginId.js b/packages/generators/plugin/files/admin/src/pluginId.js deleted file mode 100644 index f604a009da..0000000000 --- a/packages/generators/plugin/files/admin/src/pluginId.js +++ /dev/null @@ -1,5 +0,0 @@ -const pluginPkg = require('../../package.json'); - -const pluginId = pluginPkg.name.replace(/^@strapi\/plugin-/i, ''); - -module.exports = pluginId; diff --git a/packages/generators/plugin/files/admin/src/translations/en.json b/packages/generators/plugin/files/admin/src/translations/en.json deleted file mode 100644 index 9e26dfeeb6..0000000000 --- a/packages/generators/plugin/files/admin/src/translations/en.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/packages/generators/plugin/files/admin/src/translations/fr.json b/packages/generators/plugin/files/admin/src/translations/fr.json deleted file mode 100644 index 9e26dfeeb6..0000000000 --- a/packages/generators/plugin/files/admin/src/translations/fr.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/packages/generators/plugin/files/admin/src/utils/getTrad.js b/packages/generators/plugin/files/admin/src/utils/getTrad.js deleted file mode 100644 index a2b8632a8d..0000000000 --- a/packages/generators/plugin/files/admin/src/utils/getTrad.js +++ /dev/null @@ -1,5 +0,0 @@ -import pluginId from '../pluginId'; - -const getTrad = id => `${pluginId}.${id}`; - -export default getTrad; diff --git a/packages/generators/plugin/json/package.json.js b/packages/generators/plugin/json/package.json.js deleted file mode 100644 index 5513e29777..0000000000 --- a/packages/generators/plugin/json/package.json.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); - -/** - * Expose main package JSON of the application - * with basic info, dependencies, etc. - */ - -module.exports = scope => { - // Finally, return the JSON. - return _.merge(scope.appPackageJSON || {}, { - name: `strapi-plugin-${scope.id}`, - version: '0.0.0', - description: 'This is the description of the plugin.', - strapi: { - name: scope.id, - icon: 'plug', - description: `Description of ${scope.id} plugin.`, - }, - dependencies: {}, - author: { - name: scope.author || 'A Strapi developer', - email: scope.email || '', - url: scope.website || '', - }, - maintainers: [ - { - name: scope.author || 'A Strapi developer', - email: scope.email || '', - url: scope.website || '', - }, - ], - engines: { - node: '>=12.x. <=14.x.x', - npm: '>=6.0.0', - }, - license: scope.license || 'MIT', - }); -}; diff --git a/packages/generators/plugin/json/routes.json.js b/packages/generators/plugin/json/routes.json.js deleted file mode 100644 index 5456426c81..0000000000 --- a/packages/generators/plugin/json/routes.json.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -/** - * Expose main routes of the generated plugin - */ - -module.exports = scope => { - function generateRoutes() { - return { - routes: [ - { - method: 'GET', - path: '/', - handler: scope.name + '.index', - config: { - policies: [], - }, - }, - ], - }; - } - - return generateRoutes(); -}; diff --git a/packages/generators/plugin/lib/before.js b/packages/generators/plugin/lib/before.js deleted file mode 100644 index 7a922ca08c..0000000000 --- a/packages/generators/plugin/lib/before.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const path = require('path'); -const fs = require('fs-extra'); -const _ = require('lodash'); -const { nameToSlug } = require('@strapi/utils'); - -/** - * This `before` function is run before generating targets. - * Validate, configure defaults, get extra dependencies, etc. - * - * @param {Object} scope - * @param {Function} cb - */ - -module.exports = (scope, cb) => { - if (!scope.rootPath || !scope.id) { - return cb.invalid('Usage: `$ strapi generate:plugin pluginName`'); - } - - // Format `id`. - const name = scope.name || nameToSlug(scope.id); - - // Plugin info. - _.defaults(scope, { - name, - author: scope.author || 'A Strapi developer', - email: scope.email || '', - year: new Date().getFullYear(), - license: 'MIT', - }); - - // Take another pass to take advantage of the defaults absorbed in previous passes. - _.defaults(scope, { - filename: `${name}.js`, - filePath: './plugins', - }); - - const pluginDir = path.resolve(scope.rootPath, 'plugins'); - fs.ensureDirSync(pluginDir); - - // Copy the admin files. - fs.copySync(path.resolve(__dirname, '..', 'files'), path.resolve(pluginDir, name)); - - // Trigger callback with no error to proceed. - return cb.success(); -}; diff --git a/packages/generators/plugin/lib/index.js b/packages/generators/plugin/lib/index.js deleted file mode 100644 index c804258860..0000000000 --- a/packages/generators/plugin/lib/index.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -// FIXME -/* eslint-disable import/extensions */ -// Local dependencies. -const packageJSON = require('../json/package.json.js'); -const routesJSON = require('../json/routes.json.js'); - -/** - * Generate a core API - */ - -module.exports = { - templatesDirectory: path.resolve(__dirname, '..', 'templates'), - before: require('./before'), - targets: { - 'plugins/:name/.gitignore': { - copy: 'gitignore', - }, - - // Use the default `controller` file as a template for - // every generated controller. - 'plugins/:name/controllers/:filename': { - template: 'controller.template', - }, - - // every generated controller. - 'plugins/:name/services/:filename': { - template: 'service.template', - }, - - // Generate routes. - 'plugins/:name/config/routes.json': { - jsonfile: routesJSON, - }, - - // Main package. - 'plugins/:name/package.json': { - jsonfile: packageJSON, - }, - - // Copy dot files. - 'plugins/:name/.editorconfig': { - copy: 'editorconfig', - }, - - 'plugins/:name/.gitattributes': { - copy: 'gitattributes', - }, - - // Copy Markdown files with some information. - 'plugins/:name/README.md': { - template: 'README.md', - }, - }, -}; diff --git a/packages/generators/plugin/templates/README.md b/packages/generators/plugin/templates/README.md deleted file mode 100644 index 324fe31e64..0000000000 --- a/packages/generators/plugin/templates/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Strapi plugin <%= id %> - -A quick description of <%= id %>. diff --git a/packages/generators/plugin/templates/controller.template b/packages/generators/plugin/templates/controller.template deleted file mode 100644 index 6d32cf8c7f..0000000000 --- a/packages/generators/plugin/templates/controller.template +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -/** - * <%= filename %> controller - * - * @description: A set of functions called "actions" of the `<%= name %>` plugin. - */ - -module.exports = { - - /** - * Default action. - * - * @return {Object} - */ - - index: async (ctx) => { - // Add your own logic here. - - // Send 200 `ok` - ctx.send({ - message: 'ok' - }); - } -}; diff --git a/packages/generators/plugin/templates/editorconfig b/packages/generators/plugin/templates/editorconfig deleted file mode 100644 index d4eed8406b..0000000000 --- a/packages/generators/plugin/templates/editorconfig +++ /dev/null @@ -1,7 +0,0 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = false -indent_style = space -indent_size = 2 diff --git a/packages/generators/plugin/templates/gitattributes b/packages/generators/plugin/templates/gitattributes deleted file mode 100644 index 065a11c71d..0000000000 --- a/packages/generators/plugin/templates/gitattributes +++ /dev/null @@ -1,103 +0,0 @@ -# From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes - -# Handle line endings automatically for files detected as text -# and leave all files detected as binary untouched. -* text=auto - -# -# The above will handle all files NOT found below -# - -# -## These files are text and should be normalized (Convert crlf => lf) -# - -# source code -*.php text -*.css text -*.sass text -*.scss text -*.less text -*.styl text -*.js text eol=lf -*.coffee text -*.json text -*.htm text -*.html text -*.xml text -*.svg text -*.txt text -*.ini text -*.inc text -*.pl text -*.rb text -*.py text -*.scm text -*.sql text -*.sh text -*.bat text - -# templates -*.ejs text -*.hbt text -*.jade text -*.haml text -*.hbs text -*.dot text -*.tmpl text -*.phtml text - -# git config -.gitattributes text -.gitignore text -.gitconfig text - -# code analysis config -.jshintrc text -.jscsrc text -.jshintignore text -.csslintrc text - -# misc config -*.yaml text -*.yml text -.editorconfig text - -# build config -*.npmignore text -*.bowerrc text - -# Heroku -Procfile text -.slugignore text - -# Documentation -*.md text -LICENSE text -AUTHORS text - - -# -## These files are binary and should be left untouched -# - -# (binary is a macro for -text -diff) -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.mov binary -*.mp4 binary -*.mp3 binary -*.flv binary -*.fla binary -*.swf binary -*.gz binary -*.zip binary -*.7z binary -*.ttf binary -*.eot binary -*.woff binary -*.pyc binary -*.pdf binary diff --git a/packages/generators/plugin/templates/gitignore b/packages/generators/plugin/templates/gitignore deleted file mode 100644 index afe256bf30..0000000000 --- a/packages/generators/plugin/templates/gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Don't check auto-generated stuff into git -coverage -node_modules -stats.json -package-lock.json - -# Cruft -.DS_Store -npm-debug.log -.idea diff --git a/packages/generators/plugin/templates/service.template b/packages/generators/plugin/templates/service.template deleted file mode 100644 index 5891b61a5a..0000000000 --- a/packages/generators/plugin/templates/service.template +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -/** - * <%= filename %> service - * - * @description: A set of functions similar to controller's actions to avoid code duplication. - */ - -module.exports = { - -}; diff --git a/packages/generators/policy/.editorconfig b/packages/generators/policy/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/policy/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/policy/.gitignore b/packages/generators/policy/.gitignore deleted file mode 100644 index 47e0ea73cc..0000000000 --- a/packages/generators/policy/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - - - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/policy/.npmignore b/packages/generators/policy/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/policy/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/policy/.snyk b/packages/generators/policy/.snyk deleted file mode 100644 index 2d38b73373..0000000000 --- a/packages/generators/policy/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:36:09.263Z -patch: {} diff --git a/packages/generators/policy/LICENSE b/packages/generators/policy/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/policy/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/policy/README.md b/packages/generators/policy/README.md deleted file mode 100644 index d538dd3265..0000000000 --- a/packages/generators/policy/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# strapi-generate-policy - -[![npm version](https://img.shields.io/npm/v/strapi-generate-policy.svg)](https://www.npmjs.org/package/strapi-generate-policy) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate-policy.svg)](https://www.npmjs.org/package/strapi-generate-policy) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate-policy.svg)](https://david-dm.org/strapi/strapi-generate-policy) -[![Build status](https://travis-ci.org/strapi/strapi-generate-policy.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate-policy) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -This Strapi generator contains the default files for a policy. - -This generator can be called with: - -```bash -$ strapi generate:policy policyName apiName -``` - -For example if you want to generate a `isAuthenticated` policy for the `user` API: - -```bash -$ strapi generate:policy isAuthenticated user -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/policy/lib/before.js b/packages/generators/policy/lib/before.js deleted file mode 100644 index bac068d8fe..0000000000 --- a/packages/generators/policy/lib/before.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); -const { nameToSlug } = require('@strapi/utils'); - -/** - * This `before` function is run before generating targets. - * Validate, configure defaults, get extra dependencies, etc. - * - * @param {Object} scope - * @param {Function} cb - */ - -/* eslint-disable prefer-template */ -module.exports = (scope, cb) => { - if (!scope.rootPath || !scope.id) { - return cb.invalid( - 'Usage: `$ strapi generate:policy policyName --api apiName --plugin pluginName`' - ); - } - - // Format `id`. - const name = scope.name || nameToSlug(scope.id); - - let filePath; - if (scope.args.api) { - filePath = `./api/${scope.args.api}/config/policies`; - } else if (scope.args.plugin) { - filePath = `./plugins/${scope.args.plugin}/config/policies`; - } else { - filePath = './config/policies'; - } - - // Take another pass to take advantage of the defaults absorbed in previous passes. - _.defaults(scope, { - name, - filePath, - filename: `${name}.js`, - }); - - // Trigger callback with no error to proceed. - return cb(); -}; diff --git a/packages/generators/policy/lib/index.js b/packages/generators/policy/lib/index.js deleted file mode 100644 index d2fb224abb..0000000000 --- a/packages/generators/policy/lib/index.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -/** - * Generate a core API - */ - -module.exports = { - templatesDirectory: path.resolve(__dirname, '..', 'templates'), - before: require('./before'), - targets: { - ':filePath/:filename': { - template: 'policy.template', - }, - }, -}; diff --git a/packages/generators/policy/templates/policy.template b/packages/generators/policy/templates/policy.template deleted file mode 100644 index 0cf499a133..0000000000 --- a/packages/generators/policy/templates/policy.template +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -/** - * `<%= id %>` policy. - */ - -module.exports = async (ctx, next) => { - // Add your own logic here. - console.log('In <%= id %> policy.'); - - await next(); -}; diff --git a/packages/generators/service/.editorconfig b/packages/generators/service/.editorconfig deleted file mode 100644 index 473e45184b..0000000000 --- a/packages/generators/service/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[{package.json,*.yml}] -indent_style = space -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/generators/service/.gitignore b/packages/generators/service/.gitignore deleted file mode 100644 index 47e0ea73cc..0000000000 --- a/packages/generators/service/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - - - -############################ -# Tests -############################ - -testApp -coverage diff --git a/packages/generators/service/.npmignore b/packages/generators/service/.npmignore deleted file mode 100644 index 4ae4300882..0000000000 --- a/packages/generators/service/.npmignore +++ /dev/null @@ -1,109 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -ssl -.editorconfig -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -.snyk - - - -############################ -# Tests -############################ - -test -tests -__tests__ -jest.config.js -testApp -coverage diff --git a/packages/generators/service/.snyk b/packages/generators/service/.snyk deleted file mode 100644 index 7aca8c3f35..0000000000 --- a/packages/generators/service/.snyk +++ /dev/null @@ -1,9 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.12.0 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - shelljs: - - '*': - reason: testing - expires: 2019-01-04T14:36:25.992Z -patch: {} diff --git a/packages/generators/service/LICENSE b/packages/generators/service/LICENSE deleted file mode 100644 index db018546b5..0000000000 --- a/packages/generators/service/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-present Strapi Solutions SAS - -Portions of the Strapi software are licensed as follows: - -* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". - -* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. - -MIT Expat License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/generators/service/README.md b/packages/generators/service/README.md deleted file mode 100644 index a6b1967faa..0000000000 --- a/packages/generators/service/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# strapi-generate-service - -[![npm version](https://img.shields.io/npm/v/strapi-generate-service.svg)](https://www.npmjs.org/package/strapi-generate-service) -[![npm downloads](https://img.shields.io/npm/dm/strapi-generate-service.svg)](https://www.npmjs.org/package/strapi-generate-service) -[![npm dependencies](https://david-dm.org/strapi/strapi-generate-service.svg)](https://david-dm.org/strapi/strapi-generate-service) -[![Build status](https://travis-ci.org/strapi/strapi-generate-service.svg?branch=master)](https://travis-ci.org/strapi/strapi-generate-service) -[![Slack status](https://slack.strapi.io/badge.svg)](https://slack.strapi.io) - -This Strapi generator contains the default files for a service. - -This generator can be called with: - -```bash -$ strapi generate:service serviceName apiName -``` - -For example if you want to generate a `sendEmail` service for the `email` API: - -```bash -$ strapi generate:service sendEmail email -``` - -## Resources - -- [License](LICENSE) - -## Links - -- [Strapi website](https://strapi.io/) -- [Strapi community on Slack](https://slack.strapi.io) -- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/generators/service/lib/before.js b/packages/generators/service/lib/before.js deleted file mode 100644 index a3ed04148e..0000000000 --- a/packages/generators/service/lib/before.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); -const { nameToSlug } = require('@strapi/utils'); - -/** - * This `before` function is run before generating targets. - * Validate, configure defaults, get extra dependencies, etc. - * - * @param {Object} scope - * @param {Function} cb - */ - -/* eslint-disable prefer-template */ -module.exports = (scope, cb) => { - if (!scope.rootPath || !scope.id) { - return cb.invalid( - 'Usage: `$ strapi generate:service serviceName --api apiName --plugin pluginName`' - ); - } - - // Format `id`. - const name = scope.name || nameToSlug(scope.id); - - // `scope.args` are the raw command line arguments. - _.defaults(scope, { - name, - api: scope.args.api || scope.id, - }); - - // Determine the destination path. - let filePath; - if (scope.args.api) { - filePath = `./api/${scope.args.api}/services`; - } else if (scope.args.plugin) { - filePath = `./plugins/${scope.args.plugin}/services`; - } else { - filePath = `./api/${name}/services`; - } - - // Take another pass to take advantage of the defaults absorbed in previous passes. - _.defaults(scope, { - rootPath: scope.rootPath, - filePath, - filename: `${name}.js`, - }); - - // Trigger callback with no error to proceed. - return cb(); -}; diff --git a/packages/generators/service/lib/index.js b/packages/generators/service/lib/index.js deleted file mode 100644 index acc192c01e..0000000000 --- a/packages/generators/service/lib/index.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Node.js core. -const path = require('path'); - -/** - * Generate a core API - */ - -module.exports = { - templatesDirectory: path.resolve(__dirname, '..', 'templates'), - before: require('./before'), - targets: { - ':filePath/:filename': { - template: 'service.template', - }, - }, -}; diff --git a/packages/generators/service/templates/service.template b/packages/generators/service/templates/service.template deleted file mode 100644 index 2b4df98b29..0000000000 --- a/packages/generators/service/templates/service.template +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -/** - * `<%= name %>` service. - */ - -module.exports = { - // exampleService: (arg1, arg2) => { - // return isUserOnline(arg1, arg2); - // } -}; diff --git a/yarn.lock b/yarn.lock index 632f9ff105..841132c17e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2971,11 +2971,6 @@ estree-walker "^1.0.1" picomatch "^2.2.2" -"@sailshq/lodash@^3.10.2", "@sailshq/lodash@^3.10.3": - version "3.10.4" - resolved "https://registry.yarnpkg.com/@sailshq/lodash/-/lodash-3.10.4.tgz#2299648a81a67f4c6ee222c6cf8e261bd9c3fa50" - integrity sha512-YXJqp9gdHcZKAmBY/WnwFpPtNQp2huD/ME2YMurH2YHJvxrVzYsmpKw/pb7yINArRpp8E++fwbQd3ajYXGA45Q== - "@sendgrid/client@^6.4.0": version "6.5.5" resolved "https://registry.yarnpkg.com/@sendgrid/client/-/client-6.5.5.tgz#66cf569445d98a795998a894bb432a9939ead7c3" @@ -6231,16 +6226,6 @@ caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219: resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001245.tgz#45b941bbd833cb0fa53861ff2bae746b3c6ca5d4" integrity sha512-768fM9j1PKXpOCKws6eTo3RHmvTUsG9UrpT4WoREFeZgJBTi4/X9g565azS/rVUGtqb8nt7FjLeF5u4kukERnA== -captains-log@^2.0.2: - version "2.0.3" - resolved "https://registry.yarnpkg.com/captains-log/-/captains-log-2.0.3.tgz#4fa10b4f389a62299872826fc6736704e7483469" - integrity sha512-hKlNLw/4Qz1vPDhAbn3pRexi8fzY7d3SwX/BtI2lMG09UqK1W1mf2pYFslau3ZPWxdcwBBcsLLi9ngs+xhqD2Q== - dependencies: - "@sailshq/lodash" "^3.10.2" - chalk "1.1.3" - rc "1.2.8" - semver "5.4.1" - capture-exit@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4" @@ -6253,7 +6238,15 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= -chalk@1.1.3, chalk@^1.1.3: +chalk@4.1.1, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad" + integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" integrity sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg= @@ -6264,14 +6257,6 @@ chalk@1.1.3, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@4.1.1, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad" - integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.1, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" @@ -17078,7 +17063,7 @@ rc-util@^4.5.1: react-lifecycles-compat "^3.0.4" shallowequal "^1.1.0" -rc@1.2.8, rc@^1.2.7, rc@^1.2.8: +rc@^1.2.7, rc@^1.2.8: version "1.2.8" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== @@ -17868,14 +17853,6 @@ repeating@^2.0.0: dependencies: is-finite "^1.0.0" -reportback@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/reportback/-/reportback-2.0.2.tgz#8957ff5f6b1675e0284c1a14001a24463c0f9900" - integrity sha512-EOF6vRKfXjI7ydRoOdXXeRTK1zgWq7mep8/32patt0FOnBap32eTSw6yCea/o0025PHmVB8crx5OxzZJ+/P34g== - dependencies: - captains-log "^2.0.2" - switchback "^2.0.1" - request-compose@^2.1.4: version "2.1.4" resolved "https://registry.yarnpkg.com/request-compose/-/request-compose-2.1.4.tgz#d427d614d31c0300e5893cbeaf86e51da1dff445" @@ -18423,11 +18400,6 @@ semver-diff@^3.1.1: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -semver@5.4.1: - version "5.4.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e" - integrity sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg== - semver@7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e" @@ -20089,13 +20061,6 @@ swap-case@^1.1.0: lower-case "^1.1.1" upper-case "^1.1.1" -switchback@^2.0.1: - version "2.0.5" - resolved "https://registry.yarnpkg.com/switchback/-/switchback-2.0.5.tgz#2f50c91118f659c42e03c0f2bdb094f868c45336" - integrity sha512-w9gnsTxR5geOKt45QUryhDP9KTLcOAqje9usR2VQ2ng8DfhaF+mkIcArxioMP/p6Z/ecKE58i2/B0DDlMJK1jw== - dependencies: - "@sailshq/lodash" "^3.10.3" - symbol-observable@^1.0.4: version "1.2.0" resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" From fd255077e3d6fb210e3f3a2bd6259331edf1f1cb Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 23 Aug 2021 16:45:44 +0200 Subject: [PATCH 09/26] Fix merge conflicts --- packages/generators/api/package.json | 48 -------------------- packages/generators/controller/package.json | 48 -------------------- packages/generators/generate/package.json | 2 +- packages/generators/model/package.json | 49 --------------------- packages/generators/plugin/package.json | 48 -------------------- packages/generators/policy/package.json | 48 -------------------- packages/generators/service/package.json | 48 -------------------- 7 files changed, 1 insertion(+), 290 deletions(-) delete mode 100644 packages/generators/api/package.json delete mode 100644 packages/generators/controller/package.json delete mode 100644 packages/generators/model/package.json delete mode 100644 packages/generators/plugin/package.json delete mode 100644 packages/generators/policy/package.json delete mode 100644 packages/generators/service/package.json diff --git a/packages/generators/api/package.json b/packages/generators/api/package.json deleted file mode 100644 index 73970100b0..0000000000 --- a/packages/generators/api/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-api", - "version": "3.6.7", - "description": "Generate an API for a Strapi application.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "pluralize": "^8.0.0", - "@strapi/utils": "3.6.7" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/controller/package.json b/packages/generators/controller/package.json deleted file mode 100644 index 21a12c4605..0000000000 --- a/packages/generators/controller/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-controller", - "version": "3.6.7", - "description": "Generate a controller for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "controller", - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "@strapi/utils": "3.6.7" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index 7f0dd09cf5..83a64c206f 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -1,6 +1,6 @@ { "name": "@strapi/generate", - "version": "3.6.6", + "version": "3.6.7", "description": "Interactive API generator.", "main": "index.js", "license": "MIT", diff --git a/packages/generators/model/package.json b/packages/generators/model/package.json deleted file mode 100644 index bfb4791d1b..0000000000 --- a/packages/generators/model/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "@strapi/generate-model", - "version": "3.6.7", - "description": "Generate a model for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "model", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "pluralize": "^8.0.0", - "@strapi/utils": "3.6.7" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/plugin/package.json b/packages/generators/plugin/package.json deleted file mode 100644 index fc78e19b91..0000000000 --- a/packages/generators/plugin/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-plugin", - "version": "3.6.7", - "description": "Generate an plugin for a Strapi application.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "fs-extra": "^9.1.0", - "lodash": "4.17.21", - "@strapi/utils": "3.6.7" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/policy/package.json b/packages/generators/policy/package.json deleted file mode 100644 index 3acc3e6917..0000000000 --- a/packages/generators/policy/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-policy", - "version": "3.6.7", - "description": "Generate a policy for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "policy", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "@strapi/utils": "3.6.7" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/service/package.json b/packages/generators/service/package.json deleted file mode 100644 index 32f234fa28..0000000000 --- a/packages/generators/service/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-service", - "version": "3.6.7", - "description": "Generate a service for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "service", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "@strapi/utils": "3.6.7" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} From 4e7afbd0daf54a468e421b26dde0847452e6b2f1 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Mon, 23 Aug 2021 18:23:21 +0200 Subject: [PATCH 10/26] start fix for generate api in ctb --- .../services/content-types.js | 18 +----------------- packages/core/strapi/bin/strapi.js | 2 +- packages/generators/generate/index.js | 19 ++++++++++++++++++- packages/generators/generate/package.json | 1 + yarn.lock | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/core/content-type-builder/services/content-types.js b/packages/core/content-type-builder/services/content-types.js index 21bd99adee..8a99ecc4f4 100644 --- a/packages/core/content-type-builder/services/content-types.js +++ b/packages/core/content-type-builder/services/content-types.js @@ -130,23 +130,7 @@ const createContentType = async ({ contentType, components = [] }, options = {}) * @param {string} name */ const generateAPI = ({ name, kind = 'collectionType' }) => { - return new Promise((resolve, reject) => { - const scope = { - generatorType: 'api', - id: nameToSlug(name), - name: nameToSlug(name), - rootPath: strapi.dir, - args: { - attributes: {}, - kind, - }, - }; - - generator(scope, { - success: () => resolve(), - error: err => reject(err), - }); - }); + return generator.generate('api', { id: nameToSlug(name), kind }); }; /** diff --git a/packages/core/strapi/bin/strapi.js b/packages/core/strapi/bin/strapi.js index c16a7c31db..2998f282d1 100755 --- a/packages/core/strapi/bin/strapi.js +++ b/packages/core/strapi/bin/strapi.js @@ -124,7 +124,7 @@ program .description('Launch interactive API generator') .action(() => { checkCwdIsStrapiApp('generate'); - require('@strapi/generate')(); + require('@strapi/generate').execute(); }); // `$ strapi generate:template ` diff --git a/packages/generators/generate/index.js b/packages/generators/generate/index.js index d1cf30d16f..4fa4e4a501 100644 --- a/packages/generators/generate/index.js +++ b/packages/generators/generate/index.js @@ -4,7 +4,24 @@ process.argv.splice(2, 1); const { join } = require('path'); const { Plop, run } = require('plop'); +const nodePlop = require('node-plop'); -module.exports = () => { +const execute = () => { Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, run); }; + +const generate = async (action, options) => { + const plop = nodePlop(join(__dirname, 'plopfile.js')); + + const generator = plop.getGenerator(action); + await generator.runActions(options, { + onSuccess: () => {}, + onFailure: () => {}, + onComment: () => {}, + }); +}; + +module.exports = { + generate, + execute, +}; diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index 83a64c206f..742767fd0c 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -6,6 +6,7 @@ "license": "MIT", "dependencies": { "fs-extra": "10.0.0", + "node-plop": "0.26.2", "plop": "2.7.4", "pluralize": "8.0.0" } diff --git a/yarn.lock b/yarn.lock index 841132c17e..ed15134dcb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14764,7 +14764,7 @@ node-notifier@^8.0.0: uuid "^8.3.0" which "^2.0.2" -node-plop@~0.26.2: +node-plop@0.26.2, node-plop@~0.26.2: version "0.26.2" resolved "https://registry.yarnpkg.com/node-plop/-/node-plop-0.26.2.tgz#c2523596dab4e28360e615b768b11b4d60d5b1b9" integrity sha512-q444beWkMvZwAiYC3BRGJUHgRlpOItQHy+xdy6egXg8KjxDY/Ro309spQTNvH01qK9A8XF6pc0xLKbrHDpxW7w== From 92a12ce1e31f0ff699c610cd74954c660fa752d6 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Tue, 24 Aug 2021 11:46:04 +0200 Subject: [PATCH 11/26] add api and plugin prompt arguments --- packages/generators/generate/plopfile.js | 256 +++++++++++++----- .../templates/model.settings.json.hbs | 2 +- 2 files changed, 194 insertions(+), 64 deletions(-) diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generate/plopfile.js index b7c27b8fb6..ecacc3f671 100644 --- a/packages/generators/generate/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -4,8 +4,61 @@ const { join } = require('path'); const fs = require('fs-extra'); const pluralize = require('pluralize'); +const rootDir = process.cwd(); + +const getFilePath = destination => { + if (destination === 'api') { + return `api/{{api}}`; + } + + if (destination === 'plugin') { + return `plugins/{{plugin}}`; + } + + return `api/{{id}}`; +}; + +const getDestinationPrompts = action => { + return [ + { + type: 'list', + name: 'destination', + message: `Where do you want to add this ${action}?`, + choices: [ + { + name: `Add ${action} to ${action === 'policy' ? 'root of project' : 'new API'}`, + value: 'new', + }, + { name: `Add ${action} to existing API`, value: 'api' }, + { name: `Add ${action} to existing plugin`, value: 'plugin' }, + ], + }, + { + when: answers => answers.destination === 'api', + type: 'input', + message: 'Which API is this for?', + name: 'api', + validate: async input => { + const exists = await fs.pathExists(join(rootDir, `api/${input}`)); + + return exists || 'That api does not exist, please try again'; + }, + }, + { + when: answers => answers.destination === 'plugin', + type: 'input', + message: 'Which plugin is this for?', + name: 'plugin', + validate: async input => { + const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); + + return exists || 'That plugin does not exist, please try again'; + }, + }, + ]; +}; + module.exports = function(plop) { - const rootDir = process.cwd(); plop.setWelcomeMessage('Strapi Generators'); plop.addHelper('pluralize', text => pluralize(text)); @@ -19,39 +72,81 @@ module.exports = function(plop) { name: 'id', message: 'API name', }, + { + type: 'list', + name: 'kind', + message: 'Please choose the model type', + choices: [ + { name: 'Collection Type', value: 'collectionType' }, + { name: 'Singe Type', value: 'singleType' }, + ], + }, + { + type: 'confirm', + name: 'isPluginApi', + message: 'Is this API for a plugin?', + }, + { + when: answers => answers.isPluginApi, + type: 'input', + name: 'plugin', + message: 'Plugin name', + validate: async input => { + const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); + + return exists || 'That plugin does not exist, please try again'; + }, + }, { type: 'confirm', name: 'useDraftAndPublish', message: 'Use draft and publish?', }, ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/config/routes.json'), - templateFile: 'templates/api-routes.json.hbs', - }, - { - type: 'add', - path: join(rootDir, 'api/{{id}}/controllers/{{id}}.js'), - templateFile: 'templates/controller.js.hbs', - }, - { - type: 'add', - path: join(rootDir, 'api/{{id}}/models/{{id}}.js'), - templateFile: 'templates/model.js.hbs', - }, - { - type: 'add', - path: join(rootDir, 'api/{{id}}/models/{{id}}.settings.json'), - templateFile: 'templates/model.settings.json.hbs', - }, - { - type: 'add', - path: join(rootDir, 'api/{{id}}/services/{{id}}.js'), - templateFile: 'templates/service.js.hbs', - }, - ], + actions: answers => { + let filePath; + if (answers.isPluginApi && answers.plugin) { + filePath = `plugins/{{plugin}}`; + } else { + filePath = `api/{{id}}`; + } + + const baseActions = [ + { + type: 'add', + path: join(rootDir, `${filePath}/controllers/{{id}}.js`), + templateFile: 'templates/controller.js.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.js`), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + templateFile: 'templates/model.settings.json.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/services/{{id}}.js`), + templateFile: 'templates/service.js.hbs', + }, + ]; + + if (answers.isPluginApi) { + return baseActions; + } else { + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/config/routes.json`), + templateFile: 'templates/api-routes.json.hbs', + }, + ...baseActions, + ]; + } + }, }); // Controller generator @@ -63,14 +158,19 @@ module.exports = function(plop) { name: 'id', message: 'Controller name', }, + ...getDestinationPrompts('controller'), ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/controllers/{{id}}.js'), - templateFile: 'templates/controller.js.hbs', - }, - ], + actions: answers => { + const filePath = getFilePath(answers.destination); + + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/controllers/{{id}}.js`), + templateFile: 'templates/controller.js.hbs', + }, + ]; + }, }); // Model generator @@ -82,24 +182,38 @@ module.exports = function(plop) { name: 'id', message: 'Model name', }, + { + type: 'list', + name: 'kind', + message: 'Please choose the model type', + choices: [ + { name: 'Collection Type', value: 'collectionType' }, + { name: 'Singe Type', value: 'singleType' }, + ], + }, + ...getDestinationPrompts('model'), { type: 'confirm', name: 'useDraftAndPublish', message: 'Use draft and publish?', }, ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/models/{{id}}.js'), - templateFile: 'templates/model.js.hbs', - }, - { - type: 'add', - path: join(rootDir, 'api/{{id}}/models/{{id}}.settings.json'), - templateFile: 'templates/model.settings.json.hbs', - }, - ], + actions: answers => { + const filePath = getFilePath(answers.destination); + + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.js`), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + templateFile: 'templates/model.settings.json.hbs', + }, + ]; + }, }); // Plugin generator @@ -112,8 +226,8 @@ module.exports = function(plop) { message: 'Plugin name', }, ], - actions: data => { - fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', data.id)); + actions: answers => { + fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', answers.id)); return [ { type: 'add', @@ -153,14 +267,26 @@ module.exports = function(plop) { name: 'id', message: 'Policy name', }, + ...getDestinationPrompts('policy'), ], - actions: [ - { - type: 'add', - path: join(rootDir, 'config/policies/{{id}}.js'), - templateFile: 'templates/policy.js.hbs', - }, - ], + actions: answers => { + let filePath; + if (answers.destination === 'api') { + filePath = `api/{{api}}`; + } else if (answers.destination === 'plugin') { + filePath = `plugins/{{plugin}}`; + } else { + filePath = ``; + } + + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/config/policies/{{id}}.js`), + templateFile: 'templates/policy.js.hbs', + }, + ]; + }, }); // Service generator @@ -172,13 +298,17 @@ module.exports = function(plop) { name: 'id', message: 'Service name', }, + ...getDestinationPrompts('service'), ], - actions: [ - { - type: 'add', - path: join(rootDir, 'api/{{id}}/services/{{id}}.js'), - templateFile: 'templates/service.js.hbs', - }, - ], + actions: answers => { + const filePath = getFilePath(answers.destination); + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/services/{{id}}.js`), + templateFile: 'templates/service.js.hbs', + }, + ]; + }, }); }; diff --git a/packages/generators/generate/templates/model.settings.json.hbs b/packages/generators/generate/templates/model.settings.json.hbs index 8e685c01da..c0ddaabb18 100644 --- a/packages/generators/generate/templates/model.settings.json.hbs +++ b/packages/generators/generate/templates/model.settings.json.hbs @@ -1,6 +1,6 @@ { - "kind": "collectionType", + "kind": "{{kind}}", "collectionName": "{{id}}", "info": { "name": "{{id}}" From b9c5595aea060eca7c23ddc4a10f906b2362aeb1 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Thu, 26 Aug 2021 10:15:16 +0200 Subject: [PATCH 12/26] add attributes --- packages/generators/generate/custom-prompt.js | 27 ++++++++++++++ packages/generators/generate/package.json | 2 + packages/generators/generate/plopfile.js | 8 ++++ yarn.lock | 37 ++++++++++++++++++- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 packages/generators/generate/custom-prompt.js diff --git a/packages/generators/generate/custom-prompt.js b/packages/generators/generate/custom-prompt.js new file mode 100644 index 0000000000..3cf0f1225b --- /dev/null +++ b/packages/generators/generate/custom-prompt.js @@ -0,0 +1,27 @@ +'use strict'; + +const inquirer = require('inquirer'); + +const getAttributes = async (attributes = []) => { + const prompts = [ + { + type: 'input', + name: 'inputValue', + message: 'Enter some input: ', + }, + { + type: 'confirm', + name: 'again', + message: 'Enter another input? ', + default: true, + }, + ]; + + // eslint-disable-next-line + const { again, ...answers } = await inquirer.prompt(prompts); + + const newInputs = [...attributes, answers]; + return again ? getAttributes(newInputs) : newInputs; +}; + +module.exports = getAttributes; diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index 742767fd0c..5ffd56e15c 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -6,6 +6,8 @@ "license": "MIT", "dependencies": { "fs-extra": "10.0.0", + "inquirer": "8.1.2", + "inquirer-recursive": "0.0.7", "node-plop": "0.26.2", "plop": "2.7.4", "pluralize": "8.0.0" diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generate/plopfile.js index ecacc3f671..66f75a313d 100644 --- a/packages/generators/generate/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -173,6 +173,7 @@ module.exports = function(plop) { }, }); + plop.setPrompt('recursive', require('inquirer-recursive')); // Model generator plop.setGenerator('model', { description: 'Generate a model for an API', @@ -192,6 +193,10 @@ module.exports = function(plop) { ], }, ...getDestinationPrompts('model'), + { + type: 'addAttributes', + name: 'attributes', + }, { type: 'confirm', name: 'useDraftAndPublish', @@ -216,6 +221,9 @@ module.exports = function(plop) { }, }); + const { prompts } = plop.inquirer.prompt; + console.log(prompts); + // Plugin generator plop.setGenerator('plugin', { description: 'Generate a basic plugin', diff --git a/yarn.lock b/yarn.lock index 4a8b1cc33b..8ff04ea032 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11159,6 +11159,14 @@ init-package-json@^1.10.3: validate-npm-package-license "^3.0.1" validate-npm-package-name "^3.0.0" +inquirer-recursive@0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/inquirer-recursive/-/inquirer-recursive-0.0.7.tgz#09f65757e3ee10273d8c6b97e36663484741dba5" + integrity sha512-z15FD5N3GrzXM7OwEijm/9FbZzUiQUJQxrtUM0mOy3KeKshp3v/FhjspM8E3a9IgG6sYlN619lHpAdupn90ikQ== + dependencies: + inquirer "^7.3.3" + lodash "^4.17.20" + inquirer@8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.1.0.tgz#68ce5ce5376cf0e89765c993d8b7c1e62e184d69" @@ -11179,6 +11187,26 @@ inquirer@8.1.0: strip-ansi "^6.0.0" through "^2.3.6" +inquirer@8.1.2: + version "8.1.2" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.1.2.tgz#65b204d2cd7fb63400edd925dfe428bafd422e3d" + integrity sha512-DHLKJwLPNgkfwNmsuEUKSejJFbkv0FMO9SMiQbjI3n5NQuCrSIBqP66ggqyz2a6t2qEolKrMjhQ3+W/xXgUQ+Q== + dependencies: + ansi-escapes "^4.2.1" + chalk "^4.1.1" + cli-cursor "^3.1.0" + cli-width "^3.0.0" + external-editor "^3.0.3" + figures "^3.0.0" + lodash "^4.17.21" + mute-stream "0.0.8" + ora "^5.3.0" + run-async "^2.4.0" + rxjs "^7.2.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + through "^2.3.6" + inquirer@^6.2.0, inquirer@^6.2.1, inquirer@^6.3.1: version "6.5.2" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.5.2.tgz#ad50942375d036d327ff528c08bd5fab089928ca" @@ -11198,7 +11226,7 @@ inquirer@^6.2.0, inquirer@^6.2.1, inquirer@^6.3.1: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^7.1.0: +inquirer@^7.1.0, inquirer@^7.3.3: version "7.3.3" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.3.tgz#04d176b2af04afc157a83fd7c100e98ee0aad003" integrity sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA== @@ -18254,6 +18282,13 @@ rxjs@^6.4.0, rxjs@^6.6.0, rxjs@^6.6.6, rxjs@^6.6.7: dependencies: tslib "^1.9.0" +rxjs@^7.2.0: + version "7.3.0" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.3.0.tgz#39fe4f3461dc1e50be1475b2b85a0a88c1e938c6" + integrity sha512-p2yuGIg9S1epc3vrjKf6iVb3RCaAYjYskkO+jHIaV0IjOPlJop4UnodOoFb2xeNwlguqLYvGw1b1McillYb5Gw== + dependencies: + tslib "~2.1.0" + safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" From 19a8c7676d3e65bf3a6d08a785f63dc7698bf8fd Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Thu, 26 Aug 2021 17:41:48 +0200 Subject: [PATCH 13/26] massive refactor --- packages/generators/generate/package.json | 1 - packages/generators/generate/plopfile.js | 326 +----------------- packages/generators/generate/plops/api.js | 92 +++++ .../generators/generate/plops/controller.js | 31 ++ packages/generators/generate/plops/model.js | 115 ++++++ packages/generators/generate/plops/plugin.js | 48 +++ packages/generators/generate/plops/policy.js | 37 ++ packages/generators/generate/plops/service.js | 30 ++ .../plops/utils/get-destination-prompts.js | 43 +++ .../generate/plops/utils/get-file-path.js | 13 + .../templates/model.settings.json.hbs | 3 +- yarn.lock | 27 -- 12 files changed, 425 insertions(+), 341 deletions(-) create mode 100644 packages/generators/generate/plops/api.js create mode 100644 packages/generators/generate/plops/controller.js create mode 100644 packages/generators/generate/plops/model.js create mode 100644 packages/generators/generate/plops/plugin.js create mode 100644 packages/generators/generate/plops/policy.js create mode 100644 packages/generators/generate/plops/service.js create mode 100644 packages/generators/generate/plops/utils/get-destination-prompts.js create mode 100644 packages/generators/generate/plops/utils/get-file-path.js diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index 5ffd56e15c..cbbbd3a5ea 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -6,7 +6,6 @@ "license": "MIT", "dependencies": { "fs-extra": "10.0.0", - "inquirer": "8.1.2", "inquirer-recursive": "0.0.7", "node-plop": "0.26.2", "plop": "2.7.4", diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generate/plopfile.js index 66f75a313d..b51906a77b 100644 --- a/packages/generators/generate/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -1,322 +1,26 @@ 'use strict'; -const { join } = require('path'); -const fs = require('fs-extra'); const pluralize = require('pluralize'); -const rootDir = process.cwd(); - -const getFilePath = destination => { - if (destination === 'api') { - return `api/{{api}}`; - } - - if (destination === 'plugin') { - return `plugins/{{plugin}}`; - } - - return `api/{{id}}`; -}; - -const getDestinationPrompts = action => { - return [ - { - type: 'list', - name: 'destination', - message: `Where do you want to add this ${action}?`, - choices: [ - { - name: `Add ${action} to ${action === 'policy' ? 'root of project' : 'new API'}`, - value: 'new', - }, - { name: `Add ${action} to existing API`, value: 'api' }, - { name: `Add ${action} to existing plugin`, value: 'plugin' }, - ], - }, - { - when: answers => answers.destination === 'api', - type: 'input', - message: 'Which API is this for?', - name: 'api', - validate: async input => { - const exists = await fs.pathExists(join(rootDir, `api/${input}`)); - - return exists || 'That api does not exist, please try again'; - }, - }, - { - when: answers => answers.destination === 'plugin', - type: 'input', - message: 'Which plugin is this for?', - name: 'plugin', - validate: async input => { - const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); - - return exists || 'That plugin does not exist, please try again'; - }, - }, - ]; -}; +const api = require('./plops/api'); +const controller = require('./plops/controller'); +const model = require('./plops/model'); +const plugin = require('./plops/plugin'); +const policy = require('./plops/policy'); +const service = require('./plops/service'); module.exports = function(plop) { + const rootDir = process.cwd(); + // Plop config plop.setWelcomeMessage('Strapi Generators'); - plop.addHelper('pluralize', text => pluralize(text)); - - // API generator - plop.setGenerator('api', { - description: 'Generate a basic API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'API name', - }, - { - type: 'list', - name: 'kind', - message: 'Please choose the model type', - choices: [ - { name: 'Collection Type', value: 'collectionType' }, - { name: 'Singe Type', value: 'singleType' }, - ], - }, - { - type: 'confirm', - name: 'isPluginApi', - message: 'Is this API for a plugin?', - }, - { - when: answers => answers.isPluginApi, - type: 'input', - name: 'plugin', - message: 'Plugin name', - validate: async input => { - const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); - - return exists || 'That plugin does not exist, please try again'; - }, - }, - { - type: 'confirm', - name: 'useDraftAndPublish', - message: 'Use draft and publish?', - }, - ], - actions: answers => { - let filePath; - if (answers.isPluginApi && answers.plugin) { - filePath = `plugins/{{plugin}}`; - } else { - filePath = `api/{{id}}`; - } - - const baseActions = [ - { - type: 'add', - path: join(rootDir, `${filePath}/controllers/{{id}}.js`), - templateFile: 'templates/controller.js.hbs', - }, - { - type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.js`), - templateFile: 'templates/model.js.hbs', - }, - { - type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), - templateFile: 'templates/model.settings.json.hbs', - }, - { - type: 'add', - path: join(rootDir, `${filePath}/services/{{id}}.js`), - templateFile: 'templates/service.js.hbs', - }, - ]; - - if (answers.isPluginApi) { - return baseActions; - } else { - return [ - { - type: 'add', - path: join(rootDir, `${filePath}/config/routes.json`), - templateFile: 'templates/api-routes.json.hbs', - }, - ...baseActions, - ]; - } - }, - }); - - // Controller generator - plop.setGenerator('controller', { - description: 'Generate a controller for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Controller name', - }, - ...getDestinationPrompts('controller'), - ], - actions: answers => { - const filePath = getFilePath(answers.destination); - - return [ - { - type: 'add', - path: join(rootDir, `${filePath}/controllers/{{id}}.js`), - templateFile: 'templates/controller.js.hbs', - }, - ]; - }, - }); - plop.setPrompt('recursive', require('inquirer-recursive')); - // Model generator - plop.setGenerator('model', { - description: 'Generate a model for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Model name', - }, - { - type: 'list', - name: 'kind', - message: 'Please choose the model type', - choices: [ - { name: 'Collection Type', value: 'collectionType' }, - { name: 'Singe Type', value: 'singleType' }, - ], - }, - ...getDestinationPrompts('model'), - { - type: 'addAttributes', - name: 'attributes', - }, - { - type: 'confirm', - name: 'useDraftAndPublish', - message: 'Use draft and publish?', - }, - ], - actions: answers => { - const filePath = getFilePath(answers.destination); - return [ - { - type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.js`), - templateFile: 'templates/model.js.hbs', - }, - { - type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), - templateFile: 'templates/model.settings.json.hbs', - }, - ]; - }, - }); - - const { prompts } = plop.inquirer.prompt; - console.log(prompts); - - // Plugin generator - plop.setGenerator('plugin', { - description: 'Generate a basic plugin', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Plugin name', - }, - ], - actions: answers => { - fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', answers.id)); - return [ - { - type: 'add', - path: join(rootDir, 'plugins/{{id}}/services/{{id}}.js'), - templateFile: 'templates/service.js.hbs', - }, - { - type: 'add', - path: join(rootDir, 'plugins/{{id}}/controllers/{{id}}.js'), - templateFile: 'templates/controller.js.hbs', - }, - { - type: 'add', - path: join(rootDir, 'plugins/{{id}}/config/routes.json'), - templateFile: 'templates/plugin-routes.json.hbs', - }, - { - type: 'add', - path: join(rootDir, 'plugins/{{id}}/README.md'), - templateFile: 'templates/README.md.hbs', - }, - { - type: 'add', - path: join(rootDir, 'plugins/{{id}}/package.json'), - templateFile: 'templates/plugin-package.json.hbs', - }, - ]; - }, - }); - - // Policy generator - plop.setGenerator('policy', { - description: 'Generate a policy for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Policy name', - }, - ...getDestinationPrompts('policy'), - ], - actions: answers => { - let filePath; - if (answers.destination === 'api') { - filePath = `api/{{api}}`; - } else if (answers.destination === 'plugin') { - filePath = `plugins/{{plugin}}`; - } else { - filePath = ``; - } - - return [ - { - type: 'add', - path: join(rootDir, `${filePath}/config/policies/{{id}}.js`), - templateFile: 'templates/policy.js.hbs', - }, - ]; - }, - }); - - // Service generator - plop.setGenerator('service', { - description: 'Generate a service for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Service name', - }, - ...getDestinationPrompts('service'), - ], - actions: answers => { - const filePath = getFilePath(answers.destination); - return [ - { - type: 'add', - path: join(rootDir, `${filePath}/services/{{id}}.js`), - templateFile: 'templates/service.js.hbs', - }, - ]; - }, - }); + // Generators + api(plop, rootDir); + controller(plop, rootDir); + model(plop, rootDir); + plugin(plop, rootDir); + policy(plop, rootDir); + service(plop, rootDir); }; diff --git a/packages/generators/generate/plops/api.js b/packages/generators/generate/plops/api.js new file mode 100644 index 0000000000..b0f31ad4bb --- /dev/null +++ b/packages/generators/generate/plops/api.js @@ -0,0 +1,92 @@ +'use strict'; + +const { join } = require('path'); +const fs = require('fs-extra'); + +module.exports = (plop, rootDir) => { + // API generator + plop.setGenerator('api', { + description: 'Generate a basic API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'API name', + }, + { + type: 'list', + name: 'kind', + message: 'Please choose the model type', + choices: [ + { name: 'Collection Type', value: 'collectionType' }, + { name: 'Singe Type', value: 'singleType' }, + ], + }, + { + type: 'confirm', + name: 'isPluginApi', + message: 'Is this API for a plugin?', + }, + { + when: answers => answers.isPluginApi, + type: 'input', + name: 'plugin', + message: 'Plugin name', + validate: async input => { + const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); + + return exists || 'That plugin does not exist, please try again'; + }, + }, + { + type: 'confirm', + name: 'useDraftAndPublish', + message: 'Use draft and publish?', + }, + ], + actions: answers => { + let filePath; + if (answers.isPluginApi && answers.plugin) { + filePath = `plugins/{{plugin}}`; + } else { + filePath = `api/{{id}}`; + } + + const baseActions = [ + { + type: 'add', + path: join(rootDir, `${filePath}/controllers/{{id}}.js`), + templateFile: 'templates/controller.js.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.js`), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + templateFile: 'templates/model.settings.json.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/services/{{id}}.js`), + templateFile: 'templates/service.js.hbs', + }, + ]; + + if (answers.isPluginApi) { + return baseActions; + } else { + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/config/routes.json`), + templateFile: 'templates/api-routes.json.hbs', + }, + ...baseActions, + ]; + } + }, + }); +}; diff --git a/packages/generators/generate/plops/controller.js b/packages/generators/generate/plops/controller.js new file mode 100644 index 0000000000..30ab862d5b --- /dev/null +++ b/packages/generators/generate/plops/controller.js @@ -0,0 +1,31 @@ +'use strict'; + +const { join } = require('path'); +const getDestinationPrompts = require('./utils/get-destination-prompts'); +const getFilePath = require('./utils/get-file-path'); + +module.exports = (plop, rootDir) => { + // Controller generator + plop.setGenerator('controller', { + description: 'Generate a controller for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Controller name', + }, + ...getDestinationPrompts('controller'), + ], + actions: answers => { + const filePath = getFilePath(answers.destination); + + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/controllers/{{id}}.js`), + templateFile: 'templates/controller.js.hbs', + }, + ]; + }, + }); +}; diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js new file mode 100644 index 0000000000..27f4811c04 --- /dev/null +++ b/packages/generators/generate/plops/model.js @@ -0,0 +1,115 @@ +'use strict'; + +const { join } = require('path'); +const getDestinationPrompts = require('./utils/get-destination-prompts'); +const getFilePath = require('./utils/get-file-path'); + +const DEFAULT_TYPES = [ + // advanced types + 'media', + + // scalar types + 'string', + 'text', + 'richtext', + 'json', + 'enumeration', + 'password', + 'email', + 'integer', + 'biginteger', + 'float', + 'decimal', + 'date', + 'time', + 'datetime', + 'timestamp', + 'boolean', + + 'relation', +]; + +module.exports = (plop, rootDir) => { + // Model generator + plop.setGenerator('model', { + description: 'Generate a model for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Model name', + }, + { + type: 'list', + name: 'kind', + message: 'Please choose the model type', + choices: [ + { name: 'Collection Type', value: 'collectionType' }, + { name: 'Singe Type', value: 'singleType' }, + ], + }, + ...getDestinationPrompts('model'), + { + type: 'confirm', + name: 'useDraftAndPublish', + message: 'Use draft and publish?', + }, + { + type: 'recursive', + message: 'Add attribute?', + name: 'attributes', + prompts: [ + { + type: 'input', + name: 'attributeName', + message: 'Name of attribute', + }, + { + type: 'list', + name: 'attributeType', + message: 'What type of attribute', + pageSize: DEFAULT_TYPES.length, + choices: DEFAULT_TYPES.map(type => { + return { name: type, value: type }; + }), + }, + ], + }, + ], + actions: answers => { + const attributes = answers.attributes.reduce((object, answer) => { + // Rest/spread properties are not supported until Node.js 8.3.0. + // The configured version range is '>=8.0.0' + return Object.assign( + object, + { [answer.attributeName]: { type: answer.attributeType } }, + {} + ); + }, {}); + + const filePath = getFilePath(answers.destination); + + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.js`), + templateFile: 'templates/model.js.hbs', + }, + { + type: 'add', + path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + templateFile: 'templates/model.settings.json.hbs', + }, + { + type: 'modify', + path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + transform: template => { + const temp = JSON.parse(template); + temp.attributes = attributes; + return JSON.stringify(temp, null, 2); + }, + }, + ]; + }, + }); +}; diff --git a/packages/generators/generate/plops/plugin.js b/packages/generators/generate/plops/plugin.js new file mode 100644 index 0000000000..4f7c479282 --- /dev/null +++ b/packages/generators/generate/plops/plugin.js @@ -0,0 +1,48 @@ +'use strict'; + +const { join } = require('path'); +const fs = require('fs-extra'); + +module.exports = (plop, rootDir) => { + // Plugin generator + plop.setGenerator('plugin', { + description: 'Generate a basic plugin', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Plugin name', + }, + ], + actions: answers => { + fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', answers.id)); + return [ + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/services/{{id}}.js'), + templateFile: 'templates/service.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/controllers/{{id}}.js'), + templateFile: 'templates/controller.js.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/config/routes.json'), + templateFile: 'templates/plugin-routes.json.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/README.md'), + templateFile: 'templates/README.md.hbs', + }, + { + type: 'add', + path: join(rootDir, 'plugins/{{id}}/package.json'), + templateFile: 'templates/plugin-package.json.hbs', + }, + ]; + }, + }); +}; diff --git a/packages/generators/generate/plops/policy.js b/packages/generators/generate/plops/policy.js new file mode 100644 index 0000000000..5e605860a6 --- /dev/null +++ b/packages/generators/generate/plops/policy.js @@ -0,0 +1,37 @@ +'use strict'; + +const { join } = require('path'); +const getDestinationPrompts = require('./utils/get-destination-prompts'); + +module.exports = (plop, rootDir) => { + // Policy generator + plop.setGenerator('policy', { + description: 'Generate a policy for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Policy name', + }, + ...getDestinationPrompts('policy'), + ], + actions: answers => { + let filePath; + if (answers.destination === 'api') { + filePath = `api/{{api}}`; + } else if (answers.destination === 'plugin') { + filePath = `plugins/{{plugin}}`; + } else { + filePath = ``; + } + + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/config/policies/{{id}}.js`), + templateFile: 'templates/policy.js.hbs', + }, + ]; + }, + }); +}; diff --git a/packages/generators/generate/plops/service.js b/packages/generators/generate/plops/service.js new file mode 100644 index 0000000000..6950075e5f --- /dev/null +++ b/packages/generators/generate/plops/service.js @@ -0,0 +1,30 @@ +'use strict'; + +const { join } = require('path'); +const getDestinationPrompts = require('./utils/get-destination-prompts'); +const getFilePath = require('./utils/get-file-path'); + +module.exports = (plop, rootDir) => { + // Service generator + plop.setGenerator('service', { + description: 'Generate a service for an API', + prompts: [ + { + type: 'input', + name: 'id', + message: 'Service name', + }, + ...getDestinationPrompts('service'), + ], + actions: answers => { + const filePath = getFilePath(answers.destination); + return [ + { + type: 'add', + path: join(rootDir, `${filePath}/services/{{id}}.js`), + templateFile: 'templates/service.js.hbs', + }, + ]; + }, + }); +}; diff --git a/packages/generators/generate/plops/utils/get-destination-prompts.js b/packages/generators/generate/plops/utils/get-destination-prompts.js new file mode 100644 index 0000000000..da700b5c72 --- /dev/null +++ b/packages/generators/generate/plops/utils/get-destination-prompts.js @@ -0,0 +1,43 @@ +'use strict'; +const { join } = require('path'); +const fs = require('fs-extra'); + +module.exports = (action, rootDir) => { + return [ + { + type: 'list', + name: 'destination', + message: `Where do you want to add this ${action}?`, + choices: [ + { + name: `Add ${action} to ${action === 'policy' ? 'root of project' : 'new API'}`, + value: 'new', + }, + { name: `Add ${action} to existing API`, value: 'api' }, + { name: `Add ${action} to existing plugin`, value: 'plugin' }, + ], + }, + { + when: answers => answers.destination === 'api', + type: 'input', + message: 'Which API is this for?', + name: 'api', + validate: async input => { + const exists = await fs.pathExists(join(rootDir, `api/${input}`)); + + return exists || 'That api does not exist, please try again'; + }, + }, + { + when: answers => answers.destination === 'plugin', + type: 'input', + message: 'Which plugin is this for?', + name: 'plugin', + validate: async input => { + const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); + + return exists || 'That plugin does not exist, please try again'; + }, + }, + ]; +}; diff --git a/packages/generators/generate/plops/utils/get-file-path.js b/packages/generators/generate/plops/utils/get-file-path.js new file mode 100644 index 0000000000..9e5775f1c4 --- /dev/null +++ b/packages/generators/generate/plops/utils/get-file-path.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = destination => { + if (destination === 'api') { + return `api/{{api}}`; + } + + if (destination === 'plugin') { + return `plugins/{{plugin}}`; + } + + return `api/{{id}}`; +}; diff --git a/packages/generators/generate/templates/model.settings.json.hbs b/packages/generators/generate/templates/model.settings.json.hbs index c0ddaabb18..c20d27d3b7 100644 --- a/packages/generators/generate/templates/model.settings.json.hbs +++ b/packages/generators/generate/templates/model.settings.json.hbs @@ -8,6 +8,5 @@ "options": { "draftAndPublish": {{useDraftAndPublish}}, "comment": "" - }, - "attributes": {} + } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 8ff04ea032..4823f985f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11187,26 +11187,6 @@ inquirer@8.1.0: strip-ansi "^6.0.0" through "^2.3.6" -inquirer@8.1.2: - version "8.1.2" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.1.2.tgz#65b204d2cd7fb63400edd925dfe428bafd422e3d" - integrity sha512-DHLKJwLPNgkfwNmsuEUKSejJFbkv0FMO9SMiQbjI3n5NQuCrSIBqP66ggqyz2a6t2qEolKrMjhQ3+W/xXgUQ+Q== - dependencies: - ansi-escapes "^4.2.1" - chalk "^4.1.1" - cli-cursor "^3.1.0" - cli-width "^3.0.0" - external-editor "^3.0.3" - figures "^3.0.0" - lodash "^4.17.21" - mute-stream "0.0.8" - ora "^5.3.0" - run-async "^2.4.0" - rxjs "^7.2.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - through "^2.3.6" - inquirer@^6.2.0, inquirer@^6.2.1, inquirer@^6.3.1: version "6.5.2" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.5.2.tgz#ad50942375d036d327ff528c08bd5fab089928ca" @@ -18282,13 +18262,6 @@ rxjs@^6.4.0, rxjs@^6.6.0, rxjs@^6.6.6, rxjs@^6.6.7: dependencies: tslib "^1.9.0" -rxjs@^7.2.0: - version "7.3.0" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.3.0.tgz#39fe4f3461dc1e50be1475b2b85a0a88c1e938c6" - integrity sha512-p2yuGIg9S1epc3vrjKf6iVb3RCaAYjYskkO+jHIaV0IjOPlJop4UnodOoFb2xeNwlguqLYvGw1b1McillYb5Gw== - dependencies: - tslib "~2.1.0" - safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" From a500e88129bcb6ed22b402e54d2a7c2ad8e9dcac Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Thu, 26 Aug 2021 18:02:11 +0200 Subject: [PATCH 14/26] add enums --- packages/generators/generate/plops/api.js | 18 ++++++------- packages/generators/generate/plops/model.js | 28 +++++++++++++++------ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/generators/generate/plops/api.js b/packages/generators/generate/plops/api.js index b0f31ad4bb..2f0cf626d1 100644 --- a/packages/generators/generate/plops/api.js +++ b/packages/generators/generate/plops/api.js @@ -13,15 +13,6 @@ module.exports = (plop, rootDir) => { name: 'id', message: 'API name', }, - { - type: 'list', - name: 'kind', - message: 'Please choose the model type', - choices: [ - { name: 'Collection Type', value: 'collectionType' }, - { name: 'Singe Type', value: 'singleType' }, - ], - }, { type: 'confirm', name: 'isPluginApi', @@ -38,6 +29,15 @@ module.exports = (plop, rootDir) => { return exists || 'That plugin does not exist, please try again'; }, }, + { + type: 'list', + name: 'kind', + message: 'Please choose the model type', + choices: [ + { name: 'Collection Type', value: 'collectionType' }, + { name: 'Singe Type', value: 'singleType' }, + ], + }, { type: 'confirm', name: 'useDraftAndPublish', diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index 27f4811c04..682773c021 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -73,18 +73,30 @@ module.exports = (plop, rootDir) => { return { name: type, value: type }; }), }, + { + when: answers => { + console.log(answers); + return answers.attributeType === 'enumeration'; + }, + type: 'input', + name: 'enum', + message: 'Add values separated by a comma', + }, ], }, ], actions: answers => { + console.log(answers); const attributes = answers.attributes.reduce((object, answer) => { // Rest/spread properties are not supported until Node.js 8.3.0. // The configured version range is '>=8.0.0' - return Object.assign( - object, - { [answer.attributeName]: { type: answer.attributeType } }, - {} - ); + const val = { type: answer.attributeType }; + + if (answer.attributeType === 'enumeration') { + val.enum = answer.enum.split(',').map(item => item.trim()); + } + + return Object.assign(object, { [answer.attributeName]: val }, {}); }, {}); const filePath = getFilePath(answers.destination); @@ -104,9 +116,9 @@ module.exports = (plop, rootDir) => { type: 'modify', path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), transform: template => { - const temp = JSON.parse(template); - temp.attributes = attributes; - return JSON.stringify(temp, null, 2); + const parsedTemplate = JSON.parse(template); + parsedTemplate.attributes = attributes; + return JSON.stringify(parsedTemplate, null, 2); }, }, ]; From d198aa5cba1119fed64c0198ab86089f8df84a50 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 27 Aug 2021 08:48:28 +0200 Subject: [PATCH 15/26] fix missing rootDir argument --- packages/generators/generate/plopfile.js | 24 +++++++++---------- .../generators/generate/plops/controller.js | 3 ++- packages/generators/generate/plops/model.js | 2 +- packages/generators/generate/plops/policy.js | 2 +- packages/generators/generate/plops/service.js | 2 +- .../plops/utils/get-destination-prompts.js | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generate/plopfile.js index b51906a77b..7f216853a4 100644 --- a/packages/generators/generate/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -2,12 +2,12 @@ const pluralize = require('pluralize'); -const api = require('./plops/api'); -const controller = require('./plops/controller'); -const model = require('./plops/model'); -const plugin = require('./plops/plugin'); -const policy = require('./plops/policy'); -const service = require('./plops/service'); +const generateApi = require('./plops/api'); +const generateController = require('./plops/controller'); +const generateModel = require('./plops/model'); +const generatePlugin = require('./plops/plugin'); +const generatePolicy = require('./plops/policy'); +const generateService = require('./plops/service'); module.exports = function(plop) { const rootDir = process.cwd(); @@ -17,10 +17,10 @@ module.exports = function(plop) { plop.setPrompt('recursive', require('inquirer-recursive')); // Generators - api(plop, rootDir); - controller(plop, rootDir); - model(plop, rootDir); - plugin(plop, rootDir); - policy(plop, rootDir); - service(plop, rootDir); + generateApi(plop, rootDir); + generateController(plop, rootDir); + generateModel(plop, rootDir); + generatePlugin(plop, rootDir); + generatePolicy(plop, rootDir); + generateService(plop, rootDir); }; diff --git a/packages/generators/generate/plops/controller.js b/packages/generators/generate/plops/controller.js index 30ab862d5b..e2367683de 100644 --- a/packages/generators/generate/plops/controller.js +++ b/packages/generators/generate/plops/controller.js @@ -14,9 +14,10 @@ module.exports = (plop, rootDir) => { name: 'id', message: 'Controller name', }, - ...getDestinationPrompts('controller'), + ...getDestinationPrompts('controller', rootDir), ], actions: answers => { + console.log('*********', answers); const filePath = getFilePath(answers.destination); return [ diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index 682773c021..7c865cf2f7 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -48,7 +48,7 @@ module.exports = (plop, rootDir) => { { name: 'Singe Type', value: 'singleType' }, ], }, - ...getDestinationPrompts('model'), + ...getDestinationPrompts('model', rootDir), { type: 'confirm', name: 'useDraftAndPublish', diff --git a/packages/generators/generate/plops/policy.js b/packages/generators/generate/plops/policy.js index 5e605860a6..531d4b6b68 100644 --- a/packages/generators/generate/plops/policy.js +++ b/packages/generators/generate/plops/policy.js @@ -13,7 +13,7 @@ module.exports = (plop, rootDir) => { name: 'id', message: 'Policy name', }, - ...getDestinationPrompts('policy'), + ...getDestinationPrompts('policy', rootDir), ], actions: answers => { let filePath; diff --git a/packages/generators/generate/plops/service.js b/packages/generators/generate/plops/service.js index 6950075e5f..d6fdca0105 100644 --- a/packages/generators/generate/plops/service.js +++ b/packages/generators/generate/plops/service.js @@ -14,7 +14,7 @@ module.exports = (plop, rootDir) => { name: 'id', message: 'Service name', }, - ...getDestinationPrompts('service'), + ...getDestinationPrompts('service', rootDir), ], actions: answers => { const filePath = getFilePath(answers.destination); diff --git a/packages/generators/generate/plops/utils/get-destination-prompts.js b/packages/generators/generate/plops/utils/get-destination-prompts.js index da700b5c72..aa6c6773d8 100644 --- a/packages/generators/generate/plops/utils/get-destination-prompts.js +++ b/packages/generators/generate/plops/utils/get-destination-prompts.js @@ -13,8 +13,8 @@ module.exports = (action, rootDir) => { name: `Add ${action} to ${action === 'policy' ? 'root of project' : 'new API'}`, value: 'new', }, - { name: `Add ${action} to existing API`, value: 'api' }, - { name: `Add ${action} to existing plugin`, value: 'plugin' }, + { name: `Add ${action} to an existing API`, value: 'api' }, + { name: `Add ${action} to an existing plugin`, value: 'plugin' }, ], }, { From 3f03d9a8683646ccd7420d283da949d8b011ab49 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 27 Aug 2021 11:03:25 +0200 Subject: [PATCH 16/26] use list for plugins and apis --- packages/generators/generate/plops/api.js | 24 +++++++++-- .../generators/generate/plops/controller.js | 3 +- packages/generators/generate/plops/model.js | 1 - packages/generators/generate/plops/plugin.js | 2 +- .../plops/utils/get-destination-prompts.js | 41 +++++++++++++++---- .../generate/plops/utils/validate-input.js | 11 +++++ 6 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 packages/generators/generate/plops/utils/validate-input.js diff --git a/packages/generators/generate/plops/api.js b/packages/generators/generate/plops/api.js index 2f0cf626d1..0dc0e68b78 100644 --- a/packages/generators/generate/plops/api.js +++ b/packages/generators/generate/plops/api.js @@ -2,6 +2,7 @@ const { join } = require('path'); const fs = require('fs-extra'); +const validateInput = require('./utils/validate-input'); module.exports = (plop, rootDir) => { // API generator @@ -12,6 +13,7 @@ module.exports = (plop, rootDir) => { type: 'input', name: 'id', message: 'API name', + validate: input => validateInput(input), }, { type: 'confirm', @@ -20,13 +22,27 @@ module.exports = (plop, rootDir) => { }, { when: answers => answers.isPluginApi, - type: 'input', + type: 'list', name: 'plugin', message: 'Plugin name', - validate: async input => { - const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); + choices: async () => { + const pluginsPath = join(rootDir, 'plugins'); + const exists = await fs.pathExists(pluginsPath); - return exists || 'That plugin does not exist, please try again'; + if (!exists) { + throw Error('Couldn\'t find a "plugins" directory'); + } + + const pluginsDir = await fs.readdir(pluginsPath); + const pluginsDirContent = pluginsDir.filter(api => + fs.lstatSync(join(pluginsPath, api)).isDirectory() + ); + + if (pluginsDirContent.length === 0) { + throw Error('The "plugins" directory is empty'); + } + + return pluginsDirContent; }, }, { diff --git a/packages/generators/generate/plops/controller.js b/packages/generators/generate/plops/controller.js index e2367683de..30ad38aeb2 100644 --- a/packages/generators/generate/plops/controller.js +++ b/packages/generators/generate/plops/controller.js @@ -3,6 +3,7 @@ const { join } = require('path'); const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); +const validateInput = require('./utils/validate-input'); module.exports = (plop, rootDir) => { // Controller generator @@ -13,11 +14,11 @@ module.exports = (plop, rootDir) => { type: 'input', name: 'id', message: 'Controller name', + validate: input => validateInput(input), }, ...getDestinationPrompts('controller', rootDir), ], actions: answers => { - console.log('*********', answers); const filePath = getFilePath(answers.destination); return [ diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index 7c865cf2f7..61ab803ed2 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -75,7 +75,6 @@ module.exports = (plop, rootDir) => { }, { when: answers => { - console.log(answers); return answers.attributeType === 'enumeration'; }, type: 'input', diff --git a/packages/generators/generate/plops/plugin.js b/packages/generators/generate/plops/plugin.js index 4f7c479282..d260152ce2 100644 --- a/packages/generators/generate/plops/plugin.js +++ b/packages/generators/generate/plops/plugin.js @@ -15,7 +15,7 @@ module.exports = (plop, rootDir) => { }, ], actions: answers => { - fs.copySync(join(__dirname, 'files', 'plugin'), join(rootDir, 'plugins', answers.id)); + fs.copySync(join(__dirname, '..', 'files', 'plugin'), join(rootDir, 'plugins', answers.id)); return [ { type: 'add', diff --git a/packages/generators/generate/plops/utils/get-destination-prompts.js b/packages/generators/generate/plops/utils/get-destination-prompts.js index aa6c6773d8..8eb419808c 100644 --- a/packages/generators/generate/plops/utils/get-destination-prompts.js +++ b/packages/generators/generate/plops/utils/get-destination-prompts.js @@ -19,24 +19,49 @@ module.exports = (action, rootDir) => { }, { when: answers => answers.destination === 'api', - type: 'input', + type: 'list', message: 'Which API is this for?', name: 'api', - validate: async input => { - const exists = await fs.pathExists(join(rootDir, `api/${input}`)); + choices: async () => { + const apiPath = join(rootDir, 'api'); + const exists = await fs.pathExists(apiPath); - return exists || 'That api does not exist, please try again'; + if (!exists) { + throw Error('Couldn\'t find an "api" directory'); + } + + const apiDir = await fs.readdir(apiPath); + const apiDirContent = apiDir.filter(api => fs.lstatSync(join(apiPath, api)).isDirectory()); + if (apiDirContent.length === 0) { + throw Error('The "api" directory is empty'); + } + + return apiDirContent; }, }, { when: answers => answers.destination === 'plugin', - type: 'input', + type: 'list', message: 'Which plugin is this for?', name: 'plugin', - validate: async input => { - const exists = await fs.pathExists(join(rootDir, `plugins/${input}`)); + choices: async () => { + const pluginsPath = join(rootDir, 'plugins'); + const exists = await fs.pathExists(pluginsPath); - return exists || 'That plugin does not exist, please try again'; + if (!exists) { + throw Error('Couldn\'t find a "plugins" directory'); + } + + const pluginsDir = await fs.readdir(pluginsPath); + const pluginsDirContent = pluginsDir.filter(api => + fs.lstatSync(join(pluginsPath, api)).isDirectory() + ); + + if (pluginsDirContent.length === 0) { + throw Error('The "plugins" directory is empty'); + } + + return pluginsDirContent; }, }, ]; diff --git a/packages/generators/generate/plops/utils/validate-input.js b/packages/generators/generate/plops/utils/validate-input.js new file mode 100644 index 0000000000..e7e9076ec3 --- /dev/null +++ b/packages/generators/generate/plops/utils/validate-input.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = input => { + const regex = /^[A-Za-z-]+$/g; + + if (!input) { + return 'You must provide an input'; + } + + return regex.test(input) || 'Please use only letters and no spaces'; +}; From 02058535b98f0ec3e32bd212055d3ccbe03529a2 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 27 Aug 2021 14:00:48 +0200 Subject: [PATCH 17/26] add image attribute --- packages/generators/generate/plops/model.js | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index 61ab803ed2..d768eccd03 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -26,7 +26,8 @@ const DEFAULT_TYPES = [ 'timestamp', 'boolean', - 'relation', + // TODO: Should we include relation in the CLI? + // 'relation' ]; module.exports = (plop, rootDir) => { @@ -74,18 +75,25 @@ module.exports = (plop, rootDir) => { }), }, { - when: answers => { - return answers.attributeType === 'enumeration'; - }, + when: answers => answers.attributeType === 'enumeration', type: 'input', name: 'enum', message: 'Add values separated by a comma', }, + { + when: answers => answers.attributeType === 'media', + type: 'list', + name: 'multiple', + message: 'Choose media type', + choices: [ + { name: 'Multiple', value: true }, + { name: 'Single', value: false }, + ], + }, ], }, ], actions: answers => { - console.log(answers); const attributes = answers.attributes.reduce((object, answer) => { // Rest/spread properties are not supported until Node.js 8.3.0. // The configured version range is '>=8.0.0' @@ -95,6 +103,11 @@ module.exports = (plop, rootDir) => { val.enum = answer.enum.split(',').map(item => item.trim()); } + if (answer.attributeType === 'media') { + val.allowedTypes = ['images', 'files', 'videos']; + val.multiple = answer.multiple; + } + return Object.assign(object, { [answer.attributeName]: val }, {}); }, {}); From 265c7506068f583dd652809a7a5598d1d38193e8 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 27 Aug 2021 16:37:08 +0200 Subject: [PATCH 18/26] remove relation from list --- packages/generators/generate/plops/model.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index d768eccd03..724857dd59 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -25,9 +25,6 @@ const DEFAULT_TYPES = [ 'datetime', 'timestamp', 'boolean', - - // TODO: Should we include relation in the CLI? - // 'relation' ]; module.exports = (plop, rootDir) => { From f71469403147c698ce59999b96e02416666286b7 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Fri, 27 Aug 2021 18:18:41 +0200 Subject: [PATCH 19/26] fix destination path --- .../server/services/content-types.js | 2 +- packages/generators/generate/custom-prompt.js | 27 ------------------- packages/generators/generate/index.js | 8 +++--- packages/generators/generate/package.json | 2 +- packages/generators/generate/plopfile.js | 15 +++++------ packages/generators/generate/plops/api.js | 14 +++++----- .../generators/generate/plops/controller.js | 7 +++-- packages/generators/generate/plops/model.js | 6 ++--- packages/generators/generate/plops/plugin.js | 14 +++++----- packages/generators/generate/plops/policy.js | 7 +++-- packages/generators/generate/plops/service.js | 7 +++-- .../plops/utils/get-destination-prompts.js | 6 ++--- 12 files changed, 42 insertions(+), 73 deletions(-) delete mode 100644 packages/generators/generate/custom-prompt.js diff --git a/packages/core/content-type-builder/server/services/content-types.js b/packages/core/content-type-builder/server/services/content-types.js index dfcd9cb669..09d4a4f07d 100644 --- a/packages/core/content-type-builder/server/services/content-types.js +++ b/packages/core/content-type-builder/server/services/content-types.js @@ -127,7 +127,7 @@ const createContentType = async ({ contentType, components = [] }, options = {}) * @param {string} name */ const generateAPI = ({ name, kind = 'collectionType' }) => { - return generator.generate('api', { id: nameToSlug(name), kind }); + return generator.generate('api', { id: nameToSlug(name), kind }, { dir: strapi.dir }); }; /** diff --git a/packages/generators/generate/custom-prompt.js b/packages/generators/generate/custom-prompt.js deleted file mode 100644 index 3cf0f1225b..0000000000 --- a/packages/generators/generate/custom-prompt.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const inquirer = require('inquirer'); - -const getAttributes = async (attributes = []) => { - const prompts = [ - { - type: 'input', - name: 'inputValue', - message: 'Enter some input: ', - }, - { - type: 'confirm', - name: 'again', - message: 'Enter another input? ', - default: true, - }, - ]; - - // eslint-disable-next-line - const { again, ...answers } = await inquirer.prompt(prompts); - - const newInputs = [...attributes, answers]; - return again ? getAttributes(newInputs) : newInputs; -}; - -module.exports = getAttributes; diff --git a/packages/generators/generate/index.js b/packages/generators/generate/index.js index 4fa4e4a501..04032cbde4 100644 --- a/packages/generators/generate/index.js +++ b/packages/generators/generate/index.js @@ -7,11 +7,13 @@ const { Plop, run } = require('plop'); const nodePlop = require('node-plop'); const execute = () => { - Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, run); + Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, env => + run({ ...env, dest: process.cwd() }, undefined, true) + ); }; -const generate = async (action, options) => { - const plop = nodePlop(join(__dirname, 'plopfile.js')); +const generate = async (action, options, { dir = process.cwd() } = {}) => { + const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: dir }); const generator = plop.getGenerator(action); await generator.runActions(options, { diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index cbbbd3a5ea..9c5ea68439 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -1,6 +1,6 @@ { "name": "@strapi/generate", - "version": "3.6.7", + "version": "3.6.8", "description": "Interactive API generator.", "main": "index.js", "license": "MIT", diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generate/plopfile.js index 7f216853a4..f08db2286e 100644 --- a/packages/generators/generate/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -9,18 +9,17 @@ const generatePlugin = require('./plops/plugin'); const generatePolicy = require('./plops/policy'); const generateService = require('./plops/service'); -module.exports = function(plop) { - const rootDir = process.cwd(); +module.exports = (plop) => { // Plop config plop.setWelcomeMessage('Strapi Generators'); plop.addHelper('pluralize', text => pluralize(text)); plop.setPrompt('recursive', require('inquirer-recursive')); // Generators - generateApi(plop, rootDir); - generateController(plop, rootDir); - generateModel(plop, rootDir); - generatePlugin(plop, rootDir); - generatePolicy(plop, rootDir); - generateService(plop, rootDir); + generateApi(plop); + generateController(plop); + generateModel(plop); + generatePlugin(plop); + generatePolicy(plop); + generateService(plop); }; diff --git a/packages/generators/generate/plops/api.js b/packages/generators/generate/plops/api.js index 0dc0e68b78..52965cd3db 100644 --- a/packages/generators/generate/plops/api.js +++ b/packages/generators/generate/plops/api.js @@ -4,7 +4,7 @@ const { join } = require('path'); const fs = require('fs-extra'); const validateInput = require('./utils/validate-input'); -module.exports = (plop, rootDir) => { +module.exports = (plop) => { // API generator plop.setGenerator('api', { description: 'Generate a basic API', @@ -26,7 +26,7 @@ module.exports = (plop, rootDir) => { name: 'plugin', message: 'Plugin name', choices: async () => { - const pluginsPath = join(rootDir, 'plugins'); + const pluginsPath = join(plop.getDestBasePath(), 'plugins'); const exists = await fs.pathExists(pluginsPath); if (!exists) { @@ -71,22 +71,22 @@ module.exports = (plop, rootDir) => { const baseActions = [ { type: 'add', - path: join(rootDir, `${filePath}/controllers/{{id}}.js`), + path: `${filePath}/controllers/{{id}}.js`, templateFile: 'templates/controller.js.hbs', }, { type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.js`), + path: `${filePath}/models/{{id}}.js`, templateFile: 'templates/model.js.hbs', }, { type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + path: `${filePath}/models/{{id}}.settings.json`, templateFile: 'templates/model.settings.json.hbs', }, { type: 'add', - path: join(rootDir, `${filePath}/services/{{id}}.js`), + path: `${filePath}/services/{{id}}.js`, templateFile: 'templates/service.js.hbs', }, ]; @@ -97,7 +97,7 @@ module.exports = (plop, rootDir) => { return [ { type: 'add', - path: join(rootDir, `${filePath}/config/routes.json`), + path: `${filePath}/config/routes.json`, templateFile: 'templates/api-routes.json.hbs', }, ...baseActions, diff --git a/packages/generators/generate/plops/controller.js b/packages/generators/generate/plops/controller.js index 30ad38aeb2..827318a247 100644 --- a/packages/generators/generate/plops/controller.js +++ b/packages/generators/generate/plops/controller.js @@ -1,11 +1,10 @@ 'use strict'; -const { join } = require('path'); const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); const validateInput = require('./utils/validate-input'); -module.exports = (plop, rootDir) => { +module.exports = (plop) => { // Controller generator plop.setGenerator('controller', { description: 'Generate a controller for an API', @@ -16,7 +15,7 @@ module.exports = (plop, rootDir) => { message: 'Controller name', validate: input => validateInput(input), }, - ...getDestinationPrompts('controller', rootDir), + ...getDestinationPrompts('controller', plop.getDestBasePath()), ], actions: answers => { const filePath = getFilePath(answers.destination); @@ -24,7 +23,7 @@ module.exports = (plop, rootDir) => { return [ { type: 'add', - path: join(rootDir, `${filePath}/controllers/{{id}}.js`), + path: `${filePath}/controllers/{{id}}.js`, templateFile: 'templates/controller.js.hbs', }, ]; diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index 724857dd59..7d98f5995b 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -46,7 +46,7 @@ module.exports = (plop, rootDir) => { { name: 'Singe Type', value: 'singleType' }, ], }, - ...getDestinationPrompts('model', rootDir), + ...getDestinationPrompts('model', plop.getDestBasePath()), { type: 'confirm', name: 'useDraftAndPublish', @@ -92,8 +92,6 @@ module.exports = (plop, rootDir) => { ], actions: answers => { const attributes = answers.attributes.reduce((object, answer) => { - // Rest/spread properties are not supported until Node.js 8.3.0. - // The configured version range is '>=8.0.0' const val = { type: answer.attributeType }; if (answer.attributeType === 'enumeration') { @@ -113,7 +111,7 @@ module.exports = (plop, rootDir) => { return [ { type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.js`), + path: `${filePath}/models/{{id}}.js`, templateFile: 'templates/model.js.hbs', }, { diff --git a/packages/generators/generate/plops/plugin.js b/packages/generators/generate/plops/plugin.js index d260152ce2..f3312ed5f0 100644 --- a/packages/generators/generate/plops/plugin.js +++ b/packages/generators/generate/plops/plugin.js @@ -3,7 +3,7 @@ const { join } = require('path'); const fs = require('fs-extra'); -module.exports = (plop, rootDir) => { +module.exports = (plop) => { // Plugin generator plop.setGenerator('plugin', { description: 'Generate a basic plugin', @@ -15,31 +15,31 @@ module.exports = (plop, rootDir) => { }, ], actions: answers => { - fs.copySync(join(__dirname, '..', 'files', 'plugin'), join(rootDir, 'plugins', answers.id)); + fs.copySync(join(__dirname, '..', 'files', 'plugin'), join('plugins', answers.id)); return [ { type: 'add', - path: join(rootDir, 'plugins/{{id}}/services/{{id}}.js'), + path: 'plugins/{{id}}/services/{{id}}.js', templateFile: 'templates/service.js.hbs', }, { type: 'add', - path: join(rootDir, 'plugins/{{id}}/controllers/{{id}}.js'), + path: 'plugins/{{id}}/controllers/{{id}}.js', templateFile: 'templates/controller.js.hbs', }, { type: 'add', - path: join(rootDir, 'plugins/{{id}}/config/routes.json'), + path: 'plugins/{{id}}/config/routes.json', templateFile: 'templates/plugin-routes.json.hbs', }, { type: 'add', - path: join(rootDir, 'plugins/{{id}}/README.md'), + path: 'plugins/{{id}}/README.md', templateFile: 'templates/README.md.hbs', }, { type: 'add', - path: join(rootDir, 'plugins/{{id}}/package.json'), + path: 'plugins/{{id}}/package.json', templateFile: 'templates/plugin-package.json.hbs', }, ]; diff --git a/packages/generators/generate/plops/policy.js b/packages/generators/generate/plops/policy.js index 531d4b6b68..72f705c9b7 100644 --- a/packages/generators/generate/plops/policy.js +++ b/packages/generators/generate/plops/policy.js @@ -1,9 +1,8 @@ 'use strict'; -const { join } = require('path'); const getDestinationPrompts = require('./utils/get-destination-prompts'); -module.exports = (plop, rootDir) => { +module.exports = (plop) => { // Policy generator plop.setGenerator('policy', { description: 'Generate a policy for an API', @@ -13,7 +12,7 @@ module.exports = (plop, rootDir) => { name: 'id', message: 'Policy name', }, - ...getDestinationPrompts('policy', rootDir), + ...getDestinationPrompts('policy', plop.getDestBasePath()), ], actions: answers => { let filePath; @@ -28,7 +27,7 @@ module.exports = (plop, rootDir) => { return [ { type: 'add', - path: join(rootDir, `${filePath}/config/policies/{{id}}.js`), + path: `${filePath}/config/policies/{{id}}.js`, templateFile: 'templates/policy.js.hbs', }, ]; diff --git a/packages/generators/generate/plops/service.js b/packages/generators/generate/plops/service.js index d6fdca0105..2ded6814c9 100644 --- a/packages/generators/generate/plops/service.js +++ b/packages/generators/generate/plops/service.js @@ -1,10 +1,9 @@ 'use strict'; -const { join } = require('path'); const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); -module.exports = (plop, rootDir) => { +module.exports = (plop) => { // Service generator plop.setGenerator('service', { description: 'Generate a service for an API', @@ -14,14 +13,14 @@ module.exports = (plop, rootDir) => { name: 'id', message: 'Service name', }, - ...getDestinationPrompts('service', rootDir), + ...getDestinationPrompts('service', plop.getDestBasePath()), ], actions: answers => { const filePath = getFilePath(answers.destination); return [ { type: 'add', - path: join(rootDir, `${filePath}/services/{{id}}.js`), + path: `${filePath}/services/{{id}}.js`, templateFile: 'templates/service.js.hbs', }, ]; diff --git a/packages/generators/generate/plops/utils/get-destination-prompts.js b/packages/generators/generate/plops/utils/get-destination-prompts.js index 8eb419808c..a0a8a47559 100644 --- a/packages/generators/generate/plops/utils/get-destination-prompts.js +++ b/packages/generators/generate/plops/utils/get-destination-prompts.js @@ -2,7 +2,7 @@ const { join } = require('path'); const fs = require('fs-extra'); -module.exports = (action, rootDir) => { +module.exports = (action, basePath) => { return [ { type: 'list', @@ -23,7 +23,7 @@ module.exports = (action, rootDir) => { message: 'Which API is this for?', name: 'api', choices: async () => { - const apiPath = join(rootDir, 'api'); + const apiPath = join(basePath, 'api'); const exists = await fs.pathExists(apiPath); if (!exists) { @@ -45,7 +45,7 @@ module.exports = (action, rootDir) => { message: 'Which plugin is this for?', name: 'plugin', choices: async () => { - const pluginsPath = join(rootDir, 'plugins'); + const pluginsPath = join(basePath, 'plugins'); const exists = await fs.pathExists(pluginsPath); if (!exists) { From 4f1d9a5f4cc3219e173b568f69397e2a9727cccc Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 27 Aug 2021 19:25:07 +0200 Subject: [PATCH 20/26] Remove old package.json files --- packages/generators/api/package.json | 48 ------------------ packages/generators/controller/package.json | 48 ------------------ .../templates/plugin-package.json.hbs | 4 +- packages/generators/model/package.json | 49 ------------------- packages/generators/plugin/package.json | 48 ------------------ packages/generators/policy/package.json | 48 ------------------ packages/generators/service/package.json | 48 ------------------ 7 files changed, 2 insertions(+), 291 deletions(-) delete mode 100644 packages/generators/api/package.json delete mode 100644 packages/generators/controller/package.json delete mode 100644 packages/generators/model/package.json delete mode 100644 packages/generators/plugin/package.json delete mode 100644 packages/generators/policy/package.json delete mode 100644 packages/generators/service/package.json diff --git a/packages/generators/api/package.json b/packages/generators/api/package.json deleted file mode 100644 index bb6019b1cc..0000000000 --- a/packages/generators/api/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-api", - "version": "3.6.8", - "description": "Generate an API for a Strapi application.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "pluralize": "^8.0.0", - "@strapi/utils": "3.6.8" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/controller/package.json b/packages/generators/controller/package.json deleted file mode 100644 index ec367993a3..0000000000 --- a/packages/generators/controller/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-controller", - "version": "3.6.8", - "description": "Generate a controller for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "controller", - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "@strapi/utils": "3.6.8" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/generate/templates/plugin-package.json.hbs b/packages/generators/generate/templates/plugin-package.json.hbs index 75bec5a029..13c47fc600 100644 --- a/packages/generators/generate/templates/plugin-package.json.hbs +++ b/packages/generators/generate/templates/plugin-package.json.hbs @@ -21,8 +21,8 @@ } ], "engines": { - "node": ">=12.x. <=14.x.x", + "node": ">=12.x. <=64.x.x", "npm": ">=6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/generators/model/package.json b/packages/generators/model/package.json deleted file mode 100644 index d70f9a526b..0000000000 --- a/packages/generators/model/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "@strapi/generate-model", - "version": "3.6.8", - "description": "Generate a model for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "model", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "pluralize": "^8.0.0", - "@strapi/utils": "3.6.8" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/plugin/package.json b/packages/generators/plugin/package.json deleted file mode 100644 index 9c5f8b5f27..0000000000 --- a/packages/generators/plugin/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-plugin", - "version": "3.6.8", - "description": "Generate an plugin for a Strapi application.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "fs-extra": "^9.1.0", - "lodash": "4.17.21", - "@strapi/utils": "3.6.8" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/policy/package.json b/packages/generators/policy/package.json deleted file mode 100644 index e4cfa63b2c..0000000000 --- a/packages/generators/policy/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-policy", - "version": "3.6.8", - "description": "Generate a policy for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "policy", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "@strapi/utils": "3.6.8" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} diff --git a/packages/generators/service/package.json b/packages/generators/service/package.json deleted file mode 100644 index e31078d4a6..0000000000 --- a/packages/generators/service/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@strapi/generate-service", - "version": "3.6.8", - "description": "Generate a service for a Strapi API.", - "homepage": "https://strapi.io", - "keywords": [ - "generate", - "generator", - "service", - "strapi" - ], - "main": "./lib/index.js", - "directories": { - "lib": "./lib" - }, - "dependencies": { - "lodash": "4.17.21", - "@strapi/utils": "3.6.8" - }, - "scripts": { - "test": "echo \"no tests yet\"" - }, - "author": { - "email": "hi@strapi.io", - "name": "Strapi team", - "url": "https://strapi.io" - }, - "maintainers": [ - { - "name": "Strapi team", - "email": "hi@strapi.io", - "url": "https://strapi.io" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git" - }, - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - }, - "license": "SEE LICENSE IN LICENSE", - "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} From e8fe92b154231655b87f7fb3f4d9cb4ce40c83b8 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 27 Aug 2021 19:30:30 +0200 Subject: [PATCH 21/26] Fix missing engines property in package.json (thanks marion) --- packages/generators/generate/package.json | 4 ++++ .../generators/generate/templates/plugin-package.json.hbs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index 9c5ea68439..e8b41e43c6 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -10,5 +10,9 @@ "node-plop": "0.26.2", "plop": "2.7.4", "pluralize": "8.0.0" + }, + "engines": { + "node": ">=12.x.x <=16.x.x", + "npm": ">=6.0.0" } } diff --git a/packages/generators/generate/templates/plugin-package.json.hbs b/packages/generators/generate/templates/plugin-package.json.hbs index 13c47fc600..82e2b16189 100644 --- a/packages/generators/generate/templates/plugin-package.json.hbs +++ b/packages/generators/generate/templates/plugin-package.json.hbs @@ -21,7 +21,7 @@ } ], "engines": { - "node": ">=12.x. <=64.x.x", + "node": ">=12.x. <=16.x.x", "npm": ">=6.0.0" }, "license": "MIT" From 9886c61e7b4237a5d79af36c6acef22b075d13d0 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 27 Aug 2021 20:44:04 +0200 Subject: [PATCH 22/26] Fix api generator routes to use single & collection types --- packages/generators/generate/plops/api.js | 10 +++++-- ...on.hbs => collection-type-routes.json.hbs} | 0 .../templates/model.settings.json.hbs | 5 ++-- .../generate/templates/service.js.hbs | 6 +--- .../templates/single-type-routes.json.hbs | 28 +++++++++++++++++++ 5 files changed, 40 insertions(+), 9 deletions(-) rename packages/generators/generate/templates/{api-routes.json.hbs => collection-type-routes.json.hbs} (100%) create mode 100644 packages/generators/generate/templates/single-type-routes.json.hbs diff --git a/packages/generators/generate/plops/api.js b/packages/generators/generate/plops/api.js index 52965cd3db..a73b1e2ecc 100644 --- a/packages/generators/generate/plops/api.js +++ b/packages/generators/generate/plops/api.js @@ -4,7 +4,7 @@ const { join } = require('path'); const fs = require('fs-extra'); const validateInput = require('./utils/validate-input'); -module.exports = (plop) => { +module.exports = plop => { // API generator plop.setGenerator('api', { description: 'Generate a basic API', @@ -49,6 +49,7 @@ module.exports = (plop) => { type: 'list', name: 'kind', message: 'Please choose the model type', + default: 'collectionType', choices: [ { name: 'Collection Type', value: 'collectionType' }, { name: 'Singe Type', value: 'singleType' }, @@ -94,11 +95,16 @@ module.exports = (plop) => { if (answers.isPluginApi) { return baseActions; } else { + const routeType = + answers.kind === 'singleType' + ? 'single-type-routes.json.hbs' + : 'collection-type-routes.json.hbs'; + return [ { type: 'add', path: `${filePath}/config/routes.json`, - templateFile: 'templates/api-routes.json.hbs', + templateFile: `templates/${routeType}`, }, ...baseActions, ]; diff --git a/packages/generators/generate/templates/api-routes.json.hbs b/packages/generators/generate/templates/collection-type-routes.json.hbs similarity index 100% rename from packages/generators/generate/templates/api-routes.json.hbs rename to packages/generators/generate/templates/collection-type-routes.json.hbs diff --git a/packages/generators/generate/templates/model.settings.json.hbs b/packages/generators/generate/templates/model.settings.json.hbs index c20d27d3b7..35ed2fad62 100644 --- a/packages/generators/generate/templates/model.settings.json.hbs +++ b/packages/generators/generate/templates/model.settings.json.hbs @@ -8,5 +8,6 @@ "options": { "draftAndPublish": {{useDraftAndPublish}}, "comment": "" - } -} \ No newline at end of file + }, + "attributes": {} +} diff --git a/packages/generators/generate/templates/service.js.hbs b/packages/generators/generate/templates/service.js.hbs index 13861b3c1d..bc8345530c 100644 --- a/packages/generators/generate/templates/service.js.hbs +++ b/packages/generators/generate/templates/service.js.hbs @@ -4,8 +4,4 @@ * {{id}} service. */ -module.exports = { - // exampleService: (arg1, arg2) => { - // return isUserOnline(arg1, arg2); - // } -}; +module.exports = {}; diff --git a/packages/generators/generate/templates/single-type-routes.json.hbs b/packages/generators/generate/templates/single-type-routes.json.hbs new file mode 100644 index 0000000000..76112a3d83 --- /dev/null +++ b/packages/generators/generate/templates/single-type-routes.json.hbs @@ -0,0 +1,28 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/{{pluralize id}}", + "handler": "{{id}}.find", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/{{pluralize id}}", + "handler": "{{id}}.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/{{pluralize id}}/", + "handler": "{{id}}.delete", + "config": { + "policies": [] + } + } + ] +} From a2c795b843f965aa800d371d6bee32c1d850861b Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 27 Aug 2021 21:07:56 +0200 Subject: [PATCH 23/26] Use singular url for single types --- .../generate/templates/single-type-routes.json.hbs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/generators/generate/templates/single-type-routes.json.hbs b/packages/generators/generate/templates/single-type-routes.json.hbs index 76112a3d83..9f1a110ce3 100644 --- a/packages/generators/generate/templates/single-type-routes.json.hbs +++ b/packages/generators/generate/templates/single-type-routes.json.hbs @@ -2,7 +2,7 @@ "routes": [ { "method": "GET", - "path": "/{{pluralize id}}", + "path": "/{{id}}", "handler": "{{id}}.find", "config": { "policies": [] @@ -10,7 +10,7 @@ }, { "method": "PUT", - "path": "/{{pluralize id}}", + "path": "/{{id}}", "handler": "{{id}}.update", "config": { "policies": [] @@ -18,7 +18,7 @@ }, { "method": "DELETE", - "path": "/{{pluralize id}}/", + "path": "/{{id}}/", "handler": "{{id}}.delete", "config": { "policies": [] From 3ab4da68ab29ebbb286e546df5e9e67e7f11892b Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 27 Aug 2021 21:38:49 +0200 Subject: [PATCH 24/26] Update eslintignore --- .eslintignore | 6 +----- .../generators/generate/files/plugin/admin/src/index.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.eslintignore b/.eslintignore index 2633eeedbd..8919593f5d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,15 +5,11 @@ testApp/** examples/** cypress/** -packages/generators/plugin/files/admin/src/** +packages/generators/generate/files/ packages/core/helper-plugin/build/** packages/core/helper-plugin/lib/src/components/** packages/core/helper-plugin/lib/src/testUtils/** packages/core/helper-plugin/lib/src/utils/** -packages/plugins/users-permissions/admin/OLD/** .eslintrc.js .eslintrc.front.js .eslintrc.back.js - -bookshelf.old -database.old diff --git a/packages/generators/generate/files/plugin/admin/src/index.js b/packages/generators/generate/files/plugin/admin/src/index.js index e579910d4b..7f0a2e1df1 100644 --- a/packages/generators/generate/files/plugin/admin/src/index.js +++ b/packages/generators/generate/files/plugin/admin/src/index.js @@ -39,7 +39,7 @@ export default { name, }); }, - // eslint-disable-next-line + bootstrap(app) {}, async registerTrads({ locales }) { const importedTrads = await Promise.all( From 526a2ce6710821241417d57edf5afcfea13d823d Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 27 Aug 2021 22:17:51 +0200 Subject: [PATCH 25/26] Fix model generator --- packages/generators/generate/package.json | 1 - packages/generators/generate/plopfile.js | 3 +- packages/generators/generate/plops/model.js | 165 ++++++++++++-------- yarn.lock | 10 +- 4 files changed, 104 insertions(+), 75 deletions(-) diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json index e8b41e43c6..c9515e05e3 100644 --- a/packages/generators/generate/package.json +++ b/packages/generators/generate/package.json @@ -6,7 +6,6 @@ "license": "MIT", "dependencies": { "fs-extra": "10.0.0", - "inquirer-recursive": "0.0.7", "node-plop": "0.26.2", "plop": "2.7.4", "pluralize": "8.0.0" diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generate/plopfile.js index f08db2286e..1825295d9c 100644 --- a/packages/generators/generate/plopfile.js +++ b/packages/generators/generate/plopfile.js @@ -9,11 +9,10 @@ const generatePlugin = require('./plops/plugin'); const generatePolicy = require('./plops/policy'); const generateService = require('./plops/service'); -module.exports = (plop) => { +module.exports = plop => { // Plop config plop.setWelcomeMessage('Strapi Generators'); plop.addHelper('pluralize', text => pluralize(text)); - plop.setPrompt('recursive', require('inquirer-recursive')); // Generators generateApi(plop); diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generate/plops/model.js index 7d98f5995b..94052e5e9b 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generate/plops/model.js @@ -1,6 +1,5 @@ 'use strict'; -const { join } = require('path'); const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); @@ -27,69 +26,109 @@ const DEFAULT_TYPES = [ 'boolean', ]; -module.exports = (plop, rootDir) => { +const promptConfigQuestions = (plop, inquirer) => { + return inquirer.prompt([ + { + type: 'input', + name: 'id', + message: 'Model name', + }, + { + type: 'list', + name: 'kind', + message: 'Please choose the model type', + choices: [ + { name: 'Collection Type', value: 'collectionType' }, + { name: 'Singe Type', value: 'singleType' }, + ], + }, + ...getDestinationPrompts('model', plop.getDestBasePath()), + { + type: 'confirm', + name: 'useDraftAndPublish', + message: 'Use draft and publish?', + }, + { + type: 'confirm', + name: 'addAttributes', + message: 'Do you want to add attributes?', + }, + ]); +}; + +const promptAttributeQuestions = inquirer => { + return inquirer.prompt([ + { + type: 'input', + name: 'attributeName', + message: 'Name of attribute', + }, + { + type: 'list', + name: 'attributeType', + message: 'What type of attribute', + pageSize: DEFAULT_TYPES.length, + choices: DEFAULT_TYPES.map(type => { + return { name: type, value: type }; + }), + }, + { + when: answers => answers.attributeType === 'enumeration', + type: 'input', + name: 'enum', + message: 'Add values separated by a comma', + }, + { + when: answers => answers.attributeType === 'media', + type: 'list', + name: 'multiple', + message: 'Choose media type', + choices: [ + { name: 'Multiple', value: true }, + { name: 'Single', value: false }, + ], + }, + { + type: 'confirm', + name: 'addAttributes', + message: 'Do you want to add another attribute?', + }, + ]); +}; + +module.exports = plop => { // Model generator plop.setGenerator('model', { description: 'Generate a model for an API', - prompts: [ - { - type: 'input', - name: 'id', - message: 'Model name', - }, - { - type: 'list', - name: 'kind', - message: 'Please choose the model type', - choices: [ - { name: 'Collection Type', value: 'collectionType' }, - { name: 'Singe Type', value: 'singleType' }, - ], - }, - ...getDestinationPrompts('model', plop.getDestBasePath()), - { - type: 'confirm', - name: 'useDraftAndPublish', - message: 'Use draft and publish?', - }, - { - type: 'recursive', - message: 'Add attribute?', - name: 'attributes', - prompts: [ - { - type: 'input', - name: 'attributeName', - message: 'Name of attribute', - }, - { - type: 'list', - name: 'attributeType', - message: 'What type of attribute', - pageSize: DEFAULT_TYPES.length, - choices: DEFAULT_TYPES.map(type => { - return { name: type, value: type }; - }), - }, - { - when: answers => answers.attributeType === 'enumeration', - type: 'input', - name: 'enum', - message: 'Add values separated by a comma', - }, - { - when: answers => answers.attributeType === 'media', - type: 'list', - name: 'multiple', - message: 'Choose media type', - choices: [ - { name: 'Multiple', value: true }, - { name: 'Single', value: false }, - ], - }, - ], - }, - ], + prompts: async inquirer => { + const config = await promptConfigQuestions(plop, inquirer); + + if (!config.addAttributes) { + return { + ...config, + attributes: [], + }; + } + + const attributes = []; + + const genAttribute = async () => { + const answers = await promptAttributeQuestions(inquirer); + + attributes.push(answers); + + if (answers.addAttributes) { + return genAttribute(); + } + }; + + await genAttribute(); + + return { + ...config, + attributes, + }; + }, actions: answers => { const attributes = answers.attributes.reduce((object, answer) => { const val = { type: answer.attributeType }; @@ -116,12 +155,12 @@ module.exports = (plop, rootDir) => { }, { type: 'add', - path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + path: `${filePath}/models/{{id}}.settings.json`, templateFile: 'templates/model.settings.json.hbs', }, { type: 'modify', - path: join(rootDir, `${filePath}/models/{{id}}.settings.json`), + path: `${filePath}/models/{{id}}.settings.json`, transform: template => { const parsedTemplate = JSON.parse(template); parsedTemplate.attributes = attributes; diff --git a/yarn.lock b/yarn.lock index 4823f985f8..4a8b1cc33b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11159,14 +11159,6 @@ init-package-json@^1.10.3: validate-npm-package-license "^3.0.1" validate-npm-package-name "^3.0.0" -inquirer-recursive@0.0.7: - version "0.0.7" - resolved "https://registry.yarnpkg.com/inquirer-recursive/-/inquirer-recursive-0.0.7.tgz#09f65757e3ee10273d8c6b97e36663484741dba5" - integrity sha512-z15FD5N3GrzXM7OwEijm/9FbZzUiQUJQxrtUM0mOy3KeKshp3v/FhjspM8E3a9IgG6sYlN619lHpAdupn90ikQ== - dependencies: - inquirer "^7.3.3" - lodash "^4.17.20" - inquirer@8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.1.0.tgz#68ce5ce5376cf0e89765c993d8b7c1e62e184d69" @@ -11206,7 +11198,7 @@ inquirer@^6.2.0, inquirer@^6.2.1, inquirer@^6.3.1: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^7.1.0, inquirer@^7.3.3: +inquirer@^7.1.0: version "7.3.3" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.3.tgz#04d176b2af04afc157a83fd7c100e98ee0aad003" integrity sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA== From 89b02e871e02220efcfb2b5b19ed01055af1503d Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Sat, 28 Aug 2021 10:50:46 +0200 Subject: [PATCH 26/26] Org package to be consistent, complete package.json and add missing package files --- .eslintignore | 2 +- .../core/content-type-builder/package.json | 2 +- .../server/services/content-types.js | 4 +- packages/core/strapi/bin/strapi.js | 3 +- packages/core/strapi/package.json | 4 +- packages/generators/generate/package.json | 17 --- .../files/plugin => generators}/.editorconfig | 0 .../plugin => generators}/.gitattributes | 0 .../i18n => generators/generators}/.gitignore | 0 packages/generators/generators/.npmignore | 103 ++++++++++++++++++ packages/generators/generators/LICENSE | 22 ++++ packages/generators/generators/README.md | 18 +++ .../lib/files/plugin}/.editorconfig | 0 .../lib/files/plugin}/.gitattributes | 0 .../lib}/files/plugin/.gitignore | 0 .../admin/src/components/Initializer/index.js | 0 .../plugin/admin/src/containers/App/index.js | 0 .../admin/src/containers/HomePage/index.js | 0 .../admin/src/containers/Initializer/index.js | 0 .../lib}/files/plugin/admin/src/index.js | 0 .../files/plugin/admin/src/pages/App/index.js | 0 .../plugin/admin/src/pages/HomePage/index.js | 0 .../lib}/files/plugin/admin/src/pluginId.js | 0 .../plugin/admin/src/translations/en.json | 0 .../plugin/admin/src/translations/fr.json | 0 .../files/plugin/admin/src/utils/getTrad.js | 0 .../{generate => generators/lib}/index.js | 20 +++- .../{generate => generators/lib}/plopfile.js | 0 .../{generate => generators/lib}/plops/api.js | 6 +- .../lib}/plops/controller.js | 2 +- .../lib}/plops/model.js | 4 + .../lib}/plops/plugin.js | 14 ++- .../lib}/plops/policy.js | 4 +- .../lib}/plops/service.js | 2 +- .../plops/utils/get-destination-prompts.js | 7 +- .../lib}/plops/utils/get-file-path.js | 0 .../lib}/plops/utils/validate-input.js | 0 .../lib}/templates/README.md.hbs | 0 .../templates/collection-type-routes.json.hbs | 0 .../lib}/templates/controller.js.hbs | 0 .../lib}/templates/model.js.hbs | 0 .../lib}/templates/model.settings.json.hbs | 0 .../lib}/templates/plugin-package.json.hbs | 0 .../lib}/templates/plugin-routes.json.hbs | 0 .../lib}/templates/policy.js.hbs | 0 .../lib}/templates/service.js.hbs | 0 .../templates/single-type-routes.json.hbs | 0 packages/generators/generators/package.json | 41 +++++++ 48 files changed, 228 insertions(+), 47 deletions(-) delete mode 100644 packages/generators/generate/package.json rename packages/generators/{generate/files/plugin => generators}/.editorconfig (100%) rename packages/generators/{generate/files/plugin => generators}/.gitattributes (100%) rename packages/{plugins/i18n => generators/generators}/.gitignore (100%) create mode 100644 packages/generators/generators/.npmignore create mode 100644 packages/generators/generators/LICENSE create mode 100644 packages/generators/generators/README.md rename packages/{plugins/i18n => generators/generators/lib/files/plugin}/.editorconfig (100%) rename packages/{plugins/i18n => generators/generators/lib/files/plugin}/.gitattributes (100%) rename packages/generators/{generate => generators/lib}/files/plugin/.gitignore (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/components/Initializer/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/containers/App/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/containers/HomePage/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/containers/Initializer/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/pages/App/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/pages/HomePage/index.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/pluginId.js (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/translations/en.json (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/translations/fr.json (100%) rename packages/generators/{generate => generators/lib}/files/plugin/admin/src/utils/getTrad.js (100%) rename packages/generators/{generate => generators/lib}/index.js (50%) rename packages/generators/{generate => generators/lib}/plopfile.js (100%) rename packages/generators/{generate => generators/lib}/plops/api.js (93%) rename packages/generators/{generate => generators/lib}/plops/controller.js (96%) rename packages/generators/{generate => generators/lib}/plops/model.js (95%) rename packages/generators/{generate => generators/lib}/plops/plugin.js (81%) rename packages/generators/{generate => generators/lib}/plops/policy.js (93%) rename packages/generators/{generate => generators/lib}/plops/service.js (96%) rename packages/generators/{generate => generators/lib}/plops/utils/get-destination-prompts.js (89%) rename packages/generators/{generate => generators/lib}/plops/utils/get-file-path.js (100%) rename packages/generators/{generate => generators/lib}/plops/utils/validate-input.js (100%) rename packages/generators/{generate => generators/lib}/templates/README.md.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/collection-type-routes.json.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/controller.js.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/model.js.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/model.settings.json.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/plugin-package.json.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/plugin-routes.json.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/policy.js.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/service.js.hbs (100%) rename packages/generators/{generate => generators/lib}/templates/single-type-routes.json.hbs (100%) create mode 100644 packages/generators/generators/package.json diff --git a/.eslintignore b/.eslintignore index 8919593f5d..26c10e7162 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,7 +5,7 @@ testApp/** examples/** cypress/** -packages/generators/generate/files/ +packages/generators/generators/lib/files/ packages/core/helper-plugin/build/** packages/core/helper-plugin/lib/src/components/** packages/core/helper-plugin/lib/src/testUtils/** diff --git a/packages/core/content-type-builder/package.json b/packages/core/content-type-builder/package.json index 799dea8098..250c00dbde 100644 --- a/packages/core/content-type-builder/package.json +++ b/packages/core/content-type-builder/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@sindresorhus/slugify": "1.1.0", - "@strapi/generate": "3.6.8", + "@strapi/generators": "3.6.8", "@strapi/helper-plugin": "3.6.8", "@strapi/utils": "3.6.8", "fs-extra": "^9.1.0", diff --git a/packages/core/content-type-builder/server/services/content-types.js b/packages/core/content-type-builder/server/services/content-types.js index 09d4a4f07d..0fd1615ce7 100644 --- a/packages/core/content-type-builder/server/services/content-types.js +++ b/packages/core/content-type-builder/server/services/content-types.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const { getOr } = require('lodash/fp'); -const generator = require('@strapi/generate'); +const strapiGenerators = require('@strapi/generators'); const { nameToSlug, contentTypes: contentTypesUtils } = require('@strapi/utils'); const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes'); @@ -127,7 +127,7 @@ const createContentType = async ({ contentType, components = [] }, options = {}) * @param {string} name */ const generateAPI = ({ name, kind = 'collectionType' }) => { - return generator.generate('api', { id: nameToSlug(name), kind }, { dir: strapi.dir }); + return strapiGenerators.generate('api', { id: nameToSlug(name), kind }, { dir: strapi.dir }); }; /** diff --git a/packages/core/strapi/bin/strapi.js b/packages/core/strapi/bin/strapi.js index 2998f282d1..db09a7b8bb 100755 --- a/packages/core/strapi/bin/strapi.js +++ b/packages/core/strapi/bin/strapi.js @@ -124,7 +124,8 @@ program .description('Launch interactive API generator') .action(() => { checkCwdIsStrapiApp('generate'); - require('@strapi/generate').execute(); + process.argv.splice(2, 1); + require('@strapi/generators').runCLI(); }); // `$ strapi generate:template ` diff --git a/packages/core/strapi/package.json b/packages/core/strapi/package.json index 57a80f48e7..035bd65a67 100644 --- a/packages/core/strapi/package.json +++ b/packages/core/strapi/package.json @@ -16,7 +16,7 @@ "@koa/cors": "^3.0.0", "@strapi/admin": "3.6.8", "@strapi/database": "3.6.8", - "@strapi/generate": "3.6.8", + "@strapi/generators": "3.6.8", "@strapi/generate-new": "3.6.8", "@strapi/logger": "3.6.8", "@strapi/utils": "3.6.8", @@ -135,4 +135,4 @@ "reactjs" ], "gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53" -} \ No newline at end of file +} diff --git a/packages/generators/generate/package.json b/packages/generators/generate/package.json deleted file mode 100644 index c9515e05e3..0000000000 --- a/packages/generators/generate/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "@strapi/generate", - "version": "3.6.8", - "description": "Interactive API generator.", - "main": "index.js", - "license": "MIT", - "dependencies": { - "fs-extra": "10.0.0", - "node-plop": "0.26.2", - "plop": "2.7.4", - "pluralize": "8.0.0" - }, - "engines": { - "node": ">=12.x.x <=16.x.x", - "npm": ">=6.0.0" - } -} diff --git a/packages/generators/generate/files/plugin/.editorconfig b/packages/generators/generators/.editorconfig similarity index 100% rename from packages/generators/generate/files/plugin/.editorconfig rename to packages/generators/generators/.editorconfig diff --git a/packages/generators/generate/files/plugin/.gitattributes b/packages/generators/generators/.gitattributes similarity index 100% rename from packages/generators/generate/files/plugin/.gitattributes rename to packages/generators/generators/.gitattributes diff --git a/packages/plugins/i18n/.gitignore b/packages/generators/generators/.gitignore similarity index 100% rename from packages/plugins/i18n/.gitignore rename to packages/generators/generators/.gitignore diff --git a/packages/generators/generators/.npmignore b/packages/generators/generators/.npmignore new file mode 100644 index 0000000000..a788251bc6 --- /dev/null +++ b/packages/generators/generators/.npmignore @@ -0,0 +1,103 @@ +############################ +# OS X +############################ + +.DS_Store +.AppleDouble +.LSOverride +Icon +.Spotlight-V100 +.Trashes +._* + + +############################ +# Linux +############################ + +*~ + + +############################ +# Windows +############################ + +Thumbs.db +ehthumbs.db +Desktop.ini +$RECYCLE.BIN/ +*.cab +*.msi +*.msm +*.msp + + +############################ +# Packages +############################ + +*.7z +*.csv +*.dat +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip +*.com +*.class +*.dll +*.exe +*.o +*.seed +*.so +*.swo +*.swp +*.swn +*.swm +*.out +*.pid + + +############################ +# Logs and databases +############################ + +*.log +*.sql + + +############################ +# Misc. +############################ + +*# +ssl +.editorconfig +.gitattributes +.idea +nbproject + + +############################ +# Node.js +############################ + +lib-cov +lcov.info +pids +logs +results +node_modules +.node_history + + +############################ +# Tests +############################ + +test +testApp +coverage diff --git a/packages/generators/generators/LICENSE b/packages/generators/generators/LICENSE new file mode 100644 index 0000000000..638baf882b --- /dev/null +++ b/packages/generators/generators/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015-present Strapi Solutions SAS + +Portions of the Strapi software are licensed as follows: + +* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE". + +* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below. + +MIT Expat License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packages/generators/generators/README.md b/packages/generators/generators/README.md new file mode 100644 index 0000000000..ee26cbe562 --- /dev/null +++ b/packages/generators/generators/README.md @@ -0,0 +1,18 @@ +# @strapi/generators + +This package contains strapi code generators available through the CLI or programmatically. + +## API Reference + +### `runCLI()` + +Start the generator CLI. + +### `generate(generatorName, options, plopOptions)` + +Execute a generator without interactive mode. + +- `generatorName` - one of `api`, `controller`, `service`, `model`, `plugin`, `policy`. +- `options` - options are specific to each generator +- `plopOtions` + - `dir`: base directory that plop will use as base directory for its actions diff --git a/packages/plugins/i18n/.editorconfig b/packages/generators/generators/lib/files/plugin/.editorconfig similarity index 100% rename from packages/plugins/i18n/.editorconfig rename to packages/generators/generators/lib/files/plugin/.editorconfig diff --git a/packages/plugins/i18n/.gitattributes b/packages/generators/generators/lib/files/plugin/.gitattributes similarity index 100% rename from packages/plugins/i18n/.gitattributes rename to packages/generators/generators/lib/files/plugin/.gitattributes diff --git a/packages/generators/generate/files/plugin/.gitignore b/packages/generators/generators/lib/files/plugin/.gitignore similarity index 100% rename from packages/generators/generate/files/plugin/.gitignore rename to packages/generators/generators/lib/files/plugin/.gitignore diff --git a/packages/generators/generate/files/plugin/admin/src/components/Initializer/index.js b/packages/generators/generators/lib/files/plugin/admin/src/components/Initializer/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/components/Initializer/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/components/Initializer/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/containers/App/index.js b/packages/generators/generators/lib/files/plugin/admin/src/containers/App/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/containers/App/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/containers/App/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/containers/HomePage/index.js b/packages/generators/generators/lib/files/plugin/admin/src/containers/HomePage/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/containers/HomePage/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/containers/HomePage/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/containers/Initializer/index.js b/packages/generators/generators/lib/files/plugin/admin/src/containers/Initializer/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/containers/Initializer/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/containers/Initializer/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/index.js b/packages/generators/generators/lib/files/plugin/admin/src/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/pages/App/index.js b/packages/generators/generators/lib/files/plugin/admin/src/pages/App/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/pages/App/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/pages/App/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/pages/HomePage/index.js b/packages/generators/generators/lib/files/plugin/admin/src/pages/HomePage/index.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/pages/HomePage/index.js rename to packages/generators/generators/lib/files/plugin/admin/src/pages/HomePage/index.js diff --git a/packages/generators/generate/files/plugin/admin/src/pluginId.js b/packages/generators/generators/lib/files/plugin/admin/src/pluginId.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/pluginId.js rename to packages/generators/generators/lib/files/plugin/admin/src/pluginId.js diff --git a/packages/generators/generate/files/plugin/admin/src/translations/en.json b/packages/generators/generators/lib/files/plugin/admin/src/translations/en.json similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/translations/en.json rename to packages/generators/generators/lib/files/plugin/admin/src/translations/en.json diff --git a/packages/generators/generate/files/plugin/admin/src/translations/fr.json b/packages/generators/generators/lib/files/plugin/admin/src/translations/fr.json similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/translations/fr.json rename to packages/generators/generators/lib/files/plugin/admin/src/translations/fr.json diff --git a/packages/generators/generate/files/plugin/admin/src/utils/getTrad.js b/packages/generators/generators/lib/files/plugin/admin/src/utils/getTrad.js similarity index 100% rename from packages/generators/generate/files/plugin/admin/src/utils/getTrad.js rename to packages/generators/generators/lib/files/plugin/admin/src/utils/getTrad.js diff --git a/packages/generators/generate/index.js b/packages/generators/generators/lib/index.js similarity index 50% rename from packages/generators/generate/index.js rename to packages/generators/generators/lib/index.js index 04032cbde4..ce385d8b2e 100644 --- a/packages/generators/generate/index.js +++ b/packages/generators/generators/lib/index.js @@ -1,21 +1,29 @@ 'use strict'; -process.argv.splice(2, 1); - const { join } = require('path'); const { Plop, run } = require('plop'); const nodePlop = require('node-plop'); -const execute = () => { +/** + * Starts the Plop CLI programmatically + */ +const runCLI = () => { Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, env => run({ ...env, dest: process.cwd() }, undefined, true) ); }; -const generate = async (action, options, { dir = process.cwd() } = {}) => { +/** + * Runs a generator programmatically without prompts + * @param {string} generatorName + * @param {Object} options generator options replacing the prompts answers + * @param {Object} plopOptions + * @param {string} plopOptions.dir base path for plop to generate the files from + */ +const generate = async (generatorName, options, { dir = process.cwd() } = {}) => { const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: dir }); - const generator = plop.getGenerator(action); + const generator = plop.getGenerator(generatorName); await generator.runActions(options, { onSuccess: () => {}, onFailure: () => {}, @@ -25,5 +33,5 @@ const generate = async (action, options, { dir = process.cwd() } = {}) => { module.exports = { generate, - execute, + runCLI, }; diff --git a/packages/generators/generate/plopfile.js b/packages/generators/generators/lib/plopfile.js similarity index 100% rename from packages/generators/generate/plopfile.js rename to packages/generators/generators/lib/plopfile.js diff --git a/packages/generators/generate/plops/api.js b/packages/generators/generators/lib/plops/api.js similarity index 93% rename from packages/generators/generate/plops/api.js rename to packages/generators/generators/lib/plops/api.js index a73b1e2ecc..f15a6266a9 100644 --- a/packages/generators/generate/plops/api.js +++ b/packages/generators/generators/lib/plops/api.js @@ -33,10 +33,8 @@ module.exports = plop => { throw Error('Couldn\'t find a "plugins" directory'); } - const pluginsDir = await fs.readdir(pluginsPath); - const pluginsDirContent = pluginsDir.filter(api => - fs.lstatSync(join(pluginsPath, api)).isDirectory() - ); + const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true }); + const pluginsDirContent = pluginsDir.filter(fd => fd.isDirectory()); if (pluginsDirContent.length === 0) { throw Error('The "plugins" directory is empty'); diff --git a/packages/generators/generate/plops/controller.js b/packages/generators/generators/lib/plops/controller.js similarity index 96% rename from packages/generators/generate/plops/controller.js rename to packages/generators/generators/lib/plops/controller.js index 827318a247..f58d484de1 100644 --- a/packages/generators/generate/plops/controller.js +++ b/packages/generators/generators/lib/plops/controller.js @@ -4,7 +4,7 @@ const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); const validateInput = require('./utils/validate-input'); -module.exports = (plop) => { +module.exports = plop => { // Controller generator plop.setGenerator('controller', { description: 'Generate a controller for an API', diff --git a/packages/generators/generate/plops/model.js b/packages/generators/generators/lib/plops/model.js similarity index 95% rename from packages/generators/generate/plops/model.js rename to packages/generators/generators/lib/plops/model.js index 94052e5e9b..9497688fda 100644 --- a/packages/generators/generate/plops/model.js +++ b/packages/generators/generators/lib/plops/model.js @@ -2,6 +2,7 @@ const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); +const validateInput = require('./utils/validate-input'); const DEFAULT_TYPES = [ // advanced types @@ -32,6 +33,7 @@ const promptConfigQuestions = (plop, inquirer) => { type: 'input', name: 'id', message: 'Model name', + validate: input => validateInput(input), }, { type: 'list', @@ -41,6 +43,7 @@ const promptConfigQuestions = (plop, inquirer) => { { name: 'Collection Type', value: 'collectionType' }, { name: 'Singe Type', value: 'singleType' }, ], + validate: input => validateInput(input), }, ...getDestinationPrompts('model', plop.getDestBasePath()), { @@ -62,6 +65,7 @@ const promptAttributeQuestions = inquirer => { type: 'input', name: 'attributeName', message: 'Name of attribute', + validate: input => validateInput(input), }, { type: 'list', diff --git a/packages/generators/generate/plops/plugin.js b/packages/generators/generators/lib/plops/plugin.js similarity index 81% rename from packages/generators/generate/plops/plugin.js rename to packages/generators/generators/lib/plops/plugin.js index f3312ed5f0..e5bdf96206 100644 --- a/packages/generators/generate/plops/plugin.js +++ b/packages/generators/generators/lib/plops/plugin.js @@ -1,9 +1,6 @@ 'use strict'; -const { join } = require('path'); -const fs = require('fs-extra'); - -module.exports = (plop) => { +module.exports = plop => { // Plugin generator plop.setGenerator('plugin', { description: 'Generate a basic plugin', @@ -14,9 +11,14 @@ module.exports = (plop) => { message: 'Plugin name', }, ], - actions: answers => { - fs.copySync(join(__dirname, '..', 'files', 'plugin'), join('plugins', answers.id)); + actions: () => { return [ + { + type: 'addMany', + destination: 'plugins/{{id}}/admin', + base: 'files/plugin/admin', + templateFiles: 'files/plugin/admin/**', + }, { type: 'add', path: 'plugins/{{id}}/services/{{id}}.js', diff --git a/packages/generators/generate/plops/policy.js b/packages/generators/generators/lib/plops/policy.js similarity index 93% rename from packages/generators/generate/plops/policy.js rename to packages/generators/generators/lib/plops/policy.js index 72f705c9b7..6199201fde 100644 --- a/packages/generators/generate/plops/policy.js +++ b/packages/generators/generators/lib/plops/policy.js @@ -2,7 +2,7 @@ const getDestinationPrompts = require('./utils/get-destination-prompts'); -module.exports = (plop) => { +module.exports = plop => { // Policy generator plop.setGenerator('policy', { description: 'Generate a policy for an API', @@ -21,7 +21,7 @@ module.exports = (plop) => { } else if (answers.destination === 'plugin') { filePath = `plugins/{{plugin}}`; } else { - filePath = ``; + filePath = `./`; } return [ diff --git a/packages/generators/generate/plops/service.js b/packages/generators/generators/lib/plops/service.js similarity index 96% rename from packages/generators/generate/plops/service.js rename to packages/generators/generators/lib/plops/service.js index 2ded6814c9..48fcbb7ee7 100644 --- a/packages/generators/generate/plops/service.js +++ b/packages/generators/generators/lib/plops/service.js @@ -3,7 +3,7 @@ const getDestinationPrompts = require('./utils/get-destination-prompts'); const getFilePath = require('./utils/get-file-path'); -module.exports = (plop) => { +module.exports = plop => { // Service generator plop.setGenerator('service', { description: 'Generate a service for an API', diff --git a/packages/generators/generate/plops/utils/get-destination-prompts.js b/packages/generators/generators/lib/plops/utils/get-destination-prompts.js similarity index 89% rename from packages/generators/generate/plops/utils/get-destination-prompts.js rename to packages/generators/generators/lib/plops/utils/get-destination-prompts.js index a0a8a47559..e117f119cf 100644 --- a/packages/generators/generate/plops/utils/get-destination-prompts.js +++ b/packages/generators/generators/lib/plops/utils/get-destination-prompts.js @@ -30,8 +30,9 @@ module.exports = (action, basePath) => { throw Error('Couldn\'t find an "api" directory'); } - const apiDir = await fs.readdir(apiPath); - const apiDirContent = apiDir.filter(api => fs.lstatSync(join(apiPath, api)).isDirectory()); + const apiDir = await fs.readdir(apiPath, { withFileTypes: true }); + const apiDirContent = apiDir.filter(fd => fd.isDirectory()); + if (apiDirContent.length === 0) { throw Error('The "api" directory is empty'); } @@ -45,7 +46,7 @@ module.exports = (action, basePath) => { message: 'Which plugin is this for?', name: 'plugin', choices: async () => { - const pluginsPath = join(basePath, 'plugins'); + const pluginsPath = join(basePath, 'plugins'); const exists = await fs.pathExists(pluginsPath); if (!exists) { diff --git a/packages/generators/generate/plops/utils/get-file-path.js b/packages/generators/generators/lib/plops/utils/get-file-path.js similarity index 100% rename from packages/generators/generate/plops/utils/get-file-path.js rename to packages/generators/generators/lib/plops/utils/get-file-path.js diff --git a/packages/generators/generate/plops/utils/validate-input.js b/packages/generators/generators/lib/plops/utils/validate-input.js similarity index 100% rename from packages/generators/generate/plops/utils/validate-input.js rename to packages/generators/generators/lib/plops/utils/validate-input.js diff --git a/packages/generators/generate/templates/README.md.hbs b/packages/generators/generators/lib/templates/README.md.hbs similarity index 100% rename from packages/generators/generate/templates/README.md.hbs rename to packages/generators/generators/lib/templates/README.md.hbs diff --git a/packages/generators/generate/templates/collection-type-routes.json.hbs b/packages/generators/generators/lib/templates/collection-type-routes.json.hbs similarity index 100% rename from packages/generators/generate/templates/collection-type-routes.json.hbs rename to packages/generators/generators/lib/templates/collection-type-routes.json.hbs diff --git a/packages/generators/generate/templates/controller.js.hbs b/packages/generators/generators/lib/templates/controller.js.hbs similarity index 100% rename from packages/generators/generate/templates/controller.js.hbs rename to packages/generators/generators/lib/templates/controller.js.hbs diff --git a/packages/generators/generate/templates/model.js.hbs b/packages/generators/generators/lib/templates/model.js.hbs similarity index 100% rename from packages/generators/generate/templates/model.js.hbs rename to packages/generators/generators/lib/templates/model.js.hbs diff --git a/packages/generators/generate/templates/model.settings.json.hbs b/packages/generators/generators/lib/templates/model.settings.json.hbs similarity index 100% rename from packages/generators/generate/templates/model.settings.json.hbs rename to packages/generators/generators/lib/templates/model.settings.json.hbs diff --git a/packages/generators/generate/templates/plugin-package.json.hbs b/packages/generators/generators/lib/templates/plugin-package.json.hbs similarity index 100% rename from packages/generators/generate/templates/plugin-package.json.hbs rename to packages/generators/generators/lib/templates/plugin-package.json.hbs diff --git a/packages/generators/generate/templates/plugin-routes.json.hbs b/packages/generators/generators/lib/templates/plugin-routes.json.hbs similarity index 100% rename from packages/generators/generate/templates/plugin-routes.json.hbs rename to packages/generators/generators/lib/templates/plugin-routes.json.hbs diff --git a/packages/generators/generate/templates/policy.js.hbs b/packages/generators/generators/lib/templates/policy.js.hbs similarity index 100% rename from packages/generators/generate/templates/policy.js.hbs rename to packages/generators/generators/lib/templates/policy.js.hbs diff --git a/packages/generators/generate/templates/service.js.hbs b/packages/generators/generators/lib/templates/service.js.hbs similarity index 100% rename from packages/generators/generate/templates/service.js.hbs rename to packages/generators/generators/lib/templates/service.js.hbs diff --git a/packages/generators/generate/templates/single-type-routes.json.hbs b/packages/generators/generators/lib/templates/single-type-routes.json.hbs similarity index 100% rename from packages/generators/generate/templates/single-type-routes.json.hbs rename to packages/generators/generators/lib/templates/single-type-routes.json.hbs diff --git a/packages/generators/generators/package.json b/packages/generators/generators/package.json new file mode 100644 index 0000000000..f4486908c1 --- /dev/null +++ b/packages/generators/generators/package.json @@ -0,0 +1,41 @@ +{ + "name": "@strapi/generators", + "version": "3.6.8", + "description": "Interactive API generator.", + "keywords": [ + "strapi", + "generators" + ], + "homepage": "https://strapi.io", + "bugs": { + "url": "https://github.com/strapi/strapi/issues" + }, + "repository": { + "type": "git", + "url": "git://github.com/strapi/strapi.git" + }, + "license": "SEE LICENSE IN LICENSE", + "author": { + "name": "Strapi team", + "email": "hi@strapi.io", + "url": "https://strapi.io" + }, + "maintainers": [ + { + "name": "Strapi team", + "email": "hi@strapi.io", + "url": "https://strapi.io" + } + ], + "main": "lib/index.js", + "dependencies": { + "fs-extra": "10.0.0", + "node-plop": "0.26.2", + "plop": "2.7.4", + "pluralize": "8.0.0" + }, + "engines": { + "node": ">=12.x.x <=16.x.x", + "npm": ">=6.0.0" + } +}