diff --git a/generators/app/index.js b/generators/app/index.js index b5fbbde..8c84f2b 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -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(); @@ -164,9 +177,17 @@ module.exports = yeoman.Base.extend({ this.fs.write('test/test.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(); diff --git a/generators/app/templates/package.json b/generators/app/templates/template/package.json similarity index 76% rename from generators/app/templates/package.json rename to generators/app/templates/template/package.json index effe7e2..a799cdb 100644 --- a/generators/app/templates/package.json +++ b/generators/app/templates/template/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "typings bundle -o test", + "build": "typings bundle -o test <%- ambient %>", "test": "ts-node test/test.ts" }, "private": true, diff --git a/test/app.js b/test/app.js index 6e4ec9c..41c7167 100644 --- a/test/app.js +++ b/test/app.js @@ -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' + ]); + }); }); });