Skip to content

Commit de9b1ac

Browse files
committed
feature: add mobile option on ng new
Fixes #596.
1 parent f08cb64 commit de9b1ac

File tree

7 files changed

+65
-10
lines changed

7 files changed

+65
-10
lines changed
5.47 KB
Loading

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<title><%= jsComponentName %></title>
66
<base href="/">
77
{{content-for 'head'}}
8-
<link rel="icon" type="image/x-icon" href="favicon.ico">
8+
<link rel="icon" type="image/x-icon" href="favicon.ico"><% if (isMobile) { %>
9+
<link rel="manifest" href="/manifest.webapp"><% } %>
910

1011
<!-- Service worker support is disabled by default.
1112
Install the worker script and uncomment to enable.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "<%= fullAppName %>",
3+
"icons": [
4+
{
5+
"src": "icon.png",
6+
"sizes": "96x96",
7+
"type": "image/png"
8+
}
9+
],
10+
"start_url": "/index.html",
11+
"display": "standalone",
12+
"orientation": "portrait"
13+
}

addon/ng2/blueprints/ng2/index.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const Blueprint = require('ember-cli/lib/models/blueprint');
12
const path = require('path');
23
const stringUtils = require('ember-cli-string-utils');
34

@@ -6,27 +7,47 @@ module.exports = {
67

78
availableOptions: [
89
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
9-
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] }
10+
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
11+
{ name: 'mobile', type: Boolean, default: false }
1012
],
1113

1214
locals: function(options) {
1315
//TODO: pull value from config
1416
this.styleExt = 'css';
1517
this.version = require(path.resolve(__dirname, '..', '..', '..', '..', 'package.json')).version;
16-
18+
1719
// Join with / not path.sep as reference to typings require forward slashes.
1820
const refToTypings = options.sourceDir.split(path.sep).map(() => '..').join('/');
21+
const fullAppName = stringUtils.dasherize(options.entity.name)
22+
.replace(/-(.)/g, (_, l) => ' ' + l.toUpperCase())
23+
.replace(/^./, (l) => l.toUpperCase());
24+
1925
return {
2026
htmlComponentName: stringUtils.dasherize(options.entity.name),
2127
jsComponentName: stringUtils.classify(options.entity.name),
28+
fullAppName: fullAppName,
2229
styleExt: this.styleExt,
2330
version: this.version,
2431
sourceDir: options.sourceDir,
2532
prefix: options.prefix,
26-
refToTypings: refToTypings
33+
refToTypings: refToTypings,
34+
isMobile: options.mobile
2735
};
2836
},
29-
37+
38+
files: function() {
39+
var fileList = Blueprint.prototype.files.call(this);
40+
41+
if (this.options && !this.options.mobile) {
42+
fileList = fileList.filter(p => {
43+
return p != path.join('__path__', 'manifest.webapp')
44+
&& p != path.join('__path__', 'icon.png');
45+
});
46+
}
47+
48+
return fileList;
49+
},
50+
3051
fileMapTokens: function (options) {
3152
// Return custom template variables here.
3253
return {

addon/ng2/commands/init.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = Command.extend({
2121
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
2222
{ name: 'name', type: String, default: '', aliases: ['n'] },
2323
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
24-
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] }
24+
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
25+
{ name: 'mobile', type: Boolean, default: false }
2526
],
2627

2728
anonymousOptions: ['<glob-pattern>'],
@@ -89,7 +90,8 @@ module.exports = Command.extend({
8990
targetFiles: rawArgs || '',
9091
rawArgs: rawArgs.toString(),
9192
sourceDir: commandOptions.sourceDir,
92-
prefix: commandOptions.prefix
93+
prefix: commandOptions.prefix,
94+
mobile: commandOptions.mobile
9395
};
9496

9597
if (!validProjectName(packageName)) {

addon/ng2/commands/new.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const NewCommand = Command.extend({
2121
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
2222
{ name: 'directory', type: String, aliases: ['dir'] },
2323
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
24-
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] }
24+
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
25+
{ name: 'mobile', type: Boolean, default: false }
2526
],
2627

2728
run: function (commandOptions, rawArgs) {

tests/acceptance/init.spec.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var conf = require('ember-cli/tests/helpers/conf');
1313
var minimatch = require('minimatch');
1414
var intersect = require('lodash/intersection');
1515
var remove = require('lodash/remove');
16+
var pull = require('lodash/pull');
1617
var forEach = require('lodash/forEach');
1718
var any = require('lodash/some');
1819
var EOL = require('os').EOL;
@@ -31,7 +32,12 @@ describe('Acceptance: ng init', function () {
3132
});
3233

3334
beforeEach(function () {
34-
Blueprint.ignoredFiles = defaultIgnoredFiles;
35+
// Make a copy of defaultIgnoredFiles.
36+
Blueprint.ignoredFiles = defaultIgnoredFiles.splice(0);
37+
38+
// Add the mobile ones.
39+
Blueprint.ignoredFiles.push('manifest.webapp');
40+
Blueprint.ignoredFiles.push('icon.png');
3541

3642
return tmp.setup('./tmp').then(function () {
3743
process.chdir('./tmp');
@@ -103,6 +109,18 @@ describe('Acceptance: ng init', function () {
103109
]).then(confirmBlueprinted);
104110
});
105111

112+
it('ng init --mobile', () => {
113+
// Add the mobile ones.
114+
pull(Blueprint.ignoredFiles, 'manifest.webapp');
115+
pull(Blueprint.ignoredFiles, 'icon.png');
116+
return ng([
117+
'init',
118+
'--skip-npm',
119+
'--skip-bower',
120+
'--mobile'
121+
]).then(confirmBlueprinted);
122+
});
123+
106124
it('ng init can run in created folder', function () {
107125
return tmp.setup('./tmp/foo')
108126
.then(function () {
@@ -183,5 +201,4 @@ describe('Acceptance: ng init', function () {
183201
})
184202
.then(confirmBlueprinted);
185203
});
186-
187204
});

0 commit comments

Comments
 (0)