,
42 | nextElement: ClassicElement,
43 | container: Element,
44 | callback?: (component: ClassicComponent
) => any): ClassicComponent
;
45 | function unstable_renderSubtreeIntoContainer
(
46 | parentComponent: Component,
47 | nextElement: ReactElement,
48 | container: Element,
49 | callback?: (component: Component
) => any): Component
;
50 | }
51 |
52 | namespace __DOMServer {
53 | function renderToString(element: ReactElement): string;
54 | function renderToStaticMarkup(element: ReactElement): string;
55 | var version: string;
56 | }
57 | }
58 |
59 | declare module "react-dom" {
60 | import DOM = __React.__DOM;
61 | export = DOM;
62 | }
63 |
64 | declare module "react-dom/server" {
65 | import DOMServer = __React.__DOMServer;
66 | export = DOMServer;
67 | }
--------------------------------------------------------------------------------
/test/mocha/testHelper.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var helpers = require('yeoman-test');
3 | var _ = require('lodash');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var mixinFile = require('../../libs/mixinFile');
7 | var mixinInspector = require('../../libs/mixinInspector');
8 | var utils = {};
9 | mixinFile.extend(utils);
10 | mixinInspector.extend(utils);
11 |
12 | /**
13 | * Get a .yo-rc.json content
14 | * @param {object} config - A config object to apply
15 | * @returns {Object} The json configuration object
16 | */
17 | var getYoRc = function(config) {
18 | config = config || {};
19 | var result = {};
20 | _.defaultsDeep(config, {
21 | appname: 'dummyappname',
22 | clientFolder: 'client'
23 | });
24 | result[this.mixins.getGeneratorFullname()] = config;
25 | return result;
26 | };
27 |
28 | /**
29 | * Run a generator
30 | * @param {String} name - The name of the generator
31 | * @param {Object} config - The config yo-rc object
32 | * @param {String[]} subs - An optional array of sub generators names
33 | * @returns {RunContext} - runContext
34 | */
35 | var runGenerator = function(name, config, subs) {
36 | var deps = _.map(subs, function(sub) {
37 | return [helpers.createDummyGenerator(), sub];
38 | });
39 | var runGen = helpers
40 | .run(path.join(__dirname, '../../generators/' + name))
41 | .inTmpDir(function(dir) {
42 | fs.writeFileSync('.yo-rc.json', config ? JSON.stringify(config) : '{}');
43 | })
44 | .withGenerators(deps);
45 | return runGen;
46 | };
47 |
48 | /**
49 | * Create a proper folder structure for testing the generator on a pre existing project
50 | * @param {Object} config - The config yo rc object
51 | * @param {String} dir - The directory of the scaffolded project
52 | * @param {String} clientFolder - The client folder
53 | * @param {Strijng} targetname - The name of the target
54 | */
55 | var createFolderStructure = function(config, dir, clientFolder, targetname) {
56 | fs.writeFileSync('.yo-rc.json', JSON.stringify(config));
57 | utils.mixins.createDirSync(path.join(dir, clientFolder));
58 | utils.mixins.createDirSync(path.join(dir, clientFolder, 'scripts', 'app'));
59 | utils.mixins.createDirSync(path.join(dir, clientFolder, 'scripts', targetname));
60 | utils.mixins.createDirSync(path.join(dir, clientFolder, 'scripts', 'common'));
61 | utils.mixins.createDirSync(path.join(dir, clientFolder, 'scripts', 'dummy'));
62 | utils.mixins.createDirSync(path.join(dir, clientFolder, 'scripts', 'toto'));
63 | utils.mixins.createDirSync(path.join(dir, clientFolder, 'scripts', 'tata'));
64 | fs.writeFileSync(path.join(clientFolder, 'scripts', 'app', 'index.html'), '');
65 | fs.writeFileSync(path.join(clientFolder, 'scripts', 'toto', 'index.html'), '');
66 | fs.writeFileSync(path.join(clientFolder, 'scripts', 'tata', 'index.html'), '');
67 | };
68 |
69 | module.exports = {
70 | mixins: utils.mixins,
71 | runGenerator: runGenerator,
72 | getYoRc: getYoRc,
73 | createFolderStructure: createFolderStructure
74 | };
75 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generator-ng2-webpack",
3 | "version": "0.6.7",
4 | "description": "An opinionated tool for scaffolding an app using angular2 and webpack",
5 | "homepage": "https://github.com/cmelion/generator-ng2-webpack",
6 | "repository": {
7 | "type": "git",
8 | "url": "git://github.com/cmelion/generator-ng2-webpack"
9 | },
10 | "engines": {
11 | "node": ">= 4.2.1 <= 5.6.0"
12 | },
13 | "scripts": {
14 | "eslint": "eslint .",
15 | "lint": "npm run eslint",
16 | "mocha": "istanbul cover --root ./generators --include-all-sources -x **/templates/** --dir ./coverage/mocha --report text --report text-summary --report lcov --print none _mocha -- test/mocha/**/*.spec.js --reporter spec --timeout 10000",
17 | "mocha:watch": "mocha test/mocha/**/*.spec.js -R nyan -w --timeout 10000",
18 | "pretest": "npm run eslint",
19 | "test": "npm run mocha",
20 | "release:full": "gulp release:full"
21 | },
22 | "author": {
23 | "name": "Charles Fulnecky",
24 | "email": "cfulnecky@gmail.com",
25 | "url": "https://github.com/cmelion"
26 | },
27 | "files": [
28 | "generators",
29 | "libs",
30 | ".jsbeautifyrc"
31 | ],
32 | "main": "generators/app/index.js",
33 | "preferGlobal": true,
34 | "keywords": [
35 | "angular 2",
36 | "angular",
37 | "angular2",
38 | "asyncroute",
39 | "boilerplate",
40 | "generator",
41 | "hot-loading",
42 | "hot-loader",
43 | "ng2",
44 | "react",
45 | "scaffold",
46 | "starter",
47 | "typescript",
48 | "webpack",
49 | "yeoman",
50 | "yeoman-generator"
51 | ],
52 | "license": "MIT",
53 | "dependencies": {
54 | "chalk": "^1.1.1",
55 | "gulp-filter": "^3.0.1",
56 | "gulp-tap": "0.1.3",
57 | "js-beautify": "beautify-web/js-beautify",
58 | "lodash": "3.10.1",
59 | "mkdirp": "^0.5.1",
60 | "repeating": "^2.0.0",
61 | "string-length": "^1.0.1",
62 | "strip-json-comments": "^2.0.1",
63 | "underscore.string": "^3.2.3",
64 | "update-notifier": "^0.6.0",
65 | "yeoman-generator": "^0.22.4",
66 | "yeoman-option-or-prompt": "^1.0.2",
67 | "yosay": "^1.1.0"
68 | },
69 | "devDependencies": {
70 | "bluebird": "^3.3.1",
71 | "chai": "^3.5.0",
72 | "chalk": "1.1.1",
73 | "coveralls": "^2.11.6",
74 | "del": "^2.2.0",
75 | "eslint": "^2.2.0",
76 | "eslint-plugin-nodeca": "^1.0.3",
77 | "event-stream": "^3.3.2",
78 | "github": "0.2.4",
79 | "github-username": "2.1.0",
80 | "gulp": "3.9.1",
81 | "gulp-bump": "1.0.0",
82 | "gulp-concat": "2.6.0",
83 | "gulp-exec": "2.1.2",
84 | "gulp-git": "^1.7.0",
85 | "gulp-help": "1.6.1",
86 | "gulp-if": "2.0.0",
87 | "gulp-order": "1.1.1",
88 | "gulp-util": "3.0.7",
89 | "inquirer": "^0.12.0",
90 | "istanbul": "^0.4.2",
91 | "mocha": "^2.4.5",
92 | "node-jsxml": "^0.7.0",
93 | "require-dir": "0.3.0",
94 | "run-sequence": "^1.1.5",
95 | "yargs": "^4.1.0",
96 | "yeoman-assert": "^2.1.1",
97 | "yeoman-test": "^1.1.0"
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/generators/component/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var path = require('path');
3 | var ComponentGenerator = require('../componentGenerator');
4 | var Generator = module.exports = ComponentGenerator.extend({
5 |
6 | constructor: function() {
7 | this.basetype = 'component'; // this will create a property this.componentname
8 | this.basefolder = 'components'; // this is the folder for the components
9 | this.hasOwnFolder = true; // to specify if the component files should be in a subfolder
10 | this.isDasherize = true; // to specify that the file name should be dasherized
11 | ComponentGenerator.apply(this, arguments);
12 |
13 | this.option('targettype', {
14 | desc: 'The type of target',
15 | type: String,
16 | hide: false
17 | });
18 | },
19 |
20 | initializing: function() {
21 | Generator.__super__.initializing.apply(this, arguments);
22 | this.mixins.beautifyTs();
23 | },
24 |
25 | prompting: function() {
26 | var done = this.async();
27 | var self = this;
28 | var extraPrompts = [{
29 | type: 'list',
30 | name: 'targettype',
31 | default: 'web',
32 | when: function() {
33 | return !self.options.targettype || self.options.targettype.length <= 0;
34 | },
35 | message: 'What type of component do you want to create?',
36 | choices: ['web']
37 | }];
38 | Generator.__super__.prompting.call(this, done, extraPrompts);
39 |
40 | },
41 |
42 | configuring: function() {
43 | Generator.__super__.configuring.apply(this, arguments);
44 | this.targettype = this.answers.targettype || this.options.targettype;
45 | },
46 |
47 | writing: function() {
48 | var destinationPath = Generator.__super__.writing.apply(this, arguments);
49 | //var componentnameFile = this.componentname; //this.mixins.dasherize(this.componentname); // could be componentname
50 |
51 | switch (this.targettype) {
52 | case 'web':
53 | this.fs.copyTpl(
54 | this.templatePath('_component.ts'),
55 | this.destinationPath(path.join(destinationPath, 'index.ts')), {
56 | componentnameFile: this.componentnameFile,
57 | componentname: this.componentname,
58 | componentnameClass: this.componentnameClass
59 | }
60 | );
61 |
62 | this.fs.copyTpl(
63 | this.templatePath('_component.spec.ts'),
64 | this.destinationPath(path.join(destinationPath, 'spec.ts')), {
65 | componentnameFile: this.componentnameFile,
66 | componentname: this.componentname,
67 | componentnameClass: this.componentnameClass,
68 | assertPath: path.relative(path.join(destinationPath, 'spec.ts'), path.join('src','app', 'assert')).replace(/\\/g,'/')
69 | }
70 | );
71 |
72 | this.fs.copyTpl(
73 | this.templatePath('_component.html'),
74 | this.destinationPath(path.join(destinationPath, 'template.html')), {
75 | componentname: this.componentname
76 | }
77 | );
78 | this.fs.copyTpl(
79 | this.templatePath('_component.scss'),
80 | this.destinationPath(path.join(destinationPath, 'style.scss'))
81 | );
82 | break;
83 | }
84 |
85 | }
86 |
87 | });
88 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "amd": true,
4 | "browser": true,
5 | "mocha": true,
6 | "es6": true,
7 | "jasmine": true,
8 | "node": true
9 | },
10 | "globals": {
11 | "assert": true,
12 | "browser": true,
13 | "expect": true,
14 | "by": true,
15 | "protractor": true,
16 | "sinon": true,
17 | "xdescribe": true,
18 | "xit": true
19 | },
20 | "plugins": [
21 | "nodeca"
22 | ],
23 | "rules": {
24 | "comma-dangle": [2, "never"],
25 | "camelcase": 0,
26 | "complexity": [0, 11],
27 | "consistent-return": 2,
28 | "consistent-this": [1, "self"],
29 | "curly": [2, "all"],
30 | "dot-notation": 2,
31 | "eol-last": 0,
32 | "eqeqeq": [2, "smart"],
33 | "indent": [0, 1, {"SwitchCase": 1}],
34 | "keyword-spacing": [2, {"before": true, "after": true, "overrides": {}}],
35 | "nodeca/indent": [2, "spaces", 4 ],
36 | "max-depth": [0, 4],
37 | "max-len": [0, 80, 4],
38 | "max-nested-callbacks": [0, 2],
39 | "max-params": [0, 15],
40 | "max-statements": [0, 10],
41 | "new-cap": [0],
42 | "new-parens": 2,
43 | "no-alert": 2,
44 | "no-array-constructor": 2,
45 | "no-caller": 2,
46 | "no-catch-shadow": 2,
47 | "no-cond-assign": 2,
48 | "no-console": 2,
49 | "no-constant-condition": 2,
50 | "no-control-regex": 2,
51 | "no-debugger": 2,
52 | "no-delete-var": 2,
53 | "no-dupe-keys": 2,
54 | "no-empty": 0,
55 | "no-empty-character-class": 2,
56 | "no-labels": 2,
57 | "no-ex-assign": 2,
58 | "no-extend-native": 2,
59 | "no-extra-boolean-cast": 2,
60 | "no-extra-parens": 1,
61 | "no-extra-semi": 2,
62 | "no-fallthrough": 2,
63 | "no-func-assign": 2,
64 | "no-implied-eval": 2,
65 | "no-invalid-regexp": 2,
66 | "no-iterator": 2,
67 | "no-label-var": 2,
68 | "no-labels": 2,
69 | "no-lone-blocks": 2,
70 | "no-lonely-if": 0,
71 | "no-loop-func": 2,
72 | "no-mixed-spaces-and-tabs": [2, true],
73 | "no-multi-str": 2,
74 | "no-multiple-empty-lines": [2, {"max": 1}],
75 | "no-native-reassign": 2,
76 | "no-negated-in-lhs": 2,
77 | "no-nested-ternary": 0,
78 | "no-new": 2,
79 | "no-new-func": 2,
80 | "no-new-object": 2,
81 | "no-new-require": 0,
82 | "no-new-wrappers": 2,
83 | "no-obj-calls": 2,
84 | "no-octal": 2,
85 | "no-octal-escape": 2,
86 | "no-path-concat": 2,
87 | "no-process-exit": 1,
88 | "no-proto": 2,
89 | "no-redeclare": 2,
90 | "no-regex-spaces": 2,
91 | "no-return-assign": 2,
92 | "no-script-url": 2,
93 | "no-sequences": 2,
94 | "no-shadow": 0,
95 | "no-shadow-restricted-names": 2,
96 | "no-spaced-func": 2,
97 | "no-sparse-arrays": 2,
98 | "no-sync": 0,
99 | "no-ternary": 0,
100 | "no-trailing-spaces": 2,
101 | "no-undef": 2,
102 | "no-undef-init": 2,
103 | "no-underscore-dangle": 0,
104 | "no-unreachable": 2,
105 | "no-unused-vars": [2, {"args": "none", "vars": "local"}],
106 | "no-use-before-define": 2,
107 | "no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
108 | "no-with": 2,
109 | "quotes": [2, "single"],
110 | "semi": 2,
111 | "semi-spacing": 2,
112 | "space-infix-ops": [2, {"int32Hint": false}],
113 | "strict": [2, "global"],
114 | "use-isnan": 2,
115 | "valid-jsdoc": [2, { "prefer": { "return": "returns" }, "requireReturn": false, "requireParamDescription": true }],
116 | "valid-typeof": 2,
117 | "wrap-iife": [2, "any"],
118 | "yoda": [2, "never", { "exceptRange": true }]
119 | }
120 | }
--------------------------------------------------------------------------------
/generators/app/templates/_eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "amd": true,
4 | "browser": true,
5 | "mocha": true,
6 | "es6": true,
7 | "jasmine": true,
8 | "node": true
9 | },
10 | "globals": {
11 | "assert": true,
12 | "browser": true,
13 | "expect": true,
14 | "protractor": true,
15 | "sinon": true,
16 | "xdescribe": true,
17 | "xit": true,
18 | "by": true,
19 | "element": true
20 | },
21 | "plugins": [
22 | "nodeca"
23 | ],
24 | "rules": {
25 | "comma-dangle": [2, "never"],
26 | "camelcase": 0,
27 | "complexity": [0, 11],
28 | "consistent-return": 2,
29 | "consistent-this": [1, "self"],
30 | "curly": [2, "all"],
31 | "dot-notation": 2,
32 | "eol-last": 0,
33 | "eqeqeq": [2, "smart"],
34 | "indent": [0, 4, {"SwitchCase": 1}],
35 | "new-cap": 0,
36 | "nodeca/indent": [2, "spaces", 4],
37 | "max-depth": [0, 4],
38 | "max-len": [0, 80, 4],
39 | "max-nested-callbacks": [0, 2],
40 | "max-params": [0, 15],
41 | "max-statements": [0, 10],
42 | "new-parens": 2,
43 | "no-alert": 2,
44 | "no-array-constructor": 2,
45 | "no-caller": 2,
46 | "no-catch-shadow": 0,
47 | "no-cond-assign": 2,
48 | "no-console": 2,
49 | "no-constant-condition": 2,
50 | "no-control-regex": 2,
51 | "no-debugger": 2,
52 | "no-delete-var": 2,
53 | "no-dupe-keys": 2,
54 | "no-empty": 0,
55 | "no-empty-character-class": 2,
56 | "no-empty-label": 2,
57 | "no-ex-assign": 2,
58 | "no-extend-native": 2,
59 | "no-extra-boolean-cast": 2,
60 | "no-extra-parens": 1,
61 | "no-extra-semi": 2,
62 | "no-fallthrough": 2,
63 | "no-func-assign": 2,
64 | "no-implied-eval": 2,
65 | "no-invalid-regexp": 2,
66 | "no-iterator": 2,
67 | "no-label-var": 2,
68 | "no-labels": 2,
69 | "no-lone-blocks": 2,
70 | "no-lonely-if": 0,
71 | "no-loop-func": 2,
72 | "no-mixed-spaces-and-tabs": [2, true],
73 | "no-multi-str": 2,
74 | "no-multiple-empty-lines": [2, {"max": 1}],
75 | "no-native-reassign": 2,
76 | "no-negated-in-lhs": 2,
77 | "no-nested-ternary": 0,
78 | "no-new": 2,
79 | "no-new-func": 2,
80 | "no-new-object": 2,
81 | "no-new-require": 0,
82 | "no-new-wrappers": 2,
83 | "no-obj-calls": 2,
84 | "no-octal": 2,
85 | "no-octal-escape": 2,
86 | "no-path-concat": 2,
87 | "no-process-exit": 1,
88 | "no-proto": 2,
89 | "no-redeclare": 2,
90 | "no-regex-spaces": 2,
91 | "no-return-assign": 2,
92 | "no-script-url": 2,
93 | "no-sequences": 2,
94 | "no-shadow": 0,
95 | "no-shadow-restricted-names": 2,
96 | "no-spaced-func": 2,
97 | "no-sparse-arrays": 2,
98 | "no-sync": 0,
99 | "no-ternary": 0,
100 | "no-trailing-spaces": 2,
101 | "no-undef": 2,
102 | "no-undef-init": 2,
103 | "no-underscore-dangle": 0,
104 | "no-unreachable": 2,
105 | "no-unused-vars": [2, {"args": "none", "vars": "local"}],
106 | "no-use-before-define": 2,
107 | "no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
108 | "no-with": 2,
109 | "quotes": [2, "single"],
110 | "semi": 2,
111 | "semi-spacing": 2,
112 | "space-after-keywords": [2, "always"],
113 | "space-infix-ops": [2, {"int32Hint": false}],
114 | "strict": [2, "global"],
115 | "use-isnan": 2,
116 | "valid-jsdoc": [2, { "prefer": { "return": "returns" }, "requireReturn": false, "requireParamDescription": true }],
117 | "valid-typeof": 2,
118 | "wrap-iife": [2, "any"],
119 | "yoda": [2, "never", { "exceptRange": true }]
120 | }
121 | }
--------------------------------------------------------------------------------
/libs/mixinInspector.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var path = require('path');
3 | var fs = require('fs');
4 | var _ = require('lodash');
5 | var utils = {};
6 | require('./mixinFile').extend(utils);
7 |
8 | /**
9 | * Returns this generator full name so we can change it in package.json without altering the code
10 | * @returns {String} The generator full name
11 | */
12 | var getGeneratorFullname = function() {
13 | var pkg = require('../package.json');
14 | return pkg.name;
15 | };
16 |
17 | /**
18 | * Returns this generator short name (without generator) so we can change it in package.json without altering the code
19 | * @returns {String} The generator short name
20 | */
21 | var getGeneratorShortname = function() {
22 | var pkg = require('../package.json');
23 | return pkg.name.replace('generator-', '');
24 | };
25 |
26 | /**
27 | * Return the list of client targets
28 | * @param {String} clientFolder - The client folder
29 | * @returns {String[]} - An array of client targets
30 | */
31 | var getClientTargets = function(clientFolder) {
32 | if (!clientFolder) {
33 | return [];
34 | }
35 | var pathdir = this.destinationPath(path.join(clientFolder, 'app'));
36 | if (!fs.existsSync(pathdir)) {
37 | return [];
38 | }
39 | //var re = /^(index-.*\.html|index\.html)$/;
40 |
41 | var result = fs.readdirSync(pathdir)
42 | .filter(function(file) {
43 | return fs.statSync(path.join(pathdir, file)).isDirectory() === true && utils.mixins.fileExistsSync(path.join(pathdir, file, 'index.html'));
44 | })
45 | .map(function(name) {
46 | var appname = path.basename(name, '.html');
47 | appname = appname === 'index' ? 'app' : _(appname.split('-')).last();
48 | return appname;
49 | });
50 | return result;
51 | };
52 |
53 | /**
54 | * Return the list of angularjs client modules
55 | * @param {String} clientFolder - The client folder
56 | * @param {String} moduleName - the module folder
57 | * @returns {String[]} - An array of client modules
58 | */
59 | var getClientModules = function(clientFolder, moduleName) {
60 | var results = [];
61 | var charCountToIgnore = 'src/app/components/'.length;
62 |
63 | moduleName = moduleName || 'app';
64 |
65 | if (!clientFolder) {
66 | return [];
67 | }
68 | var pathString = path.join(clientFolder, moduleName, 'components');
69 | var pathdir = this.destinationPath(pathString);
70 |
71 | if (!fs.existsSync(pathdir)) {
72 | return [];
73 | }
74 |
75 | var result = fs.readdirSync(pathdir)
76 | .filter(function(file) {
77 | return fs.statSync(path.join(pathString, file)).isDirectory() === true;
78 | });
79 |
80 | result.forEach(function(module) {
81 | var includeSeparator = pathString.slice(charCountToIgnore).length > 0;
82 | results.push(path.join(pathString.slice(charCountToIgnore), includeSeparator ? '/' : '' , module));
83 | results = results.concat(getClientModules.apply(this, [pathString, module]));
84 | }, this);
85 |
86 | if (moduleName === 'app') {
87 | results.push('app');
88 | }
89 |
90 | return results;
91 | };
92 |
93 | /**
94 | * Converts the target name application to suffix
95 | * @param {String} targetname - The name of the target application
96 | *
97 | * @returns {String} - The suffix name of the target application
98 | */
99 | var targetnameToSuffix = function(targetname) {
100 | return targetname === 'app' ? '' : 'app/components/' + targetname;
101 | };
102 |
103 | /**
104 | * The exported object
105 | * To apply the mixin execute: this.mixins.extend(generator);
106 | * @type {Object}
107 | */
108 | module.exports = {
109 | extend: function(generator) {
110 | var mixins = generator.mixins = generator.mixins || {};
111 | mixins.getGeneratorFullname = getGeneratorFullname.bind(generator);
112 | mixins.getGeneratorShortname = getGeneratorShortname.bind(generator);
113 | mixins.getClientTargets = getClientTargets.bind(generator);
114 | mixins.targetnameToSuffix = targetnameToSuffix.bind(generator);
115 | mixins.getClientModules = getClientModules.bind(generator);
116 | }
117 | };
118 |
--------------------------------------------------------------------------------
/generators/target/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var generators = require('yeoman-generator');
3 | var path = require('path');
4 | var mixinInspector = require('../../libs/mixinInspector');
5 | var mixinFile = require('../../libs/mixinFile');
6 | var mixinBeautify = require('../../libs/mixinBeautify');
7 | var mixinLodash = require('../../libs/mixinLodash');
8 |
9 | module.exports = generators.Base.extend({
10 |
11 | constructor: function() {
12 | generators.Base.apply(this, arguments);
13 |
14 | // applying mixins
15 | mixinInspector.extend(this);
16 | mixinFile.extend(this);
17 | mixinBeautify.extend(this);
18 | mixinLodash.extend(this);
19 |
20 | // Registering file transforms
21 | this.mixins.beautifyJson();
22 | this.mixins.beautifyHtml();
23 | this.mixins.beautifyTs();
24 |
25 | //******* arguments ***********
26 | // To access arguments later use this.argumentName
27 | this.argument('targetname', {
28 | desc: 'The target name',
29 | type: String,
30 | optional: true,
31 | required: false
32 | });
33 | // ***** arguments ********
34 |
35 | // // ****** options *********
36 | // To access options later use this.options.optionName
37 | this.option('clientFolder', {
38 | desc: 'The client folder',
39 | type: String,
40 | hide: true
41 | });
42 | // ****** options *********
43 | },
44 |
45 | initializing: function() {
46 | this.configOptions = this.config.getAll();
47 | this.configOptions.clientFolder = this.configOptions.clientFolder || this.options.clientFolder;
48 | this.configOptions.clientTargets = this.mixins.getClientTargets(this.configOptions.clientFolder);
49 |
50 | },
51 |
52 | prompting: function() {
53 | var done = this.async();
54 | var prompts = [];
55 | this.prompt(prompts, function(answers) {
56 | this.answers = answers;
57 | done();
58 | }.bind(this));
59 | },
60 |
61 | configuring: function() {
62 | },
63 |
64 | writing: function() {
65 |
66 | this.mixins.createDirSync(this.destinationPath(this.configOptions.clientFolder));
67 |
68 | this.fs.copyTpl(
69 | this.templatePath('vendor.ts'),
70 | this.destinationPath(path.join(this.configOptions.clientFolder, 'vendor.ts'))
71 | );
72 | this.fs.copyTpl(
73 | this.templatePath('bootstrap.ts'),
74 | this.destinationPath(path.join(this.configOptions.clientFolder, 'bootstrap.ts'))
75 | );
76 |
77 | this.fs.copyTpl(
78 | this.templatePath('public/index.template.html'),
79 | this.destinationPath(path.join(this.configOptions.clientFolder, 'public/index.html'))
80 | );
81 |
82 | this.fs.copy(
83 | this.templatePath('public/service-worker.js'),
84 | this.destinationPath(path.join(this.configOptions.clientFolder, 'public/service-worker.js'))
85 | );
86 |
87 | this.fs.copy(
88 | this.templatePath('public/img/favicon.ico'),
89 | this.destinationPath(path.join(this.configOptions.clientFolder, 'public/img/favicon.ico'))
90 | );
91 |
92 | this.fs.copy(
93 | this.templatePath('public/img/shield-with-beta.png'),
94 | this.destinationPath(path.join(this.configOptions.clientFolder, 'public/img/shield-with-beta.png'))
95 | );
96 |
97 | this.fs.copy(
98 | this.templatePath('app'),
99 | this.destinationPath(path.join(this.configOptions.clientFolder, 'app'))
100 | );
101 |
102 | this.fs.copy(
103 | this.templatePath('shims'),
104 | this.destinationPath(path.join(this.configOptions.clientFolder, 'shims'))
105 | );
106 |
107 | this.fs.copy(
108 | this.templatePath('style'),
109 | this.destinationPath(path.join(this.configOptions.clientFolder, 'style'))
110 | );
111 |
112 | this.fs.copy(
113 | this.templatePath('assert'),
114 | this.destinationPath(path.join(this.configOptions.clientFolder, 'assert'))
115 | );
116 | }
117 | });
118 |
--------------------------------------------------------------------------------
/generators/componentGenerator.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var generators = require('yeoman-generator');
3 | var path = require('path');
4 | var mixinInspector = require('../libs/mixinInspector');
5 | var mixinFile = require('../libs/mixinFile');
6 | var mixinBeautify = require('../libs/mixinBeautify');
7 | var mixinLodash = require('../libs/mixinLodash');
8 | module.exports = generators.Base.extend({
9 | constructor: function() {
10 | generators.Base.apply(this, arguments);
11 | if (!this.basetype) {
12 | throw 'basetype is undefined';
13 | }
14 | if (!this.basefolder) {
15 | throw 'basefolder is undefined';
16 | }
17 |
18 | // applying mixins
19 | mixinInspector.extend(this);
20 | mixinFile.extend(this);
21 | mixinBeautify.extend(this);
22 | mixinLodash.extend(this);
23 |
24 | // Registering file transforms
25 | this.mixins.beautifyJson();
26 | this.mixins.beautifyHtml();
27 | this.mixins.beautifyTs();
28 | this.mixins.beautifyCss();
29 |
30 | //******* arguments ***********
31 | // To access arguments later use this.argumentName
32 | this.argument('modulename', {
33 | desc: 'The module name',
34 | type: String,
35 | optional: true,
36 | required: false
37 | });
38 | this.modulename = this.mixins.camelize(this.modulename);
39 |
40 | this.argument(this.basetype + 'name', {
41 | desc: 'The ' + this.basetype + ' name',
42 | type: String,
43 | optional: true,
44 | required: false
45 | });
46 | this[this.basetype + 'name'] = this.mixins.camelize(this[this.basetype + 'name']);
47 | // ***** arguments ********
48 |
49 | },
50 |
51 | initializing: function() {
52 | this.configOptions = this.config.getAll();
53 | this.configOptions.clientTargets = this.mixins.getClientTargets(this.configOptions.clientFolder);
54 | this.configOptions.clientModules = this.mixins.getClientModules(this.configOptions.clientFolder);
55 | },
56 |
57 | prompting: function(done, extraPrompts) {
58 | done = done || this.async();
59 | var self = this;
60 | extraPrompts = extraPrompts || [];
61 | var prompts = [{
62 | type: 'list',
63 | name: 'modulename',
64 | choices: this.configOptions.clientModules,
65 | message: 'In which feature would you like to store your ' + self.basetype + '?',
66 | when: function() {
67 | return !self.modulename || self.modulename.length <= 0;
68 | }
69 | }, {
70 | type: 'input',
71 | name: self.basetype + 'name',
72 | message: 'How would you like to name your ' + self.basetype + '?',
73 | when: function() {
74 | return !self[self.basetype + 'name'] || self[self.basetype + 'name'].length <= 0;
75 | }
76 | }].concat(extraPrompts);
77 |
78 | this.prompt(prompts, function(answers) {
79 | this.answers = answers;
80 | // To access props later use this.answers.someOption;
81 | done();
82 | }.bind(this));
83 |
84 | },
85 |
86 | configuring: function() {
87 | this.modulename = this.modulename || this.answers.modulename;
88 | this[this.basetype + 'name'] = this.mixins.camelize(this[this.basetype + 'name'] || this.answers[this.basetype + 'name']);
89 | this[this.basetype + 'nameFile'] = this.isDasherize ? this.mixins.dasherize(this[this.basetype + 'name']) : this[this.basetype + 'name'];
90 | this[this.basetype + 'nameClass'] = this.mixins.classify(this[this.basetype + 'name']);
91 | },
92 |
93 | writing: function() {
94 | var modulename = this.modulename === 'app' ? this.modulename : path.join('app', 'components', this.modulename);
95 | var destinationPath = path.join(this.configOptions.clientFolder, modulename, this.basefolder);
96 | if (this.hasOwnFolder) {
97 | destinationPath = path.join(destinationPath, this[this.basetype + 'nameFile']);
98 | }
99 | this.mixins.createDirSync(destinationPath);
100 | return destinationPath;
101 | }
102 |
103 | });
104 |
--------------------------------------------------------------------------------
/generators/app/templates/_package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "app",
3 | "version": "0.0.0",
4 | "license": "MIT",
5 | "scripts": {
6 | "build": "rimraf dist && webpack --progress --profile --colors --display-error-details --display-cached --optimize-occurence-order --optimize-minimize --optimize-dedupe",
7 | "ci": "npm run e2e && npm run test",
8 | "clean": "rimraf node_modules doc dist && npm cache clean",
9 | "clean-install": "npm run clean && npm install",
10 | "clean-start": "npm run clean && npm start",
11 | "client": "concurrently \"npm run docker-client\" \"npm run delayed-open\"",
12 | "delayed-open": "sleep 5 && opener http://localhost:2368",
13 | "docker-client": "webpack-dev-server --host=0.0.0.0 --hot --inline --progress --port 2368 & wait",
14 | "docker-open-terminal": "docker exec -i ${PWD##*/} /bin/bash",
15 | "docker-server": "concurrently \"npm run server\" \"npm run docker-client\"",
16 | "docker-start": "docker-compose --p ${PWD##*/} up",
17 | "docker-stop": "docker-compose --p ${PWD##*/} stop",
18 | "docs": "typedoc --options typedoc.json src/app/app.ts",
19 | "e2e": "protractor",
20 | "e2e-live": "protractor --elementExplorer",
21 | "lint": "tsconfig-lint",
22 | "new-component": "yo ng2-webpack:component",
23 | "new-directive": "yo ng2-webpack:directive",
24 | "new-interface": "yo ng2-webpack:interface",
25 | "new-pipe": "yo ng2-webpack:pipe",
26 | "new-service": "yo ng2-webpack:service",
27 | "postinstall": "npm run webdriver-update && typings install",
28 | "predocker-server": "npm install --quiet",
29 | "predocker-start": "docker pull cmelion/generator-ng2-webpack:latest",
30 | "server": "json-server --watch json-server/db.json",
31 | "start": "concurrently \"npm run server\" \"npm run client\"",
32 | "test": "karma start",
33 | "test-watch": "karma start --no-single-run --auto-watch",
34 | "watch": "webpack --watch --progress --profile",
35 | "webdriver-start": "webdriver-manager start",
36 | "webdriver-update": "webdriver-manager update"
37 | },
38 | "dependencies": {
39 | "@angular/common": "2.0.0-rc.3",
40 | "@angular/compiler": "2.0.0-rc.3",
41 | "@angular/core": "2.0.0-rc.3",
42 | "@angular/http": "2.0.0-rc.3",
43 | "@angular/platform-browser": "2.0.0-rc.3",
44 | "@angular/platform-browser-dynamic": "2.0.0-rc.3",
45 | "@angular/router-deprecated": "2.0.0-rc.2",
46 | "@ngrx/store": "^1.5.0",
47 | "es6-shim": "^0.35.0",
48 | "es7-reflect-metadata": "1.6.0",
49 | "lodash": "^4.12.0",
50 | "react": "^0.14.7",
51 | "react-dom": "^0.14.7",
52 | "react-notification-system": "^0.2.6",
53 | "reflect-metadata": "0.1.3",
54 | "rxjs": "5.0.0-beta.6",
55 | "zone.js": "^0.6.12"
56 | },
57 | "devDependencies": {
58 | "autoprefixer": "^6.3.2",
59 | "copy-webpack-plugin": "^1.1.1",
60 | "concurrently": "^2.0.0",
61 | "css-loader": "^0.23.1",
62 | "es6-promise-loader": "^1.0.1",
63 | "exports-loader": "0.6.3",
64 | "expose-loader": "^0.7.1",
65 | "extract-text-webpack-plugin": "^1.0.1",
66 | "file-loader": "^0.8.5",
67 | "html-webpack-plugin": "^2.8.1",
68 | "imports-loader": "^0.6.5",
69 | "istanbul-instrumenter-loader": "^0.1.3",
70 | "jasmine-core": "^2.4.1",
71 | "json-loader": "^0.5.4",
72 | "json-server": "^0.8.12",
73 | "karma": "^0.13.22",
74 | "karma-coverage": "^0.5.2",
75 | "karma-jasmine": "^1.0.2",
76 | "karma-phantomjs-launcher": "^1.0.0",
77 | "karma-chrome-launcher": "^0.2.1",
78 | "karma-spec-reporter": "0.0.26",
79 | "karma-sourcemap-loader": "^0.3.7",
80 | "karma-story-reporter": "^0.3.1",
81 | "karma-webpack": "^1.7.0",
82 | "left-pad": "git://github.com/azer/left-pad.git#bff80e3ef0db0bfaba7698606c4f623433d14355",
83 | "node-sass": "^3.4.2",
84 | "null-loader": "git+https://github.com/webpack/null-loader.git",
85 | "opener": "^1.4.1",
86 | "phantomjs-polyfill": "0.0.2",
87 | "phantomjs-prebuilt": "^2.1.7",
88 | "postcss-loader": "^0.8.0",
89 | "protractor": "^3.3.0",
90 | "raw-loader": "0.5.1",
91 | "rimraf": "^2.5.2",
92 | "sass-loader": "^3.1.2",
93 | "style-loader": "^0.13.1",
94 | "system-sleep": "1.0.0-f",
95 | "ts-loader": "^0.8.2",
96 | "tsconfig-lint": "^0.11.0",
97 | "tslint": "^3.9.0",
98 | "tslint-loader": "^2.1.4",
99 | "ts-helpers": "^1.1.1",
100 | "typedoc": "^0.3.12",
101 | "typescript": "^1.8.10",
102 | "typings": "^0.8.1",
103 | "url-loader": "^0.5.7",
104 | "webpack": "^1.13.0",
105 | "webpack-dev-server": "^1.14.1",
106 | "webpack-hot-middleware": "^2.10.0",
107 | "webpack-load-plugins": "^0.1.2"
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/libs/mixinBeautify.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var filter = require('gulp-filter');
4 | var tap = require('gulp-tap');
5 | var beautify_js = require('js-beautify').js;
6 | var beautify_css = require('js-beautify').css;
7 | var beautify_html = require('js-beautify').html;
8 | var utils = {};
9 | require('./mixinFile').extend(utils);
10 | var beautifyConfig = utils.mixins.readJsonFile('../.jsbeautifyrc', __dirname);
11 |
12 | /**
13 | * Beautify a json stream
14 | * @param {Array} globs An optional array of globs
15 | */
16 | var beautifyJson = function(globs) {
17 | globs = [].concat(globs || ['**/*.json']);
18 | var extensionFilter = filter(globs, {
19 | restore: true
20 | });
21 | var config = beautifyConfig.js;
22 | config.indent_size = 2;
23 | config.max_preserve_newlines = 1;
24 | this.registerTransformStream([
25 | extensionFilter,
26 | tap(function(file, t) {
27 | var contents = file.contents.toString();
28 | contents = beautify_js(contents, config);
29 | file.contents = new Buffer(contents);
30 | }),
31 | //prettifyJs(config),
32 | extensionFilter.restore
33 | ]);
34 | };
35 |
36 | /**
37 | * Beautify a javascript stream
38 | * @param {Array} globs An optional array of globs
39 | */
40 | var beautifyJs = function(globs) {
41 | globs = [].concat(globs || ['**/*.js']);
42 | var extensionFilter = filter(globs, {
43 | restore: true
44 | });
45 | var config = beautifyConfig.js;
46 | config.indent_size = 4;
47 | config.max_preserve_newlines = 2;
48 | this.registerTransformStream([
49 | extensionFilter,
50 | //prettifyJs(config),
51 | tap(function(file, t) {
52 | var contents = file.contents.toString();
53 | contents = beautify_js(contents, config);
54 | file.contents = new Buffer(contents);
55 | }),
56 | extensionFilter.restore
57 | ]);
58 | };
59 |
60 | /**
61 | * Beautify a typescript stream
62 | * @param {Array} globs An optional array of globs
63 | */
64 | var beautifyTs = function(globs) {
65 | globs = [].concat(globs || ['**/*.ts']);
66 | var extensionFilter = filter(globs, {
67 | restore: true
68 | });
69 | var config = beautifyConfig.js;
70 | config.indent_size = 4;
71 | config.max_preserve_newlines = 2;
72 | this.registerTransformStream([
73 | extensionFilter,
74 | tap(function(file, t) {
75 | var contents = file.contents.toString();
76 | contents = beautify_js(contents, config);
77 | file.contents = new Buffer(contents);
78 | }),
79 | extensionFilter.restore
80 | ]);
81 | };
82 |
83 | /**
84 | * Beautify an html stream
85 | * @param {Array} globs An optional array of globs
86 | */
87 | var beautifyHtml = function(globs) {
88 | globs = [].concat(globs || ['**/*.html']);
89 | var extensionFilter = filter(globs, {
90 | restore: true
91 | });
92 | var config = beautifyConfig.html;
93 | config.max_preserve_newlines = 1;
94 | this.registerTransformStream([
95 | extensionFilter,
96 | tap(function(file, t) {
97 | var contents = file.contents.toString();
98 | contents = beautify_html(contents, config);
99 | file.contents = new Buffer(contents);
100 | }),
101 | extensionFilter.restore
102 | ]);
103 | };
104 |
105 | /**
106 | * Beautify an css stream
107 | * @param {Array} globs An optional array of globs
108 | */
109 | var beautifyCss = function(globs) {
110 | globs = [].concat(globs || ['**/*.css', '**/*.scss', '**/*.sass']);
111 | var extensionFilter = filter(globs, {
112 | restore: true
113 | });
114 | var config = beautifyConfig.css;
115 | config.max_preserve_newlines = 1;
116 | this.registerTransformStream([
117 | extensionFilter,
118 | tap(function(file, t) {
119 | var contents = file.contents.toString();
120 | contents = beautify_css(contents, config);
121 | file.contents = new Buffer(contents);
122 | }),
123 | extensionFilter.restore
124 | ]);
125 | };
126 |
127 | /**
128 | * The exported object
129 | * To apply the mixin execute: this.mixins.extend(generator);
130 | * @type {Object}
131 | */
132 | module.exports = {
133 | extend: function(generator) {
134 | var mixins = generator.mixins = generator.mixins || {};
135 | mixins.beautifyJson = beautifyJson.bind(generator);
136 | mixins.beautifyJs = beautifyJs.bind(generator);
137 | mixins.beautifyTs = beautifyTs.bind(generator);
138 | mixins.beautifyHtml = beautifyHtml.bind(generator);
139 | mixins.beautifyCss = beautifyCss.bind(generator);
140 | }
141 | };
142 |
--------------------------------------------------------------------------------
/generators/app/templates/typings/main/definitions/es6-promise/es6-promise.d.ts:
--------------------------------------------------------------------------------
1 | // Compiled using typings@0.6.8
2 | // Source: https://raw.githubusercontent.com/typed-typings/npm-es6-promise/fb04188767acfec1defd054fc8024fafa5cd4de7/dist/es6-promise.d.ts
3 | declare module 'es6-promise/dist/es6-promise' {
4 | export interface Thenable {
5 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable;
6 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable;
7 | }
8 |
9 | export class Promise implements Thenable {
10 | /**
11 | * If you call resolve in the body of the callback passed to the constructor,
12 | * your promise is fulfilled with result object passed to resolve.
13 | * If you call reject your promise is rejected with the object passed to resolve.
14 | * For consistency and debugging (eg stack traces), obj should be an instanceof Error.
15 | * Any errors thrown in the constructor callback will be implicitly passed to reject().
16 | */
17 | constructor (callback: (resolve : (value?: R | Thenable) => void, reject: (error?: any) => void) => void);
18 |
19 | /**
20 | * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
21 | * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
22 | * Both callbacks have a single parameter , the fulfillment value or rejection reason.
23 | * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
24 | * If an error is thrown in the callback, the returned promise rejects with that error.
25 | *
26 | * @param onFulfilled called when/if "promise" resolves
27 | * @param onRejected called when/if "promise" rejects
28 | */
29 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Promise;
30 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Promise;
31 |
32 | /**
33 | * Sugar for promise.then(undefined, onRejected)
34 | *
35 | * @param onRejected called when/if "promise" rejects
36 | */
37 | catch (onRejected?: (error: any) => U | Thenable): Promise;
38 |
39 | /**
40 | * Make a new promise from the thenable.
41 | * A thenable is promise-like in as far as it has a "then" method.
42 | */
43 | static resolve (): Promise;
44 | static resolve (value: R | Thenable): Promise;
45 |
46 | /**
47 | * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
48 | */
49 | static reject (error: any): Promise;
50 |
51 | /**
52 | * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
53 | * the array passed to all can be a mixture of promise-like objects and other objects.
54 | * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
55 | */
56 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable, T8 | Thenable, T9 | Thenable, T10 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
57 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable, T8 | Thenable, T9 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
58 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable, T8 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
59 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
60 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6]>;
61 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable]): Promise<[T1, T2, T3, T4, T5]>;
62 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable ]): Promise<[T1, T2, T3, T4]>;
63 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable]): Promise<[T1, T2, T3]>;
64 | static all(values: [T1 | Thenable, T2 | Thenable]): Promise<[T1, T2]>;
65 | static all(values: [T1 | Thenable]): Promise<[T1]>;
66 | static all(values: Array>): Promise;
67 |
68 | /**
69 | * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
70 | */
71 | static race (promises: (R | Thenable)[]): Promise;
72 | }
73 |
74 | /**
75 | * The polyfill method will patch the global environment (in this case to the Promise name) when called.
76 | */
77 | export function polyfill (): void;
78 | }
79 | declare module 'es6-promise' {
80 | export * from 'es6-promise/dist/es6-promise';
81 | }
--------------------------------------------------------------------------------
/generators/app/templates/typings/browser/definitions/es6-promise/es6-promise.d.ts:
--------------------------------------------------------------------------------
1 | // Compiled using typings@0.6.8
2 | // Source: https://raw.githubusercontent.com/typed-typings/npm-es6-promise/fb04188767acfec1defd054fc8024fafa5cd4de7/dist/es6-promise.d.ts
3 | declare module 'es6-promise/dist/es6-promise' {
4 | export interface Thenable {
5 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable;
6 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable;
7 | }
8 |
9 | export class Promise implements Thenable {
10 | /**
11 | * If you call resolve in the body of the callback passed to the constructor,
12 | * your promise is fulfilled with result object passed to resolve.
13 | * If you call reject your promise is rejected with the object passed to resolve.
14 | * For consistency and debugging (eg stack traces), obj should be an instanceof Error.
15 | * Any errors thrown in the constructor callback will be implicitly passed to reject().
16 | */
17 | constructor (callback: (resolve : (value?: R | Thenable) => void, reject: (error?: any) => void) => void);
18 |
19 | /**
20 | * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
21 | * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
22 | * Both callbacks have a single parameter , the fulfillment value or rejection reason.
23 | * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
24 | * If an error is thrown in the callback, the returned promise rejects with that error.
25 | *
26 | * @param onFulfilled called when/if "promise" resolves
27 | * @param onRejected called when/if "promise" rejects
28 | */
29 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Promise;
30 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Promise;
31 |
32 | /**
33 | * Sugar for promise.then(undefined, onRejected)
34 | *
35 | * @param onRejected called when/if "promise" rejects
36 | */
37 | catch (onRejected?: (error: any) => U | Thenable): Promise;
38 |
39 | /**
40 | * Make a new promise from the thenable.
41 | * A thenable is promise-like in as far as it has a "then" method.
42 | */
43 | static resolve (): Promise;
44 | static resolve (value: R | Thenable): Promise;
45 |
46 | /**
47 | * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
48 | */
49 | static reject (error: any): Promise;
50 |
51 | /**
52 | * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
53 | * the array passed to all can be a mixture of promise-like objects and other objects.
54 | * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
55 | */
56 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable, T8 | Thenable, T9 | Thenable, T10 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
57 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable, T8 | Thenable, T9 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
58 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable, T8 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
59 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable, T7 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
60 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable, T6 | Thenable]): Promise<[T1, T2, T3, T4, T5, T6]>;
61 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable , T5 | Thenable]): Promise<[T1, T2, T3, T4, T5]>;
62 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable, T4 | Thenable ]): Promise<[T1, T2, T3, T4]>;
63 | static all(values: [T1 | Thenable, T2 | Thenable, T3 | Thenable]): Promise<[T1, T2, T3]>;
64 | static all(values: [T1 | Thenable, T2 | Thenable]): Promise<[T1, T2]>;
65 | static all(values: [T1 | Thenable]): Promise<[T1]>;
66 | static all(values: Array>): Promise;
67 |
68 | /**
69 | * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
70 | */
71 | static race