Skip to content

Commit

Permalink
Update package.json and other files. Run npm install. Improve log. Ad…
Browse files Browse the repository at this point in the history
…d typiings
  • Loading branch information
unional committed Feb 5, 2016
1 parent 756a100 commit 0e1bace
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
47 changes: 39 additions & 8 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
// var extend = require('deep-extend');
var changeCase = require('change-case');

module.exports = yeoman.generators.Base.extend({
prompting: {
greeting() {
this.log(yosay('Welcome to the sensational ' + chalk.red('typings') + ' generator!'));
},
sourceUri() {
var done = this.async();

// Have Yeoman greet the user.
this.log(yosay('Welcome to the sensational ' + chalk.red('typings') + ' generator!'));

const uriExamples = [
'facebook/react',
'atom/atom',
Expand All @@ -27,7 +28,7 @@ module.exports = yeoman.generators.Base.extend({
validate: (value) => value.length > 0
}, (props) => {
this.sourceUri = props.sourceUri;
this.sourceUrl = `https://github.com/${props.sourceUri}`;
this.sourcePackageUrl = `https://github.com/${props.sourceUri}`;
this.sourcePackageName = props.sourceUri.split('/')[1];
this.prettyPackageName = changeCase.titleCase(this.sourcePackageName.replace('-', ' '));
done();
Expand Down Expand Up @@ -96,14 +97,44 @@ module.exports = yeoman.generators.Base.extend({
createTest() {
this.fs.write('test/test.ts',
`import * as ${this.sourcePackageName} from '${this.sourcePackageName}'`);
},
updatePackageJson() {
var pkg = this.fs.read(this.destinationPath('package.json'));
console.log(this.packageName, this.sourcePackageUrl, this.sourcePackageName, this.username);
pkg = pkg.replace('{username}', this.username);
pkg = pkg.replace('{packageName}', this.packageName);
pkg = pkg.replace('{sourcePackageName}', this.sourcePackageName);
pkg = pkg.replace('{sourcePackageUrl}', this.sourcePackageUrl);
this.fs.write(this.destinationPath('package.json'), pkg);

// Don't know why it doesn't work.
// var pkg = this.fs.readJSON(this.destinationPath('package.json'), {});
// extend(pkg, {
// packageName: this.packageName,
// sourcePackageUrl: this.sourcePackageUrl,
// sourcePackageName: this.sourcePackageName,
// username: this.username
// });
// this.fs.writeJSON(this.destinationPath('package.json'), pkg);
},
updateLICENSE() {
var lic = this.fs.read(this.destinationPath('LICENSE'));
lic = lic.replace('{username}', this.username);
this.fs.write(this.destinationPath('LICENSE'), lic);
}
},
install: {
npm() {
this.log(`Running ${chalk.green('npm install')}...`);
this.spawnCommandSync('npm', ['install']);
}
},
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.`);

this.log(`Almost ready! Run ${chalk.green(`typings install ${this.sourcePackageName} --ambient"`) }`);
this.log(' to get a copy of the DefinitelyTyped file (if available)');
this.log(' so you have something to start with!');
}
}
});
8 changes: 8 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "commonjs"
},
"files": [
"typings/main.d.ts"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"yosay": "^1.0.2"
},
"devDependencies": {
"deep-extend": "^0.4.1",
"eslint-config-xo-space": "^0.7.0",
"gulp": "^3.9.0",
"gulp-eslint": "^1.0.0",
Expand Down
8 changes: 8 additions & 0 deletions typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"chalk": "github:typings/typed-chalk#a7e422c5455e70292e5675a727d43a7b05fc3e58"
},
"ambientDependencies": {
"change-case": "github:DefinitelyTyped/DefinitelyTyped/change-case/change-case.d.ts#ddab41325d5dba4f6488d5b9a8b4dcb9d2b2b361"
}
}

0 comments on commit 0e1bace

Please sign in to comment.