Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Nov 20, 2018
1 parent 14718bc commit 4956754
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 61 deletions.
124 changes: 70 additions & 54 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = class extends Generator {
this.log('Hi! I am your DatoCMS plugin generator!');
this.log('I will generate for you the structure of a Webpack project to start developing your shiny new DatoCMS plugin right away! Let\'s start, shall we? :)');

this.answers = await this.prompt([
const { packageName } = await this.prompt([
{
type : 'input',
name : 'packageName',
Expand All @@ -69,11 +69,15 @@ module.exports = class extends Generator {
return "You need to add a datocms-plugin- prefix!";
}
}
},
}
]);

this.answers = await this.prompt([
{
type : 'input',
name : 'pluginTitle',
message : 'Please insert a human name for this plugin',
default: changeCase.titleCase(packageName.replace('datocms-plugin-', '')),
validate: required,
},
{
Expand All @@ -93,42 +97,6 @@ module.exports = class extends Generator {
],
validate: required,
},
{
type : 'input',
name : 'keywords',
message : 'Please add some tags to make the plugin more discoverable (comma separated)',
validate: required,
},
{
type : 'input',
name : 'authorName',
message : 'What\'s your name?',
validate: required,
},
{
type : 'input',
name : 'authorEmail',
message : 'What\'s your email?',
validate: required,
},
{
type : 'checkbox',
name : 'fieldTypes',
message : 'Which kind of fields is this plugin compatible with?',
choices:
[
{ name: 'Boolean', value: 'boolean' },
{ name: 'Date', value: 'date' },
{ name: 'Date-time', value: 'date_time' },
{ name: 'Float', value: 'float' },
{ name: 'Integer', value: 'integer' },
{ name: 'String', value: 'string' },
{ name: 'Text', value: 'text' },
{ name: 'JSON', value: 'json' },
{ name: 'Color', value: 'color' },
],
validate: atLeastOne,
},
{
type : 'checkbox',
name : 'fieldTypes',
Expand All @@ -148,12 +116,62 @@ module.exports = class extends Generator {
validate: atLeastOne,
},
{
type : 'confirm',
name : 'addToProject',
message : 'Would you like to add this plugin in development mode to one of your projects and start developing it right away?',
type : 'editor',
name : 'parameterDefinitions',
message : 'Please insert any configuration parameters this plugin requires (see https://www.datocms.com/docs/plugins/creating-a-new-plugin/#configuration-parameters)',
default : JSON.stringify({ global: [], instance: [] }, null, 2),
validate: (value) => {
try {
const defs = JSON.parse(value);
if (defs.instance && Array.isArray(defs.instance) && defs.global && Array.isArray(defs.global)) {
return true;
}
return 'Please insert a valid JSON object';
} catch(e) {
return 'Not valid JSON';
}
},
},
]);

this.answers = Object.assign(
{ packageName },
this.answers,
await this.prompt([
{
type : 'input',
name : 'keywords',
message : 'Please add some tags to make the plugin more discoverable (comma separated)',
validate: required,
default: [changeCase.paramCase(this.answers.pluginType)].concat(this.answers.fieldTypes.map(ft => `${changeCase.paramCase(ft)}-field` )).join(', '),
},
{
type : 'input',
name : 'homepage',
message : 'Please add the homepage for this plugin',
validate: required,
default: `https://github.com/YOUR-USER/${packageName}`
},
{
type : 'input',
name : 'authorName',
message : 'What\'s your name?',
validate: required,
},
{
type : 'input',
name : 'authorEmail',
message : 'What\'s your email?',
validate: required,
},
{
type : 'confirm',
name : 'addToProject',
message : 'Would you like to add this plugin in development mode to one of your projects and start developing it right away?',
},
])
);

if (this.answers.addToProject) {
await this.prompt([
{
Expand All @@ -179,8 +197,6 @@ module.exports = class extends Generator {
]);

this.answers.site = answers2.site;

console.log(this.answers.site);
}
}

Expand All @@ -191,9 +207,11 @@ module.exports = class extends Generator {
pluginType,
description,
authorName,
parameterDefinitions,
authorEmail,
keywords,
fieldTypes
fieldTypes,
homepage,
} = this.answers;

this.fs.copy(
Expand All @@ -212,12 +230,13 @@ module.exports = class extends Generator {
authorName,
authorEmail,
fieldTypes,
keywords: keywords.split(',').concat(
[
"datocms",
"datocms-plugin"
]
)
homepage,
parameterDefinitions: JSON.parse(parameterDefinitions),
keywords: ['datocms', 'datocms-plugin'].concat(
[changeCase.paramCase(this.answers.pluginType)],
this.answers.fieldTypes.map(ft => `${changeCase.paramCase(ft)}-field`),
keywords.split(/\s*,\s*/)
).filter((value, index, self) => self.indexOf(value) === index),
}
);

Expand All @@ -238,10 +257,7 @@ module.exports = class extends Generator {
description: description,
fieldTypes,
pluginType,
parameterDefinitions: {
global: [],
instance: [],
},
parameterDefinitions: JSON.parse(parameterDefinitions),
url: `https://${packageName}.localtunnel.me/`,
});
}
Expand Down
3 changes: 2 additions & 1 deletion generators/app/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Start the local development server with:
```
yarn start
```
The plugin will be served from https://<%= packageName %>.localtunnel.me. Insert this URL as the plugin [Entry point URL](https://www.datocms.com/docs/plugins/creating-a-new-plugin/).

The plugin will be served from [https://<%= packageName %>.localtunnel.me/](https://<%= packageName %>.localtunnel.me/). Insert this URL as the plugin [Entry point URL](https://www.datocms.com/docs/plugins/creating-a-new-plugin/).

## Publishing

Expand Down
9 changes: 3 additions & 6 deletions generators/app/templates/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "<%= packageName %>",
"homepage": "https://github.com/YOUR-USER/YOUR-PLUGIN-REPO",
"homepage": "<%= homepage %>",
"version": "0.0.1",
"description": "<%= description %>",
"main": "index.js",
Expand All @@ -13,7 +13,7 @@
"test": "echo 1"
},
"keywords": <%- JSON.stringify(keywords) %>,
"author": "<%= authorName %> <%= authorEmail %>",
"author": "<%= authorName %> <<%= authorEmail %>>",
"license": "ISC",
"datoCmsPlugin": {
"title": "<%= pluginTitle %>",
Expand All @@ -22,10 +22,7 @@
"entryPoint": "dist/index.html",
"pluginType": "field_addon",
"fieldTypes": <%- JSON.stringify(fieldTypes) %>,
"parameters": {
"global": [],
"instance": []
}
"parameters": <%- JSON.stringify(parameterDefinitions) %>
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.54",
Expand Down

0 comments on commit 4956754

Please sign in to comment.