From 1d2449763f15e4794bf1caeab27d0b587a7c875b Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 15 May 2019 17:22:24 +0200 Subject: [PATCH] Clean strapi-generate-plugin --- .../getstarted/plugins/myplugin/package.json | 11 +++ .../strapi-generate-plugin/files/README.md | 1 - .../json/package.json.js | 72 ++++++------------- packages/strapi-generate-plugin/lib/before.js | 6 -- packages/strapi-generate-plugin/lib/index.js | 18 +++++ .../templates/README.md | 3 + .../.editorconfig => templates/editorconfig} | 0 .../gitattributes} | 0 8 files changed, 55 insertions(+), 56 deletions(-) create mode 100644 examples/getstarted/plugins/myplugin/package.json delete mode 100644 packages/strapi-generate-plugin/files/README.md create mode 100644 packages/strapi-generate-plugin/templates/README.md rename packages/strapi-generate-plugin/{files/.editorconfig => templates/editorconfig} (100%) rename packages/strapi-generate-plugin/{files/.gitattributes => templates/gitattributes} (100%) diff --git a/examples/getstarted/plugins/myplugin/package.json b/examples/getstarted/plugins/myplugin/package.json new file mode 100644 index 0000000000..db1b128183 --- /dev/null +++ b/examples/getstarted/plugins/myplugin/package.json @@ -0,0 +1,11 @@ +{ + "name": "strapi-plugin-my-plugin", + "version": "0.0.0", + "description": "This is the description of my plugin.", + "private": true, + "strapi": { + "name": "my-plugin", + "icon": "plug", + "description": "Description of my plugin." + } +} diff --git a/packages/strapi-generate-plugin/files/README.md b/packages/strapi-generate-plugin/files/README.md deleted file mode 100644 index 6f2fd987e1..0000000000 --- a/packages/strapi-generate-plugin/files/README.md +++ /dev/null @@ -1 +0,0 @@ -# Strapi plugin \ No newline at end of file diff --git a/packages/strapi-generate-plugin/json/package.json.js b/packages/strapi-generate-plugin/json/package.json.js index 1c0c75db6a..82d844f8d2 100644 --- a/packages/strapi-generate-plugin/json/package.json.js +++ b/packages/strapi-generate-plugin/json/package.json.js @@ -13,59 +13,33 @@ const _ = require('lodash'); */ module.exports = scope => { - const cliPkg = scope.strapiPackageJSON || {}; - // 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.` + 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.`, }, - 'scripts': { - 'analyze:clean': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf stats.json', - 'preanalyze': 'npm run analyze:clean', - 'analyze': 'node ./node_modules/strapi-helper-plugin/lib/internals/scripts/analyze.js', - 'prebuild': 'npm run build:clean', - 'build:dev': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development node ./node_modules/strapi-helper-plugin/node_modules/.bin/webpack --config node_modules/strapi-helper-plugin/lib/internals/webpack/webpack.prod.babel.js --color -p --progress', - 'build': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=production node node_modules/strapi-helper-plugin/node_modules/.bin/webpack --config node_modules/strapi-helper-plugin/lib/internals/webpack/webpack.prod.babel.js --color -p --progress', - 'build:clean': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf admin/build', - 'start': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development node ./node_modules/strapi-helper-plugin/lib/server', - 'generate': 'node ./node_modules/strapi-helper-plugin/node_modules/plop --plopfile ./node_modules/strapi-helper-plugin/lib/internals/generators/index.js', - 'lint': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern \'/admin/build/\' --config ./node_modules/strapi-helper-plugin/lib/internals/eslint/.eslintrc.json admin', - 'prettier': 'node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write "{admin,__{tests,mocks}__}/**/*.js"', - 'test': 'npm run lint', - 'prepublishOnly': 'npm run build' + dependencies: {}, + author: { + name: scope.author || 'A Strapi developer', + email: scope.email || '', + url: scope.website || '', }, - 'dependencies': {}, - 'devDependencies': { - 'strapi-helper-plugin': getDependencyVersion(cliPkg, 'strapi') + maintainers: [ + { + name: scope.author || 'A Strapi developer', + email: scope.email || '', + url: scope.website || '', + }, + ], + engines: { + node: '^10.0.0', + npm: '>= 6.0.0', }, - '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": "^10.0.0", - "npm": ">= 6.0.0" - }, - 'license': scope.license || 'MIT' + license: scope.license || 'MIT', }); }; - - /** - * Get dependencies version - */ - -function getDependencyVersion(packageJSON, module) { - return module === packageJSON.name ? packageJSON.version : packageJSON.dependencies && packageJSON.dependencies[module]; -} diff --git a/packages/strapi-generate-plugin/lib/before.js b/packages/strapi-generate-plugin/lib/before.js index 84a7b3af9c..1e72f32367 100644 --- a/packages/strapi-generate-plugin/lib/before.js +++ b/packages/strapi-generate-plugin/lib/before.js @@ -56,12 +56,6 @@ module.exports = (scope, cb) => { const pluginDir = path.resolve(scope.rootPath, 'plugins'); fs.ensureDirSync(pluginDir); - // Copy the admin files. - fs.copySync( - path.resolve(__dirname, '..', 'files'), - path.resolve(scope.rootPath, 'plugins', scope.humanizeId) - ); - // Trigger callback with no error to proceed. return cb.success(); }; diff --git a/packages/strapi-generate-plugin/lib/index.js b/packages/strapi-generate-plugin/lib/index.js index c2adb9e7fb..67d137d55f 100644 --- a/packages/strapi-generate-plugin/lib/index.js +++ b/packages/strapi-generate-plugin/lib/index.js @@ -43,5 +43,23 @@ module.exports = { 'plugins/:humanizeId/package.json': { jsonfile: packageJSON }, + + // Copy dot files. + 'plugins/:humanizeId/.editorconfig': { + copy: 'editorconfig' + }, + + 'plugins/:humanizeId/.gitignore': { + copy: 'gitignore' + }, + + 'plugins/:humanizeId/.gitattributes': { + copy: 'gitattributes' + }, + + // Copy Markdown files with some information. + 'plugins/:humanizeId/README.md': { + template: 'README.md' + }, } }; diff --git a/packages/strapi-generate-plugin/templates/README.md b/packages/strapi-generate-plugin/templates/README.md new file mode 100644 index 0000000000..324fe31e64 --- /dev/null +++ b/packages/strapi-generate-plugin/templates/README.md @@ -0,0 +1,3 @@ +# Strapi plugin <%= id %> + +A quick description of <%= id %>. diff --git a/packages/strapi-generate-plugin/files/.editorconfig b/packages/strapi-generate-plugin/templates/editorconfig similarity index 100% rename from packages/strapi-generate-plugin/files/.editorconfig rename to packages/strapi-generate-plugin/templates/editorconfig diff --git a/packages/strapi-generate-plugin/files/.gitattributes b/packages/strapi-generate-plugin/templates/gitattributes similarity index 100% rename from packages/strapi-generate-plugin/files/.gitattributes rename to packages/strapi-generate-plugin/templates/gitattributes