Skip to content

Commit

Permalink
feature: add mobile option on ng new
Browse files Browse the repository at this point in the history
Fixes #596.
  • Loading branch information
hansl committed May 2, 2016
1 parent f08cb64 commit de9b1ac
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
Binary file added addon/ng2/blueprints/ng2/files/__path__/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion addon/ng2/blueprints/ng2/files/__path__/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title><%= jsComponentName %></title>
<base href="/">
{{content-for 'head'}}
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="icon" type="image/x-icon" href="favicon.ico"><% if (isMobile) { %>
<link rel="manifest" href="/manifest.webapp"><% } %>

<!-- Service worker support is disabled by default.
Install the worker script and uncomment to enable.
Expand Down
13 changes: 13 additions & 0 deletions addon/ng2/blueprints/ng2/files/__path__/manifest.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "<%= fullAppName %>",
"icons": [
{
"src": "icon.png",
"sizes": "96x96",
"type": "image/png"
}
],
"start_url": "/index.html",
"display": "standalone",
"orientation": "portrait"
}
29 changes: 25 additions & 4 deletions addon/ng2/blueprints/ng2/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Blueprint = require('ember-cli/lib/models/blueprint');
const path = require('path');
const stringUtils = require('ember-cli-string-utils');

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

availableOptions: [
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] }
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'mobile', type: Boolean, default: false }
],

locals: function(options) {
//TODO: pull value from config
this.styleExt = 'css';
this.version = require(path.resolve(__dirname, '..', '..', '..', '..', 'package.json')).version;

// Join with / not path.sep as reference to typings require forward slashes.
const refToTypings = options.sourceDir.split(path.sep).map(() => '..').join('/');
const fullAppName = stringUtils.dasherize(options.entity.name)
.replace(/-(.)/g, (_, l) => ' ' + l.toUpperCase())
.replace(/^./, (l) => l.toUpperCase());

return {
htmlComponentName: stringUtils.dasherize(options.entity.name),
jsComponentName: stringUtils.classify(options.entity.name),
fullAppName: fullAppName,
styleExt: this.styleExt,
version: this.version,
sourceDir: options.sourceDir,
prefix: options.prefix,
refToTypings: refToTypings
refToTypings: refToTypings,
isMobile: options.mobile
};
},


files: function() {
var fileList = Blueprint.prototype.files.call(this);

if (this.options && !this.options.mobile) {
fileList = fileList.filter(p => {
return p != path.join('__path__', 'manifest.webapp')
&& p != path.join('__path__', 'icon.png');
});
}

return fileList;
},

fileMapTokens: function (options) {
// Return custom template variables here.
return {
Expand Down
6 changes: 4 additions & 2 deletions addon/ng2/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = Command.extend({
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
{ name: 'name', type: String, default: '', aliases: ['n'] },
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] }
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'mobile', type: Boolean, default: false }
],

anonymousOptions: ['<glob-pattern>'],
Expand Down Expand Up @@ -89,7 +90,8 @@ module.exports = Command.extend({
targetFiles: rawArgs || '',
rawArgs: rawArgs.toString(),
sourceDir: commandOptions.sourceDir,
prefix: commandOptions.prefix
prefix: commandOptions.prefix,
mobile: commandOptions.mobile
};

if (!validProjectName(packageName)) {
Expand Down
3 changes: 2 additions & 1 deletion addon/ng2/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const NewCommand = Command.extend({
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'directory', type: String, aliases: ['dir'] },
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] }
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'mobile', type: Boolean, default: false }
],

run: function (commandOptions, rawArgs) {
Expand Down
21 changes: 19 additions & 2 deletions tests/acceptance/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var conf = require('ember-cli/tests/helpers/conf');
var minimatch = require('minimatch');
var intersect = require('lodash/intersection');
var remove = require('lodash/remove');
var pull = require('lodash/pull');
var forEach = require('lodash/forEach');
var any = require('lodash/some');
var EOL = require('os').EOL;
Expand All @@ -31,7 +32,12 @@ describe('Acceptance: ng init', function () {
});

beforeEach(function () {
Blueprint.ignoredFiles = defaultIgnoredFiles;
// Make a copy of defaultIgnoredFiles.
Blueprint.ignoredFiles = defaultIgnoredFiles.splice(0);

// Add the mobile ones.
Blueprint.ignoredFiles.push('manifest.webapp');
Blueprint.ignoredFiles.push('icon.png');

return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
Expand Down Expand Up @@ -103,6 +109,18 @@ describe('Acceptance: ng init', function () {
]).then(confirmBlueprinted);
});

it('ng init --mobile', () => {
// Add the mobile ones.
pull(Blueprint.ignoredFiles, 'manifest.webapp');
pull(Blueprint.ignoredFiles, 'icon.png');
return ng([
'init',
'--skip-npm',
'--skip-bower',
'--mobile'
]).then(confirmBlueprinted);
});

it('ng init can run in created folder', function () {
return tmp.setup('./tmp/foo')
.then(function () {
Expand Down Expand Up @@ -183,5 +201,4 @@ describe('Acceptance: ng init', function () {
})
.then(confirmBlueprinted);
});

});

0 comments on commit de9b1ac

Please sign in to comment.