UNPKG

generator-backed-element

Version:
1 lines 8.74 kB
{"version":3,"file":"index-node.js","sources":["../src/element.js"],"sourcesContent":["'use strict';\r\nimport Generator from 'yeoman-generator';\r\nimport chalk from 'chalk';\r\nimport yosay from 'yosay';\r\nimport utils from 'backed-utils';\r\nimport path from 'path';\r\nimport os from 'os';\r\nconst platform = os.platform();\r\n\r\nexport default class extends Generator {\r\n constructor(args, opts) {\r\n super(args, opts);\r\n\r\n // This method adds support for a `--coffee` flag\r\n this.option('default');\r\n this.argument('name', {type: 'string', required: false});\r\n }\r\n\r\n initializing() {\r\n const name = this.options.name || path.win32.basename(process.cwd());\r\n const _className = utils.toJsProp(name);\r\n const className = _className.charAt(0).toUpperCase() + _className.slice(1);\r\n this.props = {\r\n name: name,\r\n className: className\r\n };\r\n }\r\n\r\n prompting() {\r\n var prompts = [{\r\n type: 'input',\r\n name: 'name',\r\n message: 'Whats the name for your component?',\r\n default: this.props.name,\r\n when: !this.options.name\r\n }, {\r\n type: 'input',\r\n name: 'version',\r\n message: 'Version',\r\n default: '0.0.0'\r\n }, {\r\n type: 'input',\r\n name: 'description',\r\n message: 'Description',\r\n when: !this.props.description\r\n }, {\r\n type: 'input',\r\n name: 'homepage',\r\n message: 'Project homepage url',\r\n when: !this.props.homepage\r\n }, {\r\n type: 'input',\r\n store: true,\r\n name: 'authorName',\r\n message: 'Author\\'s Name',\r\n default: this.user.git.name()\r\n }, {\r\n type: 'input',\r\n store: true,\r\n name: 'authorEmail',\r\n message: 'Author\\'s Email',\r\n default: this.user.git.email()\r\n }, {\r\n type: 'input',\r\n store: true,\r\n name: 'authorUrl',\r\n message: 'Author\\'s Homepage',\r\n default: ''\r\n }, {\r\n type: 'confirm',\r\n store: true,\r\n name: 'license',\r\n message: 'Include license?',\r\n default: true\r\n }, {\r\n type: 'input',\r\n name: 'keywords',\r\n message: 'Package keywords (comma to split)'\r\n }];\r\n\r\n if (this.options.default) return;\r\n else return this.prompt(prompts).then(props => {\r\n // To access props later use this.props.someAnswer;\r\n this.props = props;\r\n });\r\n }\r\n\r\n configuring() {\r\n this.composeWith(require.resolve('generator-node/generators/git'), {\r\n name: this.props.name || this.options.name,\r\n githubAccount: this.props.authorEmail\r\n });\r\n\r\n if (this.props.license) {\r\n this.composeWith(require.resolve('generator-license/app'), {\r\n name: this.props.authorName,\r\n email: this.props.authorEmail,\r\n website: this.props.authorUrl\r\n });\r\n }\r\n }\r\n\r\n writing() {\r\n this.fs.copy(\r\n this.templatePath('.*'),\r\n this.destinationPath('./')\r\n );\r\n\r\n this.fs.copyTpl(\r\n this.templatePath('package.json'),\r\n this.destinationPath('package.json'),\r\n {\r\n name: this.props.name || this.options.name,\r\n version: this.props.version,\r\n authorName: this.props.authorName,\r\n authorEmail: this.props.authorEmail,\r\n authorUrl: this.props.authorUrl\r\n }\r\n );\r\n\r\n this.fs.copyTpl(\r\n this.templatePath('backed.json'),\r\n this.destinationPath('backed.json'),\r\n {\r\n name: this.props.name || this.options.name\r\n }\r\n );\r\n\r\n this.fs.copyTpl(\r\n this.templatePath('backed-element.js'),\r\n this.destinationPath(`src/${this.props.name || this.options.name}.js`),\r\n {\r\n className: this.props.className\r\n }\r\n );\r\n\r\n this.fs.copyTpl(\r\n this.templatePath('backed-element.html'),\r\n this.destinationPath(`${this.props.name || this.options.name}.html`),\r\n {\r\n name: this.props.name || this.options.name\r\n }\r\n );\r\n\r\n this.fs.copyTpl(\r\n this.templatePath('demo.html'),\r\n this.destinationPath('demo/index.html'),\r\n {\r\n name: this.props.name || this.options.name\r\n }\r\n );\r\n }\r\n\r\n install() {\r\n try {\r\n console.log(chalk.yellow('backed version'))\r\n this.spawnCommandSync('backed', ['version']);\r\n console.log();\r\n } catch (e) {\r\n if (platform === 'win32') {\r\n this.spawnCommandSync('yarn', ['global', 'add', 'backed-cli']);\r\n } else {\r\n this.spawnCommandSync('sudo', ['yarn', 'global', 'add', 'backed-cli']);\r\n }\r\n }\r\n this.log('Swiping things up');\r\n this.spawnCommand('rm', ['-rf', 'node_modules']);\r\n\r\n this.installDependencies({\r\n bower: false,\r\n npm: false,\r\n yarn: true\r\n });\r\n }\r\n}\r\n"],"names":["platform","os","args","opts","option","argument","type","required","name","options","path","win32","basename","process","cwd","_className","utils","toJsProp","className","charAt","toUpperCase","slice","props","prompts","description","homepage","user","git","email","default","prompt","then","composeWith","require","resolve","authorEmail","license","authorName","authorUrl","fs","copy","templatePath","destinationPath","copyTpl","version","log","chalk","yellow","spawnCommandSync","e","spawnCommand","installDependencies","Generator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAMA,WAAWC,GAAGD,QAAH,EAAjB;;;;;kBAGcE,IAAZ,EAAkBC,IAAlB,EAAwB;;;;+GAChBD,IADgB,EACVC,IADU;;UAIjBC,MAAL,CAAY,SAAZ;UACKC,QAAL,CAAc,MAAd,EAAsB,EAACC,MAAM,QAAP,EAAiBC,UAAU,KAA3B,EAAtB;;;;;;mCAGa;UACPC,OAAO,KAAKC,OAAL,CAAaD,IAAb,IAAqBE,KAAKC,KAAL,CAAWC,QAAX,CAAoBC,QAAQC,GAAR,EAApB,CAAlC;UACMC,aAAaC,MAAMC,QAAN,CAAeT,IAAf,CAAnB;UACMU,YAAYH,WAAWI,MAAX,CAAkB,CAAlB,EAAqBC,WAArB,KAAqCL,WAAWM,KAAX,CAAiB,CAAjB,CAAvD;WACKC,KAAL,GAAa;cACLd,IADK;mBAEAU;OAFb;;;;gCAMU;;;UACNK,UAAU,CAAC;cACP,OADO;cAEP,MAFO;iBAGJ,oCAHI;iBAIJ,KAAKD,KAAL,CAAWd,IAJP;cAKP,CAAC,KAAKC,OAAL,CAAaD;OALR,EAMX;cACK,OADL;cAEK,SAFL;iBAGQ,SAHR;iBAIQ;OAVG,EAWX;cACK,OADL;cAEK,aAFL;iBAGQ,aAHR;cAIK,CAAC,KAAKc,KAAL,CAAWE;OAfN,EAgBX;cACK,O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