Skip to content

Commit a47c8e3

Browse files
delastevedevCrossNet
authored andcommitted
chore(generator): Update template barrels to use 'export *'
Close angular#863 removed pwa option added custom serve task universal serve alpha changed ember-cli-live-reload to inline script. live reload works now with universal-serve
1 parent 17e09d7 commit a47c8e3

File tree

15 files changed

+482
-31
lines changed

15 files changed

+482
-31
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component';
1+
export * from './<%= dasherizedModuleName %>.component';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive';
1+
export * from './<%= dasherizedModuleName %>.directive';

addon/ng2/blueprints/ng2/files/__path__/index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
<base href="/">
77

88
{{#unless environment.production}}
9-
<script src="/ember-cli-live-reload.js" type="text/javascript"></script>
9+
<script type="text/javascript">
10+
(function() {
11+
var src = (location.protocol || 'http:') + '//' + (location.hostname || 'localhost') + ':49153/livereload.js?snipver=1';
12+
var script = document.createElement('script');
13+
script.type = 'text/javascript';
14+
script.src = src;
15+
document.getElementsByTagName('head')[0].appendChild(script);
16+
}());
17+
</script>
1018
{{/unless}}
1119
<meta name="viewport" content="width=device-width, initial-scale=1">
12-
<link rel="icon" type="image/x-icon" href="favicon.ico"><% if (isMobile || pwa) { %>
20+
<link rel="icon" type="image/x-icon" href="favicon.ico"><% if (isMobile) { %>
1321
<meta name="apple-mobile-web-app-capable" content="yes">
1422
<meta name="theme-color" content="#000000">
1523
<link rel="manifest" href="/manifest.webapp">

addon/ng2/blueprints/ng2/files/angular-cli.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"main": "<%= sourceDir %>/start-browser.ts",
99
"tsconfig": "<%= sourceDir %>/tsconfig.json",
1010
"mobile": <%= isMobile %>,
11-
"universal" : <%= universal %>,
12-
"pwa": <%= pwa %>
11+
"universal" : <%= universal %>
1312
}
1413
],
1514
"addons": [],

addon/ng2/blueprints/ng2/files/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
"angular2-universal-polyfills": "^0.4.1",
2727
"preboot": "^2.0.10",
2828
"body-parser": "^1.15.0",
29-
"express": "^4.13.4",<% } %><% if(pwa) { %>
30-
"@angular/service-worker": "^0.2.0",
31-
"@angular/app-shell": "^0.0.0",<% } %>
29+
"express": "^4.13.4",<% } %>
3230
"es6-shim": "^0.35.0",
3331
"reflect-metadata": "0.1.3",
3432
"rxjs": "5.0.0-beta.6",

addon/ng2/blueprints/ng2/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ module.exports = {
1111
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
1212
{ name: 'style', type: String, default: 'css' },
1313
{ name: 'mobile', type: Boolean, default: false },
14-
{ name: 'universal', type: Boolean, default: false },
15-
{ name: 'pwa', type: Boolean, default: false }
14+
{ name: 'universal', type: Boolean, default: false }
1615
],
1716

1817
afterInstall: function (options) {
@@ -43,8 +42,7 @@ module.exports = {
4342
styleExt: this.styleExt,
4443
refToTypings: refToTypings,
4544
isMobile: options.mobile,
46-
universal: options.universal,
47-
pwa: options.pwa
45+
universal: options.universal
4846
};
4947
},
5048

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.pipe';
1+
export * from './<%= dasherizedModuleName %>.pipe';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {<%= classifiedModuleName %>Service} from './<%= dasherizedModuleName %>.service';
1+
export * from './<%= dasherizedModuleName %>.service';

