-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (57 loc) · 1.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* eslint-disable prettier/prettier */
"use strict";
const Generator = require("yeoman-generator");
const chalk = require("chalk");
const yosay = require("yosay");
const validate = require('validate-element-name');
const path = require("path");
const util = require("./util/index.js");
module.exports = class extends Generator {
async prompting() {
this.log(yosay(chalk.blue("New Polymer 3 Element")));
const prompts = [
{
type: "input",
name: "componentName",
message: "Name of element:",
validate: (value) => {
const isValid = validate(value);
if (!isValid.isValid) {
return isValid.message;
};
return true;
}
},
{
type: "list",
name: "packageManager",
message: "Select package manager",
choices: ["npm", "yarn"]
}
];
this.props = await this.prompt(prompts);
}
writing() {
const templateOptions = {
componentNameAsClass: util.getClassName(this.props.componentName),
componentName: this.props.componentName
}
util.templateToDestTuples.forEach( (pathTuple) => {
this.fs.copyTpl(
this.templatePath( pathTuple[0] ),
this.destinationPath( path.join( this.props.componentName, (pathTuple.length === 1) ? pathTuple[0] : pathTuple[1] ) ),
templateOptions
)
});
this.fs.readJSON(this.destinationPath("package.json"));
}
install() {
let defaults = {
npm: false,
bower: false,
yarn: false
};
defaults[this.props.packageManager] = true;
this.installDependencies(defaults);
}
};