Skip to content

Commit

Permalink
Update questions and add package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Feb 5, 2016
1 parent 5fa5d11 commit 756a100
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 45 deletions.
139 changes: 94 additions & 45 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
}
});
21 changes: 21 additions & 0 deletions generators/app/templates/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Empty file.
28 changes: 28 additions & 0 deletions generators/app/templates/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions generators/app/templates/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},
"files": [
"test.ts",
"../main.d.ts",
"../typings/main.d.ts"
]
}

0 comments on commit 756a100

Please sign in to comment.