addon/ng2/blueprints/universal/files/__path__/start-node.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,4 @@ function ngApp(req, res) {
140140
*/
141141
app.get('/**', ngApp);
142142

143-
/**
144-
* start server
145-
*/
146-
app.listen(4200, () => {
147-
console.log('Listen on http://localhost:4200');
148-
});
143+
module.exports = app;

addon/ng2/commands/init.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ module.exports = Command.extend({
2626
{ name: 'style', type: String, default: 'css' },
2727
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
2828
{ name: 'mobile', type: Boolean, default: false },
29-
{ name: 'universal', type: Boolean, default: false },
30-
{ name: 'pwa', type: Boolean, default: false }
29+
{ name: 'universal', type: Boolean, default: false }
3130
],
3231

3332
anonymousOptions: ['<glob-pattern>'],
@@ -106,8 +105,7 @@ module.exports = Command.extend({
106105
style: commandOptions.style,
107106
prefix: commandOptions.prefix,
108107
mobile: commandOptions.mobile,
109-
universal: commandOptions.universal,
110-
pwa: commandOptions.pwa
108+
universal: commandOptions.universal
111109
};
112110

113111
if (!validProjectName(packageName)) {

addon/ng2/commands/new.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ const NewCommand = Command.extend({
2525
{ name: 'style', type: String, default: 'css' },
2626
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
2727
{ name: 'mobile', type: Boolean, default: false },
28-
{ name: 'universal', type: Boolean, default: false },
29-
{ name: 'pwa', type: Boolean, default: false }
28+
{ name: 'universal', type: Boolean, default: false }
3029
],
3130

3231
run: function (commandOptions, rawArgs) {
@@ -60,10 +59,6 @@ const NewCommand = Command.extend({
6059
commandOptions.directory = packageName;
6160
}
6261

63-
if (commandOptions.pwa === true) {
64-
commandOptions.universal = true;
65-
}
66-
6762
const createAndStepIntoDirectory =
6863
new this.tasks.CreateAndStepIntoDirectory({ ui: this.ui, analytics: this.analytics });
6964

addon/ng2/commands/serve.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
'use strict';
2+
3+
var assign = require('lodash/assign');
4+
var Command = require('ember-cli/lib/models/command');
5+
var Promise = require('ember-cli/lib/ext/promise');
6+
var SilentError = require('silent-error');
7+
var PortFinder = require('portfinder');
8+
var win = require('ember-cli/lib/utilities/windows-admin');
9+
var EOL = require('os').EOL;
10+
var UniversalServe = require('../tasks/universal-serve');
11+
const config = require('../models/config');
12+
13+
PortFinder.basePort = 49152;
14+
15+
var getPort = Promise.denodeify(PortFinder.getPort);
16+
var defaultPort = process.env.PORT || 4200;
17+
18+
const NewCommand = Command.extend({
19+
name: 'serve',
20+
description: 'Builds and serves your app, rebuilding on file changes.',
21+
aliases: ['server', 's'],
22+
23+
availableOptions: [
24+
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
25+
{ name: 'host', type: String, aliases: ['H'], description: 'Listens on all interfaces by default' },
26+
{ name: 'proxy', type: String, aliases: ['pr', 'pxy'] },
27+
{
28+
name: 'insecure-proxy',
29+
type: Boolean,
30+
default: false,
31+
aliases: ['inspr'],
32+
description: 'Set false to proxy self-signed SSL certificates'
33+
},
34+
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
35+
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
36+
{ name: 'live-reload-host', type: String, aliases: ['lrh'], description: 'Defaults to host' },
37+
{ name: 'live-reload-base-url', type: String, aliases: ['lrbu'], description: 'Defaults to baseURL' },
38+
{
39+
name: 'live-reload-port',
40+
type: Number,
41+
aliases: ['lrp'],
42+
description: '(Defaults to port number within [49152...65535])'
43+
},
44+
{
45+
name: 'environment',
46+
type: String,
47+
default: 'development',
48+
aliases: ['e', { 'dev': 'development' }, { 'prod': 'production' }]
49+
},
50+
{ name: 'output-path', type: 'Path', default: 'dist/', aliases: ['op', 'out'] },
51+
{ name: 'ssl', type: Boolean, default: false },
52+
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
53+
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' }
54+
],
55+
56+
run: function (commandOptions) {
57+
this.project.ngConfig = this.project.ngConfig || config.CliConfig.fromProject();
58+
commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;
59+
60+
return this._checkExpressPort(commandOptions)
61+
.then(this._autoFindLiveReloadPort.bind(this))
62+
.then(function (commandOptions) {
63+
var serve;
64+
commandOptions = assign({}, commandOptions, {
65+
baseURL: this.project.config(commandOptions.environment).baseURL || '/'
66+
});
67+
68+
if (commandOptions.proxy) {
69+
if (!commandOptions.proxy.match(/^(http:|https:)/)) {
70+
var message = 'You need to include a protocol with the proxy URL.' + EOL + 'Try --proxy http://' + commandOptions.proxy;
71+
72+
return Promise.reject(new SilentError(message));
73+
}
74+
}
75+
76+
if (this.project.ngConfig.apps[0].universal === false) {
77+
var ServeTask = this.tasks.Serve;
78+
serve = new ServeTask({
79+
ui: this.ui,
80+
analytics: this.analytics,
81+
project: this.project
82+
});
83+
} else {
84+
serve = new UniversalServe({
85+
ui: this.ui,
86+
analytics: this.analytics,
87+
project: this.project
88+
});
89+
}
90+
91+
return win.checkWindowsElevation(this.ui).then(function () {
92+
return serve.run(commandOptions);
93+
});
94+
}.bind(this));
95+
},
96+
97+
_checkExpressPort: function (commandOptions) {
98+
return getPort({ port: commandOptions.port, host: commandOptions.host })
99+
.then(function (foundPort) {
100+
101+
if (commandOptions.port !== foundPort && commandOptions.port !== 0) {
102+
var message = 'Port ' + commandOptions.port + ' is already in use.';
103+
return Promise.reject(new SilentError(message));
104+
}
105+
106+
// otherwise, our found port is good
107+
commandOptions.port = foundPort;
108+
return commandOptions;
109+
110+
}.bind(this));
111+
},
112+
113+
_autoFindLiveReloadPort: function (commandOptions) {
114+
return getPort({ port: commandOptions.liveReloadPort, host: commandOptions.liveReloadHost })
115+
.then(function (foundPort) {
116+
117+
// if live reload port matches express port, try one higher
118+
if (foundPort === commandOptions.port) {
119+
commandOptions.liveReloadPort = foundPort + 1;
120+
return this._autoFindLiveReloadPort(commandOptions);
121+
}
122+
123+
// port was already open
124+
if (foundPort === commandOptions.liveReloadPort) {
125+
return commandOptions;
126+
}
127+
128+
// use found port as live reload port
129+
commandOptions.liveReloadPort = foundPort;
130+
return commandOptions;
131+
132+
}.bind(this));
133+
}
134+
});
135+
136+
module.exports = NewCommand;
137+
module.exports.overrideCore = true;

addon/ng2/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212

1313
includedCommands: function () {
1414
return {
15+
'serve': require('./commands/serve'),
1516
'new': require('./commands/new'),
1617
'generate': require('./commands/generate'),
1718
'init': require('./commands/init'),

0 commit comments

Comments
 (0)