Skip to content

Commit 89a10c1

Browse files
committed
Add generator blueprint for prototype extensions.
Resolves #88
1 parent a8ee9e7 commit 89a10c1

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= baseDeclarations(dasherizedPackageName) %>

blueprints/ember-cli-typescript/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
const fs = require('fs');
44
const path = require('path');
55

6+
const APP_DECLARATIONS = `
7+
declare global {
8+
interface Array<T> extends Ember.ArrayPrototypeExtensions<T> {}
9+
interface Function extends Ember.FunctionPrototypeExtensions {}
10+
}
11+
`;
12+
613
module.exports = {
14+
APP_DECLARATIONS,
15+
716
description: 'Initialize files needed for typescript compilation',
817

918
install(options) {
@@ -49,6 +58,11 @@ module.exports = {
4958

5059
return JSON.stringify(paths, null, 2).replace(/\n/g, '\n ');
5160
},
61+
baseDeclarations: dasherizedName => {
62+
const isDummyApp = dasherizedName === 'dummy';
63+
const useAppDeclarations = !(isAddon || isDummyApp);
64+
return useAppDeclarations ? APP_DECLARATIONS : '';
65+
},
5266
};
5367
},
5468

node-tests/blueprints/ember-cli-typescript-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const path = require('path');
55
const helpers = require('ember-cli-blueprint-test-helpers/helpers');
66
const chaiHelpers = require('ember-cli-blueprint-test-helpers/chai');
77

8+
const ects = require('../../blueprints/ember-cli-typescript');
9+
810
const expect = chaiHelpers.expect;
911
const file = chaiHelpers.file;
1012

@@ -39,6 +41,7 @@ describe('Acceptance: ember-cli-typescript generator', function() {
3941

4042
const projectTypes = file('types/my-app/index.d.ts');
4143
expect(projectTypes).to.exist;
44+
expect(projectTypes).to.include(ects.APP_DECLARATIONS);
4245

4346
const environmentTypes = file('types/my-app/config/environment.d.ts');
4447
expect(environmentTypes).to.exist;
@@ -72,6 +75,10 @@ describe('Acceptance: ember-cli-typescript generator', function() {
7275
});
7376

7477
expect(tsconfigJson.include).to.deep.equal(['addon', 'tests']);
78+
79+
const projectTypes = file('types/my-addon/index.d.ts');
80+
expect(projectTypes).to.exist;
81+
expect(projectTypes).not.to.include(ects.APP_DECLARATIONS);
7582
});
7683
});
7784

@@ -105,6 +112,10 @@ describe('Acceptance: ember-cli-typescript generator', function() {
105112
});
106113

107114
expect(json.include).to.deep.equal(['app', 'tests', 'lib/my-addon-1', 'lib/my-addon-2']);
115+
116+
const projectTypes = file('types/my-app/index.d.ts');
117+
expect(projectTypes).to.exist;
118+
expect(projectTypes).to.include(ects.APP_DECLARATIONS);
108119
});
109120
});
110121
});

0 commit comments

Comments
 (0)