From 756a100c206160d7ec04a49afeae8c97215764d1 Mon Sep 17 00:00:00 2001 From: Homa Wong Date: Thu, 4 Feb 2016 23:50:46 -0800 Subject: [PATCH] Update questions and add package.json --- generators/app/index.js | 139 +++++++++++++------- generators/app/templates/LICENSE | 21 +++ generators/app/templates/main.d.ts | 0 generators/app/templates/package.json | 28 ++++ generators/app/templates/test/tsconfig.json | 1 + 5 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 generators/app/templates/LICENSE create mode 100644 generators/app/templates/main.d.ts create mode 100644 generators/app/templates/package.json diff --git a/generators/app/index.js b/generators/app/index.js index d1b8086..d1d2fc1 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -5,56 +5,105 @@ var yosay = require('yosay'); var changeCase = require('change-case'); module.exports = yeoman.generators.Base.extend({ - prompting: function () { - var done = this.async(); + prompting: { + sourceUri() { + var done = this.async(); - // Have Yeoman greet the user. - this.log(yosay('Welcome to the sensational ' + chalk.red('typings') + ' generator!')); + // Have Yeoman greet the user. + this.log(yosay('Welcome to the sensational ' + chalk.red('typings') + ' generator!')); - this.prompt({ - type: 'input', - name: 'repo', - message: 'What is the username/repo of the package you are writing this typings for?', - default: 'username/repo' - }, function (props) { - this.sourceUrl = `https://github.com/${props.repo}`; - this.sourcePackageName = props.repo.split('/')[1]; - this.prettyPackageName = changeCase.titleCase(this.sourcePackageName.replace('-', ' ')); - done(); - }.bind(this)); - }, - - writing: function () { - this.fs.copy( - this.templatePath('**/*'), - this.destinationPath() - ); - this.fs.copy( - this.templatePath('**/.*'), - this.destinationPath() - ); - var typeFileName = `${this.sourcePackageName}.d.ts`; - - var typings = { name: this.sourcePackageName, main: typeFileName }; - this.fs.writeJSON(this.destinationPath('typings.json'), typings); + const uriExamples = [ + 'facebook/react', + 'atom/atom', + 'microsoft/vscode', + 'angular/angular' + ]; - var tsconfig = { - compilerOptions: { - module: 'commonjs' - }, - files: [typeFileName] - }; - this.fs.writeJSON(this.destinationPath('tsconfig.json'), tsconfig); + this.prompt({ + type: 'input', + name: 'sourceUri', + message: `What is the ${chalk.green('source') } author/module name?`, + default: () => uriExamples[Math.round(Math.random() * 4 - 0.5)], + validate: (value) => value.length > 0 + }, (props) => { + this.sourceUri = props.sourceUri; + this.sourceUrl = `https://github.com/${props.sourceUri}`; + this.sourcePackageName = props.sourceUri.split('/')[1]; + this.prettyPackageName = changeCase.titleCase(this.sourcePackageName.replace('-', ' ')); + done(); + }); + }, + packageName() { + var done = this.async(); - this.fs.write(typeFileName, ''); + this.prompt({ + type: 'input', + name: 'packageName', + message: 'Can I name this project as', + default: () => `typed-${this.sourcePackageName}`, + validate: (value) => value.length > 0 + }, (props) => { + this.packageName = props.packageName; + done(); + }); + }, + username() { + var done = this.async(); - this.fs.write('README.md', - `# Typed ${this.prettyPackageName }\n` + - `The type definition for [${this.sourcePackageName }](${this.sourceUrl }).`); - - this.fs.write('test/test.ts', - `import * as ${this.sourcePackageName} from '${this.sourcePackageName}'`); + this.prompt({ + type: 'input', + name: 'username', + message: 'And your GitHub username is...', + validate: (value) => value.length > 0, + store: true + }, (props) => { + this.username = props.username; + done(); + }); + } + }, - this.log(`Run "typings install file:typings.json" when you are ready to test your definition in test/test.ts.`); + writing: { + copyFiles() { + this.fs.copy( + this.templatePath('**/*'), + this.destinationPath() + ); + this.fs.copy( + this.templatePath('**/.*'), + this.destinationPath() + ); + }, + createTypings() { + var typings = { name: this.sourcePackageName, main: 'main.d.ts' }; + this.fs.writeJSON(this.destinationPath('typings.json'), typings); + }, + createTsconfig() { + var tsconfig = { + compilerOptions: { + module: 'commonjs', + moduleResolution: 'node' + }, + files: ['main.d.ts', 'typings/main.d.ts'] // TODO: add ambient source typings file + }; + this.fs.writeJSON(this.destinationPath('tsconfig.json'), tsconfig); + }, + createREADME() { + this.fs.write('README.md', + `# Typed ${this.prettyPackageName}\n` + + `The type definition for [${this.sourcePackageName }](${this.sourceUrl}).`); + }, + createTest() { + this.fs.write('test/test.ts', + `import * as ${this.sourcePackageName} from '${this.sourcePackageName}'`); + } + }, + end: { + goodbye() { + this.log(`Almost ready! Run ${chalk.green(`typings install ${this.sourcePackageName} --ambient"`)} to get a copy of the DefinitelyTyped file (if available) so you have something to start with!`); + this.log(''); + this.log(''); + this.log(`When you are ready, run ${chalk.green('typings install -D file:main.d.ts')} when you are ready to test your definition in test/test.ts.`); + } } }); diff --git a/generators/app/templates/LICENSE b/generators/app/templates/LICENSE new file mode 100644 index 0000000..df96af5 --- /dev/null +++ b/generators/app/templates/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 {username} + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/generators/app/templates/main.d.ts b/generators/app/templates/main.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/generators/app/templates/package.json b/generators/app/templates/package.json new file mode 100644 index 0000000..34c15d1 --- /dev/null +++ b/generators/app/templates/package.json @@ -0,0 +1,28 @@ +{ + "name": "{packageName}", + "version": "0.0.1", + "description": "The type definition for {sourcePackageUrl}", + "directories": { + "test": "test" + }, + "dependencies": {}, + "devDependencies": { + "tslint": "^3.3.0", + "typescript": "^1.8.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/{username}/{packageName}.git" + }, + "keywords": [ + "typings", + "typed", + "{sourcePackageName}" + ], + "author": "{username}", + "license": "MIT", + "bugs": { + "url": "https://github.com/{username}/{packageName}/issues" + }, + "homepage": "https://github.com/{username}/{packageName}#readme" +} \ No newline at end of file diff --git a/generators/app/templates/test/tsconfig.json b/generators/app/templates/test/tsconfig.json index 7f5e22b..162586c 100644 --- a/generators/app/templates/test/tsconfig.json +++ b/generators/app/templates/test/tsconfig.json @@ -4,6 +4,7 @@ }, "files": [ "test.ts", + "../main.d.ts", "../typings/main.d.ts" ] } \ No newline at end of file