@mendix/generator-widget
Version:
Mendix Pluggable Widgets Generator
177 lines (172 loc) • 5.55 kB
JavaScript
const { valid, satisfies } = require("semver");
function promptWidgetProperties(mxProjectDir, widgetName) {
return [
{
type: "input",
name: "name",
validate: input => {
if (/^([a-zA-Z]+)$/.test(input)) {
return true;
}
return "Your widget name may only contain characters matching [a-zA-Z]. Please provide a valid name.";
},
message: "What is the name of your widget?",
default: widgetName ? widgetName : "MyWidget"
},
{
type: "input",
name: "description",
message: "Enter a description for your widget",
default: "My widget description"
},
{
type: "input",
name: "organization",
validate: input => {
if (/[^a-zA-Z0-9_.-]/.test(input)) {
return "Your organization name may only contain characters matching [a-zA-Z0-9_.-]. Please provide a valid name.";
}
if (!/^([a-zA-Z0-9_-]+.)*[a-zA-Z0-9_-]+$/.test(input)) {
return "Your organization name must follow the structure (namespace.)org-name, for example 'mendix' or 'com.mendix.widgets'. Please provide a valid name.";
}
return true;
},
message: "Organization name",
default: "Mendix",
store: true
},
{
type: "input",
name: "copyright",
message: "Add a copyright",
default: `© Mendix Technology BV ${new Date().getFullYear()}. All rights reserved.`,
store: true
},
{
type: "input",
name: "license",
message: "Add a license",
default: "Apache-2.0",
store: true
},
{
type: "input",
name: "version",
validate(input) {
if (valid(input) && satisfies(input, ">=0.0.1")) {
return true;
}
return "Your version needs to be formatted as x.x.x and starts at 0.0.1";
},
message: "Initial version",
default: "1.0.0"
},
{
type: "input",
name: "author",
message: "Author",
default: "John",
store: true
},
{
type: "input",
name: "projectPath",
message: "Mendix project path",
default: mxProjectDir ? mxProjectDir : "./tests/testProject"
},
{
type: "list",
name: "programmingLanguage",
message: "Which programming language do you want to use for the widget?",
choices: [
{
name: "JavaScript ES6",
value: "javascript"
},
{
name: "TypeScript",
value: "typescript"
}
],
default: "javascript",
store: true
},
{
type: "list",
name: "programmingStyle",
message: "Which type of components do you want to use?",
choices: [
{
name: "Class Components",
value: "class"
},
{
name: "Function Components",
value: "function"
}
],
default: "class",
store: true
},
{
type: "list",
name: "platform",
message: "Which type of widget are you developing?",
choices: [
{
name: "For web and hybrid mobile apps",
value: "web"
},
{
name: "For native mobile apps",
value: "native"
}
],
default: "web",
store: true
},
{
type: "list",
name: "boilerplate",
message: "Which template do you want to use for the widget?",
choices: [
{
name: "Full Boilerplate (recommended for beginners)",
value: "full"
},
{
name: "Empty widget (recommended for more experienced developers)",
value: "empty"
}
],
default: "full",
store: true
}
];
}
function promptTestsInfo(props) {
if (props) {
const prompts = [
{
type: "confirm",
name: "hasUnitTests",
message: "Add unit tests for the widget ? (recommended for Full Boilerplate)",
default: !!(props.boilerplate && props.boilerplate === "full")
}
];
if (props.platform && props.platform === "web") {
prompts.push({
type: "confirm",
name: "hasE2eTests",
message: "Add End-to-end tests for the widget ? (recommended for Full Boilerplate)",
default: !!(props.boilerplate && props.boilerplate === "full")
});
}
return prompts;
}
return [];
}
module.exports = {
promptWidgetProperties,
promptTestsInfo
};