Skip to content

Commit

Permalink
Add ambient support
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Mar 8, 2016
1 parent 6b72e31 commit b009a07
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 31 deletions.
23 changes: 22 additions & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ module.exports = yeoman.Base.extend({
done();
});
},
isAmbient() {
var done = this.async();

this.prompt({
type: 'confirm',
name: 'isAmbient',
message: `Is this module ambient? i.e. does it declare globally?`,
default: true
}, (props) => {
this.isAmbient = props.isAmbient;
done();
});
},
username() {
var done = this.async();

Expand Down Expand Up @@ -164,9 +177,17 @@ module.exports = yeoman.Base.extend({
this.fs.write('test/test.ts',
['/// <reference path="./main.d.ts" />',
'',
`import * as ${this.sourcePackageName} from '${this.sourcePackageName}';`,
this.isAmbient? '': `import * as ${this.sourcePackageName} from '${this.sourcePackageName}';`,
''].join('\n'));
},
updatePackageJson() {
this.fs.copyTpl(
this.templatePath('template/package.json'),
this.destinationPath('package.json'),
{
ambient: this.isAmbient? '--ambient': ''
});
},
createLICENSE() {
var filename = `template/${this.license}.txt`;
var author = this.nameOnLicense.trim();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "typings bundle -o test",
"build": "typings bundle -o test <%- ambient %>",
"test": "ts-node test/test.ts"
},
"private": true,
Expand Down
95 changes: 66 additions & 29 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,73 @@ var path = require('path');
var assert = require('yeoman-assert');
var helpers = require('yeoman-test');

describe('app', function () {
before(function (done) {
this.timeout(60000);
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({
sourceUri: 'visionmedia/batch',
projectUri: 'typed-typings/npm-batch',
// Set to false to avoid longer test time.
isNpm: false,
username: 'unional',
license: 'MIT',
name: 'unional'
})
.on('end', done);
describe('app', function() {
describe('module', function() {
before(function(done) {
this.timeout(60000);
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({
sourceUri: 'visionmedia/batch',
projectUri: 'typed-typings/npm-batch',
// Set to false to avoid longer test time.
isNpm: false,
isAmbient: false,
username: 'unional',
license: 'MIT',
name: 'unional'
})
.on('end', done);
});

it('creates files', function() {
assert.file([
'.vscode/settings.json',
'test/test.ts',
'test/main.d.ts',
'test/browser.d.ts',
'.editorconfig',
'.gitignore',
'LICENSE',
'index.d.ts',
'README.md',
'package.json',
'typings.json',
'tsconfig.json'
]);
});
});
describe('namespace', function() {
before(function(done) {
this.timeout(60000);
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({
sourceUri: 'visionmedia/batch',
projectUri: 'typed-typings/npm-batch',
// Set to false to avoid longer test time.
isNpm: false,
isAmbient: true,
username: 'unional',
license: 'MIT',
name: 'unional'
})
.on('end', done);
});

it('creates files', function () {
assert.file([
'.vscode/settings.json',
'test/test.ts',
'test/main.d.ts',
'test/browser.d.ts',
'.editorconfig',
'.gitignore',
'LICENSE',
'index.d.ts',
'README.md',
'package.json',
'typings.json',
'tsconfig.json'
]);
it('creates files', function() {
assert.file([
'.vscode/settings.json',
'test/test.ts',
'test/main.d.ts',
'test/browser.d.ts',
'.editorconfig',
'.gitignore',
'LICENSE',
'index.d.ts',
'README.md',
'package.json',
'typings.json',
'tsconfig.json'
]);
});
});
});

0 comments on commit b009a07

Please sign in to comment.