Skip to content

Added .editorconfig to ng new #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import {
ComponentFixture,
TestComponentBuilder
} from 'angular2/testing';
import {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';
import { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component';

describe('Component: <%= classifiedModuleName %>', () => {
beforeEachProviders(() => [<%= classifiedModuleName %>Component]);

it('should create the component', inject([<%= classifiedModuleName %>Component], (component: <%= classifiedModuleName %>Component) => {
expect(component).toBeTruthy();
}));

});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit} from 'angular2/core';
import { Component, OnInit } from 'angular2/core';

@Component({
moduleId: __moduleName,
Expand Down
3 changes: 1 addition & 2 deletions addon/ng2/blueprints/component/files/__path__/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';

export { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component';
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
ComponentFixture,
TestComponentBuilder
} from 'angular2/testing';
import {provide, Component} from 'angular2/core';
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive';
import { provide, Component } from 'angular2/core';
import { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.directive';

@Component({
selector: 'test-component',
Expand All @@ -20,14 +20,11 @@ import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directi
class TestComponent {}

describe('<%= classifiedModuleName %> Directive', () => {

beforeEachProviders((): any[] => []);


it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture) => {
fixture.detectChanges();
});
})));

});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Directive} from 'angular2/core';
import { Directive } from 'angular2/core';

@Directive({
selector: '[<%= rawEntityName %>]'
Expand Down
14 changes: 14 additions & 0 deletions addon/ng2/blueprints/ng2/files/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = 0
trim_trailing_whitespace = false
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
ComponentFixture,
TestComponentBuilder
} from 'angular2/testing';
import {<%= jsComponentName %>App} from '../app/<%= htmlComponentName %>.component';
import { <%= jsComponentName %>AppComponent } from '../app/<%= htmlComponentName %>.component';

beforeEachProviders(() => [<%= jsComponentName %>App]);
beforeEachProviders(() => [<%= jsComponentName %>AppComponent]);

describe('App: <%= jsComponentName %>', () => {
it('should create the app', inject([<%= jsComponentName %>App], (app: <%= jsComponentName %>App) => {
it('should create the app', inject([<%= jsComponentName %>AppComponent], (app: <%= jsComponentName %>AppComponent) => {
expect(app).toBeTruthy();
}));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Component} from 'angular2/core';
import { Component } from 'angular2/core';

@Component({
moduleId: __moduleName,
selector: '<%= htmlComponentName %>-app',
templateUrl: '<%= htmlComponentName %>.component.html',
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
})
export class <%= jsComponentName %>App {
export class <%= jsComponentName %>AppComponent {
}
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
10 changes: 5 additions & 5 deletions addon/ng2/blueprints/ng2/files/__path__/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {bootstrap} from 'angular2/platform/browser';
import {enableProdMode} from 'angular2/core';
import {environment} from './app/environment';
import {<%= jsComponentName %>App} from './app/<%= htmlComponentName %>.component';
import { bootstrap } from 'angular2/platform/browser';
import { enableProdMode } from 'angular2/core';
import { environment } from './app/environment';
import { <%= jsComponentName %>AppComponent } from './app/<%= htmlComponentName %>.component';

if (environment.production) {
enableProdMode();
}

bootstrap(<%= jsComponentName %>App);
bootstrap(<%= jsComponentName %>AppComponent);
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import {
TestComponentBuilder,
beforeEachProviders
} from 'angular2/testing';
import {provide} from 'angular2/core';
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.pipe';
import { provide } from 'angular2/core';
import { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.pipe';

describe('<%= classifiedModuleName %> Pipe', () => {

beforeEachProviders(() => [<%= classifiedModuleName%>]);

it('should transform the input', inject([<%= classifiedModuleName %>], (pipe:<%= classifiedModuleName %>) => {
expect(pipe.transform(true)).toBe(null);
}));

});
2 changes: 1 addition & 1 deletion addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Pipe, PipeTransform} from 'angular2/core';
import { Pipe, PipeTransform } from 'angular2/core';

@Pipe({
name: '<%= camelizedModuleName %>'
Expand Down
2 changes: 1 addition & 1 deletion addon/ng2/blueprints/pipe/files/__path__/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.pipe';
export { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.pipe';
2 changes: 1 addition & 1 deletion addon/ng2/blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function _insertImport(content, symbolName, fileName) {
+ content.substr(m.index + m[0].length);
}

const importTemplate = `import {${symbolName}} from '${fileName}';`;
const importTemplate = `import { ${symbolName} } from '${fileName}';`;
// Find the last import and add an import to it.
content = content.replace(/(import.+)\n(?!import)/m, function (f, m1) {
return `${m1}\n${importTemplate}\n`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
expect,
inject
} from 'angular2/testing';
import {provide} from 'angular2/core';
import {<%= classifiedModuleName %>Service} from './<%= dasherizedModuleName %>.service';
import { provide } from 'angular2/core';
import { <%= classifiedModuleName %>Service } from './<%= dasherizedModuleName %>.service';

describe('<%= classifiedModuleName %> Service', () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/core';
import { Injectable } from 'angular2/core';

@Injectable()
export class <%= classifiedModuleName %>Service {
Expand Down
26 changes: 23 additions & 3 deletions addon/ng2/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as EmberGenerateCommand from 'ember-cli/lib/commands/generate';
import * as fs from 'fs';
import * as path from 'path';
import * as SilentError from 'silent-error';

var chalk = require('chalk');
import * as Blueprint from 'ember-cli/lib/models/blueprint';
var EOL = require('os').EOL;

const GenerateCommand = EmberGenerateCommand.extend({
name: 'generate',
Expand All @@ -15,10 +17,28 @@ const GenerateCommand = EmberGenerateCommand.extend({
// map the blueprint name to allow for aliases
rawArgs[0] = mapBlueprintName(rawArgs[0]);

if (!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
if (rawArgs[0] !== '--help' &&
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
}


// Override default help to hide ember blueprints
EmberGenerateCommand.prototype.printDetailedHelp = function (options) {
var blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
var blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));

var output = '';
blueprints
.forEach(function (bp) {
output += bp.printBasicHelp(false) + EOL;
});
this.ui.writeLine(chalk.cyan(' Available blueprints'));
this.ui.writeLine(output);
};

return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
}
});
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);
});

});
9 changes: 9 additions & 0 deletions tests/acceptance/new.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ describe('Acceptance: ng new', function () {
});
});

it('ng new has a .editorconfig file', function () {
return ng(['new', 'FooApp', '--skip-npm', '--skip-bower', '--skip-git']).then(function () {
expect(!existsSync('FooApp'));

var editorConfig = fs.readFileSync('.editorconfig', 'utf8');
expect(editorConfig).to.exist;
});
});

it('Cannot run ng new, inside of ember-cli project', function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git'])
.then(function () {
Expand Down