From 039a0f17fecdeb90be5f633db14b7072f3080dd6 Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 17 Feb 2018 00:03:50 -0600 Subject: [PATCH 01/14] initial asking --- src/commands/create.ts | 55 ++++++++++++++++++++++++++++++++++ src/templates/.gitignore.ejs | 1 + src/templates/README.md.ejs | 1 + src/templates/package.json.ejs | 1 + 4 files changed, 58 insertions(+) create mode 100644 src/commands/create.ts create mode 100644 src/templates/.gitignore.ejs create mode 100644 src/templates/README.md.ejs create mode 100644 src/templates/package.json.ejs diff --git a/src/commands/create.ts b/src/commands/create.ts new file mode 100644 index 0000000..24a2ae4 --- /dev/null +++ b/src/commands/create.ts @@ -0,0 +1,55 @@ +import { GluegunCommand } from 'gluegun' + +const createables = ['plugin'] + +module.exports = { + alias: 'c', + description: 'Displays this help', + run: async context => { + const { print, parameters, template, prompt } = context + const { colors } = print + + const answerPluginName = await prompt.ask({ + type: 'input', + name: 'plugin', + message: 'What would you like to name your plugin?' + }) + const pluginName = `solidarity-${answerPluginName.plugin.replace('solidarity-', '')}` + + const ruleChoices = [ + 'I do not want a generated rule file', + 'Just a simple rule template', + 'Some optional rules' + ] + const answer = await prompt.ask({ + type: 'list', + name: 'ruleChoice', + message: 'What kind of rule file will you generate from your plugin?', + choices: ruleChoices + }) + + const customRules = await prompt.confirm('Will you need custom rules? (e.g. Rules other than provided types)') + + switch (parameters.first && parameters.first.toLowerCase()) { + case 'plugin': + print.info(`Creating a plugin ${pluginName}`) + const files = [ + '.gitignore', + 'README.md', + 'package.json' + ] + files.map((file) => { + template.generate({ + template: `${file}.ejs`, + target: `${pluginName}/${file}`, + props: {}, + }) + }) + break + default: + print.error('Missing what to create') + print.error('solidarity create ') + print.info(`Things you can create: ${createables}`) + } + }, +} as GluegunCommand diff --git a/src/templates/.gitignore.ejs b/src/templates/.gitignore.ejs new file mode 100644 index 0000000..53ff743 --- /dev/null +++ b/src/templates/.gitignore.ejs @@ -0,0 +1 @@ +testing gitignore file diff --git a/src/templates/README.md.ejs b/src/templates/README.md.ejs new file mode 100644 index 0000000..12a3b71 --- /dev/null +++ b/src/templates/README.md.ejs @@ -0,0 +1 @@ +testin readme diff --git a/src/templates/package.json.ejs b/src/templates/package.json.ejs new file mode 100644 index 0000000..bd6efac --- /dev/null +++ b/src/templates/package.json.ejs @@ -0,0 +1 @@ +wuuuuut From cfd4269229a84f886c1808fb407d9a8acbbece78 Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 17 Feb 2018 10:22:38 -0600 Subject: [PATCH 02/14] :building_construction: cleanup --- .../__snapshots__/extensionCheck.ts.snap | 1 + src/commands/create.ts | 41 ++----------------- src/extensions/functions/createPlugin.ts | 38 +++++++++++++++++ src/types.ts | 1 + 4 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 src/extensions/functions/createPlugin.ts diff --git a/__tests__/extensions/__snapshots__/extensionCheck.ts.snap b/__tests__/extensions/__snapshots__/extensionCheck.ts.snap index f2c3df4..d33967f 100644 --- a/__tests__/extensions/__snapshots__/extensionCheck.ts.snap +++ b/__tests__/extensions/__snapshots__/extensionCheck.ts.snap @@ -10,6 +10,7 @@ Object { "checkENV": [Function], "checkFile": [Function], "checkRequirement": [Function], + "createPlugin": [Function], "getLineWithVersion": [Function], "getSolidaritySettings": [Function], "getVersion": [Function], diff --git a/src/commands/create.ts b/src/commands/create.ts index 24a2ae4..97ac41e 100644 --- a/src/commands/create.ts +++ b/src/commands/create.ts @@ -5,46 +5,11 @@ const createables = ['plugin'] module.exports = { alias: 'c', description: 'Displays this help', - run: async context => { - const { print, parameters, template, prompt } = context - const { colors } = print - - const answerPluginName = await prompt.ask({ - type: 'input', - name: 'plugin', - message: 'What would you like to name your plugin?' - }) - const pluginName = `solidarity-${answerPluginName.plugin.replace('solidarity-', '')}` - - const ruleChoices = [ - 'I do not want a generated rule file', - 'Just a simple rule template', - 'Some optional rules' - ] - const answer = await prompt.ask({ - type: 'list', - name: 'ruleChoice', - message: 'What kind of rule file will you generate from your plugin?', - choices: ruleChoices - }) - - const customRules = await prompt.confirm('Will you need custom rules? (e.g. Rules other than provided types)') - + run: context => { + const { print, solidarity, parameters } = context switch (parameters.first && parameters.first.toLowerCase()) { case 'plugin': - print.info(`Creating a plugin ${pluginName}`) - const files = [ - '.gitignore', - 'README.md', - 'package.json' - ] - files.map((file) => { - template.generate({ - template: `${file}.ejs`, - target: `${pluginName}/${file}`, - props: {}, - }) - }) + solidarity.createPlugin(context) break default: print.error('Missing what to create') diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts new file mode 100644 index 0000000..620f100 --- /dev/null +++ b/src/extensions/functions/createPlugin.ts @@ -0,0 +1,38 @@ +module.exports = async (context) => { + const { print, parameters, template, prompt } = context + + const answerPluginName = await prompt.ask({ + type: 'input', + name: 'plugin', + message: 'Plugin name? (we will add the namespacing for you)' + }) + const pluginName = `solidarity-${answerPluginName.plugin.replace('solidarity-', '')}` + + const ruleChoices = [ + 'I do not want a generated rule file', + 'Just a simple rule template', + 'Template + optional rules' + ] + const answer = await prompt.ask({ + type: 'list', + name: 'ruleChoice', + message: 'Your initial rule file template?', + choices: ruleChoices + }) + + const customRules = await prompt.confirm('Custom rules? (e.g. Rules other than basic types)') + + print.info(`Creating a plugin ${pluginName}`) + const files = [ + '.gitignore', + 'README.md', + 'package.json' + ] + files.map((file) => { + template.generate({ + template: `${file}.ejs`, + target: `${pluginName}/${file}`, + props: {}, + }) + }) +} diff --git a/src/types.ts b/src/types.ts index 24c4a75..6feb52a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,6 +19,7 @@ export const solidarity = { buildSpecificRequirement: require('./extensions/functions/buildSpecificRequirement'), appendSolidaritySettings: require('./extensions/functions/appendSolidaritySettings'), ruleHandlers: require('./extensions/functions/ruleHandlers'), + createPlugin: require('./extensions/functions/createPlugin'), } export interface SolidarityPlugin { From e5602e0fbe0177cf4640fdfb260f239ce3a857dd Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 17 Feb 2018 22:58:57 -0600 Subject: [PATCH 03/14] plugin generator functioning --- src/extensions/functions/createPlugin.ts | 43 ++++++++++++++++++------ src/templates/.gitignore.ejs | 10 +++++- src/templates/README.md.ejs | 11 +++++- src/templates/addOptionalRules.js.ejs | 12 +++++++ src/templates/helpful-plugin.js.ejs | 19 +++++++++++ src/templates/package.json.ejs | 13 ++++++- src/templates/rules-template.json.ejs | 6 ++++ src/templates/simple-plugin.js.ejs | 8 +++++ 8 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 src/templates/addOptionalRules.js.ejs create mode 100644 src/templates/helpful-plugin.js.ejs create mode 100644 src/templates/rules-template.json.ejs create mode 100644 src/templates/simple-plugin.js.ejs diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index 620f100..bfd5a4e 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -1,4 +1,9 @@ module.exports = async (context) => { + let files = [ + ['.gitignore.ejs', '.gitignore'], + ['README.md.ejs', 'README.md'], + ['package.json.ejs', 'package.json'], + ] const { print, parameters, template, prompt } = context const answerPluginName = await prompt.ask({ @@ -19,20 +24,38 @@ module.exports = async (context) => { message: 'Your initial rule file template?', choices: ruleChoices }) + // if they want a template, copy it over + if (answer.ruleChoice !== ruleChoices[0]) { + files.push([ + 'rules-template.json.ejs', + `templates/${pluginName}-template.json` + ]) + } const customRules = await prompt.confirm('Custom rules? (e.g. Rules other than basic types)') + if (customRules) { + files.push([ + 'helpful-plugin.js.ejs', + `extensions/${pluginName}.js` + ]) + files.push([ + 'addOptionalRules.js.ejs', + `extensions/helpers/addOptionalRules.js` + ]) + } else { + files.push([ + 'simple-plugin.js.ejs', + `extensions/${pluginName}.js` + ]) + } - print.info(`Creating a plugin ${pluginName}`) - const files = [ - '.gitignore', - 'README.md', - 'package.json' - ] - files.map((file) => { + print.info(`Creating plugin ${pluginName}`) + // copy files over + files.map((fileSet) => { template.generate({ - template: `${file}.ejs`, - target: `${pluginName}/${file}`, - props: {}, + template: fileSet[0], + target: `${pluginName}/${fileSet[1]}`, + props: { pluginName }, }) }) } diff --git a/src/templates/.gitignore.ejs b/src/templates/.gitignore.ejs index 53ff743..7ccd6bd 100644 --- a/src/templates/.gitignore.ejs +++ b/src/templates/.gitignore.ejs @@ -1 +1,9 @@ -testing gitignore file +node_modules/ +yarn-error.log +.node-version +coverage +.nyc_output +.idea +dist/ +.vscode/* +!.vscode/cSpell.json diff --git a/src/templates/README.md.ejs b/src/templates/README.md.ejs index 12a3b71..1db62a3 100644 --- a/src/templates/README.md.ejs +++ b/src/templates/README.md.ejs @@ -1 +1,10 @@ -testin readme + + +# <%= props.pluginName %> +### Short Description +Much longer description + + + +# What is Solidarity? +#### [:newspaper: Read More About Solidarity Here](https://github.com/infinitered/solidarity) diff --git a/src/templates/addOptionalRules.js.ejs b/src/templates/addOptionalRules.js.ejs new file mode 100644 index 0000000..5d2fbdd --- /dev/null +++ b/src/templates/addOptionalRules.js.ejs @@ -0,0 +1,12 @@ +module.exports = (context, requirements) => { + const { solidarity, filesystem } = context + const { binaryExists } = solidarity + + // Conditionally add requirements and rules + + // Example: + // if (binaryExists('yarn', context) && filesystem.exists('./yarn.lock') === 'file') { + // requirements['Yarn'] = [{rule: 'cli', binary: 'yarn', version: '--version', semver: '0.0.0'}] + // } + +} diff --git a/src/templates/helpful-plugin.js.ejs b/src/templates/helpful-plugin.js.ejs new file mode 100644 index 0000000..c8cebe8 --- /dev/null +++ b/src/templates/helpful-plugin.js.ejs @@ -0,0 +1,19 @@ +const addOptionalRules = require('./helpers/addOptionalRules') + +module.exports = (context) => { + // Register this plugin + context.addPlugin({ + name: '<%= props.pluginName %>', + description: 'My custom plugin', + snapshot: async (context) => { + // start with template + let solidarity = require('../templates/<%= props.pluginName %>-template.json') + // add optional rules + addOptionalRules(context, solidarity.requirements) + // write out .solidarity file + context.solidarity.setSolidaritySettings(solidarity, context) + // update file with local versions + await context.system.run('solidarity snapshot') + } + }) +} diff --git a/src/templates/package.json.ejs b/src/templates/package.json.ejs index bd6efac..2114294 100644 --- a/src/templates/package.json.ejs +++ b/src/templates/package.json.ejs @@ -1 +1,12 @@ -wuuuuut +{ + "name": "<%= props.pluginName %>", + "version": "1.0.0", + "repository": "https://github.com//<%= props.pluginName %>", + "description": "Description here", + "author": "Super Awesome Coder", + "license": "MIT", + "private": false, + "scripts": { + "test": "echo not yet", + } +} diff --git a/src/templates/rules-template.json.ejs b/src/templates/rules-template.json.ejs new file mode 100644 index 0000000..f51731f --- /dev/null +++ b/src/templates/rules-template.json.ejs @@ -0,0 +1,6 @@ +{ + "$schema": "http://json.schemastore.org/solidaritySchema", + "requirements": { + "Node Example": [{ "rule": "cli", "binary": "node", "semver": "0.0.0"}] + } +} diff --git a/src/templates/simple-plugin.js.ejs b/src/templates/simple-plugin.js.ejs new file mode 100644 index 0000000..9948c39 --- /dev/null +++ b/src/templates/simple-plugin.js.ejs @@ -0,0 +1,8 @@ +module.exports = (context) => { + // Register this plugin + context.addPlugin({ + name: '<%= props.pluginName %>', + description: 'My custom plugin', + snapshot: '<%= props.pluginName %>-template.json' + }) +} From 133958fa100bf372e1a39333d0ac8c6c5b5e75c4 Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 17 Feb 2018 23:03:36 -0600 Subject: [PATCH 04/14] lint fix --- src/extensions/functions/createPlugin.ts | 38 +++++++----------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index bfd5a4e..570ee82 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -1,57 +1,41 @@ -module.exports = async (context) => { - let files = [ - ['.gitignore.ejs', '.gitignore'], - ['README.md.ejs', 'README.md'], - ['package.json.ejs', 'package.json'], - ] - const { print, parameters, template, prompt } = context +module.exports = async context => { + let files = [['.gitignore.ejs', '.gitignore'], ['README.md.ejs', 'README.md'], ['package.json.ejs', 'package.json']] + const { print, template, prompt } = context const answerPluginName = await prompt.ask({ type: 'input', name: 'plugin', - message: 'Plugin name? (we will add the namespacing for you)' + message: 'Plugin name? (we will add the namespacing for you)', }) const pluginName = `solidarity-${answerPluginName.plugin.replace('solidarity-', '')}` const ruleChoices = [ 'I do not want a generated rule file', 'Just a simple rule template', - 'Template + optional rules' + 'Template + optional rules', ] const answer = await prompt.ask({ type: 'list', name: 'ruleChoice', message: 'Your initial rule file template?', - choices: ruleChoices + choices: ruleChoices, }) // if they want a template, copy it over if (answer.ruleChoice !== ruleChoices[0]) { - files.push([ - 'rules-template.json.ejs', - `templates/${pluginName}-template.json` - ]) + files.push(['rules-template.json.ejs', `templates/${pluginName}-template.json`]) } const customRules = await prompt.confirm('Custom rules? (e.g. Rules other than basic types)') if (customRules) { - files.push([ - 'helpful-plugin.js.ejs', - `extensions/${pluginName}.js` - ]) - files.push([ - 'addOptionalRules.js.ejs', - `extensions/helpers/addOptionalRules.js` - ]) + files.push(['helpful-plugin.js.ejs', `extensions/${pluginName}.js`]) + files.push(['addOptionalRules.js.ejs', `extensions/helpers/addOptionalRules.js`]) } else { - files.push([ - 'simple-plugin.js.ejs', - `extensions/${pluginName}.js` - ]) + files.push(['simple-plugin.js.ejs', `extensions/${pluginName}.js`]) } print.info(`Creating plugin ${pluginName}`) // copy files over - files.map((fileSet) => { + files.map(fileSet => { template.generate({ template: fileSet[0], target: `${pluginName}/${fileSet[1]}`, From 8d91d9e8c537da36edd06a506849cc81af58598c Mon Sep 17 00:00:00 2001 From: Gant Date: Sun, 18 Feb 2018 17:38:06 -0600 Subject: [PATCH 05/14] conditional advanced features --- src/extensions/functions/createPlugin.ts | 17 ++++++++-------- src/templates/helpful-plugin.js.ejs | 25 +++++++++++++++++++++++- src/templates/simple-plugin.js.ejs | 25 +++++++++++++++++++++++- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index 570ee82..6d3f228 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -20,26 +20,25 @@ module.exports = async context => { message: 'Your initial rule file template?', choices: ruleChoices, }) - // if they want a template, copy it over - if (answer.ruleChoice !== ruleChoices[0]) { - files.push(['rules-template.json.ejs', `templates/${pluginName}-template.json`]) - } - const customRules = await prompt.confirm('Custom rules? (e.g. Rules other than basic types)') - if (customRules) { + if (answer.ruleChoice === ruleChoices[1]) { + files.push(['rules-template.json.ejs', `templates/${pluginName}-template.json`]) + files.push(['simple-plugin.js.ejs', `extensions/${pluginName}.js`]) + } else if (answer.ruleChoice === ruleChoices[2]) { + files.push(['rules-template.json.ejs', `templates/${pluginName}-template.json`]) files.push(['helpful-plugin.js.ejs', `extensions/${pluginName}.js`]) files.push(['addOptionalRules.js.ejs', `extensions/helpers/addOptionalRules.js`]) - } else { - files.push(['simple-plugin.js.ejs', `extensions/${pluginName}.js`]) } + const customRules = await prompt.confirm('Custom rules? (e.g. Rules other than basic types)') + print.info(`Creating plugin ${pluginName}`) // copy files over files.map(fileSet => { template.generate({ template: fileSet[0], target: `${pluginName}/${fileSet[1]}`, - props: { pluginName }, + props: { pluginName, customRules }, }) }) } diff --git a/src/templates/helpful-plugin.js.ejs b/src/templates/helpful-plugin.js.ejs index c8cebe8..bd6df9d 100644 --- a/src/templates/helpful-plugin.js.ejs +++ b/src/templates/helpful-plugin.js.ejs @@ -14,6 +14,29 @@ module.exports = (context) => { context.solidarity.setSolidaritySettings(solidarity, context) // update file with local versions await context.system.run('solidarity snapshot') - } + }<% if(props.customRules){ %>, + rules: { + ruleName: { + check: async (rule, context) => { + return { + pass: true, + message: 'Check always passes' + } + }, + snapshot: async (rule, context) => [ + { + prop: 'addedProp', + value: '12.0.0' + }, + ], + report: async (rule, context, report) => { + report.addCLI({ + binary: 'imaginaryCLI', + version: '10', + desired: '12' + }) + } + } + }<% } %> }) } diff --git a/src/templates/simple-plugin.js.ejs b/src/templates/simple-plugin.js.ejs index 9948c39..9f7ec92 100644 --- a/src/templates/simple-plugin.js.ejs +++ b/src/templates/simple-plugin.js.ejs @@ -3,6 +3,29 @@ module.exports = (context) => { context.addPlugin({ name: '<%= props.pluginName %>', description: 'My custom plugin', - snapshot: '<%= props.pluginName %>-template.json' + snapshot: '<%= props.pluginName %>-template.json'<% if(props.customRules){ %>, + rules: { + ruleName: { + check: async (rule, context) => { + return { + pass: true, + message: 'Check always passes' + } + }, + snapshot: async (rule, context) => [ + { + prop: 'addedProp', + value: '12.0.0' + }, + ], + report: async (rule, context, report) => { + report.addCLI({ + binary: 'imaginaryCLI', + version: '10', + desired: '12' + }) + } + } + }<% } %> }) } From 032a293b4861d69ad22b2af468dc9420c6b7d67b Mon Sep 17 00:00:00 2001 From: Gant Date: Sun, 18 Feb 2018 17:45:10 -0600 Subject: [PATCH 06/14] small json error --- src/templates/package.json.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/package.json.ejs b/src/templates/package.json.ejs index 2114294..45b405c 100644 --- a/src/templates/package.json.ejs +++ b/src/templates/package.json.ejs @@ -7,6 +7,6 @@ "license": "MIT", "private": false, "scripts": { - "test": "echo not yet", + "test": "echo not yet" } } From e235b0b9efbb5665474e59f0593347c205bd2a10 Mon Sep 17 00:00:00 2001 From: Gant Laborde Date: Mon, 19 Feb 2018 21:27:10 -0600 Subject: [PATCH 07/14] start asking description --- .vscode/cSpell.json | 1 + src/commands/create.ts | 9 +++++++-- src/extensions/functions/createPlugin.ts | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index eafdd51..088412a 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -31,6 +31,7 @@ "infinite.red", "info", "macos", + "namespacing", "newclear", "npmignore", "Plugin", diff --git a/src/commands/create.ts b/src/commands/create.ts index 97ac41e..0a540fe 100644 --- a/src/commands/create.ts +++ b/src/commands/create.ts @@ -5,11 +5,16 @@ const createables = ['plugin'] module.exports = { alias: 'c', description: 'Displays this help', - run: context => { + run: async context => { const { print, solidarity, parameters } = context switch (parameters.first && parameters.first.toLowerCase()) { case 'plugin': - solidarity.createPlugin(context) + // Handle errors like grown-ups + try { + await solidarity.createPlugin(context) + } catch (e) { + print.error(e) + } break default: print.error('Missing what to create') diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index 6d3f228..957de1c 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -7,8 +7,15 @@ module.exports = async context => { name: 'plugin', message: 'Plugin name? (we will add the namespacing for you)', }) + if (!answerPluginName.plugin) throw Error('A plugin requires a name') const pluginName = `solidarity-${answerPluginName.plugin.replace('solidarity-', '')}` + const description = await prompt.ask({ + type: 'input', + name: 'pluginDesc', + message: 'Short description of the plugin' + }) + const ruleChoices = [ 'I do not want a generated rule file', 'Just a simple rule template', From a00c088f5ee9e13dc0be7051bacb728f822d73b9 Mon Sep 17 00:00:00 2001 From: Gant Date: Mon, 19 Feb 2018 21:47:45 -0600 Subject: [PATCH 08/14] description prompt --- src/extensions/functions/createPlugin.ts | 4 ++-- src/templates/README.md.ejs | 8 +++++--- src/templates/helpful-plugin.js.ejs | 2 +- src/templates/package.json.ejs | 2 +- src/templates/simple-plugin.js.ejs | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index 957de1c..100a21c 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -13,7 +13,7 @@ module.exports = async context => { const description = await prompt.ask({ type: 'input', name: 'pluginDesc', - message: 'Short description of the plugin' + message: 'Short plugin description (used in various places)' }) const ruleChoices = [ @@ -45,7 +45,7 @@ module.exports = async context => { template.generate({ template: fileSet[0], target: `${pluginName}/${fileSet[1]}`, - props: { pluginName, customRules }, + props: { pluginName, customRules, description: description.pluginDesc }, }) }) } diff --git a/src/templates/README.md.ejs b/src/templates/README.md.ejs index 1db62a3..9b4f826 100644 --- a/src/templates/README.md.ejs +++ b/src/templates/README.md.ejs @@ -1,10 +1,12 @@ # <%= props.pluginName %> -### Short Description +## <%= props.description %> Much longer description +## Install: +`npm i <%= props.pluginName %>` or `yarn add <%= props.pluginName %>` +This plugin will automatically be picked up by Solidarity (which should already be installed). - -# What is Solidarity? +## What is Solidarity? #### [:newspaper: Read More About Solidarity Here](https://github.com/infinitered/solidarity) diff --git a/src/templates/helpful-plugin.js.ejs b/src/templates/helpful-plugin.js.ejs index bd6df9d..a4a1c0c 100644 --- a/src/templates/helpful-plugin.js.ejs +++ b/src/templates/helpful-plugin.js.ejs @@ -4,7 +4,7 @@ module.exports = (context) => { // Register this plugin context.addPlugin({ name: '<%= props.pluginName %>', - description: 'My custom plugin', + description: '<%= props.description %>', snapshot: async (context) => { // start with template let solidarity = require('../templates/<%= props.pluginName %>-template.json') diff --git a/src/templates/package.json.ejs b/src/templates/package.json.ejs index 45b405c..172727e 100644 --- a/src/templates/package.json.ejs +++ b/src/templates/package.json.ejs @@ -2,7 +2,7 @@ "name": "<%= props.pluginName %>", "version": "1.0.0", "repository": "https://github.com//<%= props.pluginName %>", - "description": "Description here", + "description": "<%= props.description %>", "author": "Super Awesome Coder", "license": "MIT", "private": false, diff --git a/src/templates/simple-plugin.js.ejs b/src/templates/simple-plugin.js.ejs index 9f7ec92..dff1bd6 100644 --- a/src/templates/simple-plugin.js.ejs +++ b/src/templates/simple-plugin.js.ejs @@ -2,7 +2,7 @@ module.exports = (context) => { // Register this plugin context.addPlugin({ name: '<%= props.pluginName %>', - description: 'My custom plugin', + description: '<%= props.description %>', snapshot: '<%= props.pluginName %>-template.json'<% if(props.customRules){ %>, rules: { ruleName: { From f501ffe5dced13159896717ba467ad076704fe1b Mon Sep 17 00:00:00 2001 From: Gant Date: Mon, 19 Feb 2018 22:56:17 -0600 Subject: [PATCH 09/14] added create tests --- __tests__/command_helpers/createPlugin.ts | 3 ++ .../commands/__snapshots__/create.ts.snap | 9 +++++ __tests__/commands/create.ts | 34 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 __tests__/command_helpers/createPlugin.ts create mode 100644 __tests__/commands/__snapshots__/create.ts.snap create mode 100644 __tests__/commands/create.ts diff --git a/__tests__/command_helpers/createPlugin.ts b/__tests__/command_helpers/createPlugin.ts new file mode 100644 index 0000000..09a542c --- /dev/null +++ b/__tests__/command_helpers/createPlugin.ts @@ -0,0 +1,3 @@ +test('placeholder', () => { + expect(false).toBeFalsy() +}) diff --git a/__tests__/commands/__snapshots__/create.ts.snap b/__tests__/commands/__snapshots__/create.ts.snap new file mode 100644 index 0000000..940d4d3 --- /dev/null +++ b/__tests__/commands/__snapshots__/create.ts.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Snapshot create command 1`] = ` +Object { + "alias": "c", + "description": "Displays this help", + "run": [Function], +} +`; diff --git a/__tests__/commands/create.ts b/__tests__/commands/create.ts new file mode 100644 index 0000000..fd6119e --- /dev/null +++ b/__tests__/commands/create.ts @@ -0,0 +1,34 @@ +import createCommand from '../../src/commands/create' +const mockContext = require('mockContext') + +test('Snapshot create command', () => { + expect(createCommand).toMatchSnapshot() +}) + +it('enforces required properties', () => { + expect(createCommand.description).toBeTruthy() + expect(createCommand.run).toBeTruthy() + expect(typeof createCommand.run).toBe('function') +}) + +test('check solidarity create with no parameter', async () => { + const result = await createCommand.run(mockContext) + expect(mockContext.print.error.mock.calls).toEqual([["Missing what to create"], ["solidarity create "]]) + expect(mockContext.print.info.mock.calls.length).toBe(1) +}) + +test('check solidarity create with plugin', async () => { + const goodContext = { + ...mockContext, + parameters: { first: 'plugin' }, + solidarity: { createPlugin: jest.fn() } + } + await createCommand.run(goodContext) + expect(goodContext.solidarity.createPlugin).toBeCalled() + + // now make it fail + const errorString = 'ER MA GERD ARRAWRS' + goodContext.solidarity.createPlugin = jest.fn(() => throw Error(errorString)) + await createCommand.run(goodContext) + expect(goodContext.print.error.mock.calls.slice(-1).toString()).toEqual(`Error: ${errorString}`) +}) From 2878426311e3b47781a9a34e30eedfa7d1dbbe2e Mon Sep 17 00:00:00 2001 From: Gant Date: Mon, 19 Feb 2018 23:00:41 -0600 Subject: [PATCH 10/14] prep for testing --- src/extensions/functions/createPlugin.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index 100a21c..275b526 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -48,4 +48,7 @@ module.exports = async context => { props: { pluginName, customRules, description: description.pluginDesc }, }) }) + + // for tests really + return files } From ea5036bb84894c134b82e7f559184967b348e3d3 Mon Sep 17 00:00:00 2001 From: Gant Date: Sun, 25 Feb 2018 10:45:38 -0600 Subject: [PATCH 11/14] finish tests --- __tests__/__mocks__/mockContext.ts | 6 +++++- .../__snapshots__/createPlugin.ts.snap | 20 +++++++++++++++++++ __tests__/command_helpers/createPlugin.ts | 16 +++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 __tests__/command_helpers/__snapshots__/createPlugin.ts.snap diff --git a/__tests__/__mocks__/mockContext.ts b/__tests__/__mocks__/mockContext.ts index 599375e..e06b240 100644 --- a/__tests__/__mocks__/mockContext.ts +++ b/__tests__/__mocks__/mockContext.ts @@ -17,6 +17,9 @@ const mockContext = { system: { startTimer: jest.fn(() => jest.fn()), }, + template: { + generate: jest.fn(), + }, print: { error: jest.fn(), success: jest.fn(), @@ -45,7 +48,8 @@ const mockContext = { options: {}, }, prompt: { - ask: jest.fn(() => Promise.resolve({ createFile: true })), + ask: jest.fn(({ name }) => Promise.resolve({ [name]: 'taco', createFile: true })), + confirm: jest.fn(() => true) }, solidarity: noConfigSolidarity, } diff --git a/__tests__/command_helpers/__snapshots__/createPlugin.ts.snap b/__tests__/command_helpers/__snapshots__/createPlugin.ts.snap new file mode 100644 index 0000000..34dd200 --- /dev/null +++ b/__tests__/command_helpers/__snapshots__/createPlugin.ts.snap @@ -0,0 +1,20 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`check result shape 1`] = `[Function]`; + +exports[`investigate createPlugin 1`] = ` +Array [ + Array [ + ".gitignore.ejs", + ".gitignore", + ], + Array [ + "README.md.ejs", + "README.md", + ], + Array [ + "package.json.ejs", + "package.json", + ], +] +`; diff --git a/__tests__/command_helpers/createPlugin.ts b/__tests__/command_helpers/createPlugin.ts index 09a542c..2585142 100644 --- a/__tests__/command_helpers/createPlugin.ts +++ b/__tests__/command_helpers/createPlugin.ts @@ -1,3 +1,15 @@ -test('placeholder', () => { - expect(false).toBeFalsy() +const createPlugin: Function = require('../../src/extensions/functions/createPlugin') +const context = require('mockContext') + +test('check result shape', () => { + expect(createPlugin).toMatchSnapshot() +}) + +test('investigate createPlugin', async () => { + + const result = await createPlugin(context) + expect(result).toMatchSnapshot() + expect(context.template.generate).toBeCalled() + expect(context.prompt.ask).toBeCalled() + expect(context.prompt.confirm).toBeCalled() }) From adaeec11da2b13c7dea39dd7f3fd179101ee1f58 Mon Sep 17 00:00:00 2001 From: Gant Date: Sun, 25 Feb 2018 10:55:28 -0600 Subject: [PATCH 12/14] add create plugin link to docs --- __tests__/__mocks__/mockContext.ts | 2 ++ __tests__/command_helpers/createPlugin.ts | 1 + src/extensions/functions/createPlugin.ts | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/__tests__/__mocks__/mockContext.ts b/__tests__/__mocks__/mockContext.ts index e06b240..1ed2f51 100644 --- a/__tests__/__mocks__/mockContext.ts +++ b/__tests__/__mocks__/mockContext.ts @@ -36,11 +36,13 @@ const mockContext = { green: jest.fn(), red: jest.fn(), blue: jest.fn(), + magenta: jest.fn(), }, colors: { green: jest.fn(), red: jest.fn(), blue: jest.fn(), + magenta: jest.fn(), }, }, printSeparator: jest.fn(), diff --git a/__tests__/command_helpers/createPlugin.ts b/__tests__/command_helpers/createPlugin.ts index 2585142..f04b987 100644 --- a/__tests__/command_helpers/createPlugin.ts +++ b/__tests__/command_helpers/createPlugin.ts @@ -12,4 +12,5 @@ test('investigate createPlugin', async () => { expect(context.template.generate).toBeCalled() expect(context.prompt.ask).toBeCalled() expect(context.prompt.confirm).toBeCalled() + expect(context.print.success).toBeCalled() }) diff --git a/src/extensions/functions/createPlugin.ts b/src/extensions/functions/createPlugin.ts index 275b526..7db2f7f 100644 --- a/src/extensions/functions/createPlugin.ts +++ b/src/extensions/functions/createPlugin.ts @@ -1,6 +1,7 @@ module.exports = async context => { let files = [['.gitignore.ejs', '.gitignore'], ['README.md.ejs', 'README.md'], ['package.json.ejs', 'package.json']] const { print, template, prompt } = context + const { colors } = print const answerPluginName = await prompt.ask({ type: 'input', @@ -49,6 +50,10 @@ module.exports = async context => { }) }) + print.success(` + Done! ${colors.magenta('\n\nPlugin Docs: https://infinitered.github.io/solidarity/#/docs/plugins')} + `) + // for tests really return files } From ea8d1afd6e802698487e759538dbf369bc10c1b9 Mon Sep 17 00:00:00 2001 From: Gant Date: Sun, 25 Feb 2018 11:01:09 -0600 Subject: [PATCH 13/14] add reference to plugin creator in docs --- .vscode/cSpell.json | 3 ++- docs/plugins.md | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index 088412a..dab156f 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -47,7 +47,8 @@ "tada", "tempy", "updtr", - "v1" + "v1", + "walkthrough" ], // flagWords - list of words to be always considered incorrect // This is useful for offensive words and common spelling errors. diff --git a/docs/plugins.md b/docs/plugins.md index a291c0f..9e099da 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -1,6 +1,8 @@ # Writing your own plugins If you're using a technology that doesn't have a plugin, or if you'd just like build your own custom rules to use in solidarity, we've made creating plugins extremely simple. +The following docs will show you all the features of how to create a plugin. If you'd like, you can generate a plugin-base by typing `solidarity create plugin`. This starts a walkthrough that will ask you questions to help you get started writing your plugin. + ## Plugin Docs * [Write the Simplest Plugin](/docs/simplePlugin.md) * [Plugins that write Solidarity Files from Code](/docs/solidarityFromCode.md) From 1e6220eb1a9fb00962a18ccc53e8a052265f3f5d Mon Sep 17 00:00:00 2001 From: Gant Date: Sun, 25 Feb 2018 11:25:54 -0600 Subject: [PATCH 14/14] :chart_with_upwards_trend: speed up cov from CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 792908c..3b0f7bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ script: - 'npm run test:ci' - yarn danger ci after_success: - - './node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/codecov' + - './node_modules/.bin/jest --coverage --runInBand && cat ./coverage/lcov.info | ./node_modules/.bin/codecov' notifications: webhooks: urls: