Permalink
Browse files

Auto merge of #6272 - Turbo87:sort-package-json, r=Turbo87

Sort package.json according to the package.json documentation

This PR sorts our own `package.json` file according to the order in the [documentation](https://docs.npmjs.com/files/package.json). It also sorts that file in the `app` blueprint the same way and introduces [sort-package-json](https://github.com/keithamus/sort-package-json) to make sure that the file is sorted properly for the `addon` blueprint too.

Note that this is also the same order that `npm init` will create for you.

/cc @rwjblue @stefanpenner @kellyselden
  • Loading branch information...
homu committed Sep 17, 2016
2 parents 84c9ec3 + e385562 commit 39bbd05c2e3c49951822ee67c3c18a5646091e67
View
@@ -5,17 +5,17 @@ var walkSync = require('walk-sync');
var stringUtil = require('ember-cli-string-utils');
var uniq = require('ember-cli-lodash-subset').uniq;
var SilentError = require('silent-error');
var sortPackageJson = require('sort-package-json');
var date = new Date();
var normalizeEntityName = require('ember-cli-normalize-entity-name');
var stringifyAndNormalize = require('../../lib/utilities/stringify-and-normalize');
var alphabetizeObjectKeys = require('../../lib/utilities/alphabetize-object-keys');
module.exports = {
description: 'The default blueprint for ember-cli addons.',
generatePackageJson: function() {
var contents = readContentsFromFile.call(this, 'package.json');
var contents = this._readContentsFromFile('package.json');
delete contents.private;
contents.name = this.project.name();
@@ -43,18 +43,15 @@ module.exports = {
contents['ember-addon'] = contents['ember-addon'] || {};
contents['ember-addon'].configPath = 'tests/dummy/config';
// sort the dependencies like an `npm install` would
alphabetizeDependencies(contents);
writeContentsToFile.call(this, contents, 'package.json');
this._writeContentsToFile(sortPackageJson(contents), 'package.json');
},
generateBowerJson: function() {
var contents = readContentsFromFile.call(this, 'bower.json');
var contents = this._readContentsFromFile('bower.json');
contents.name = this.project.name();
writeContentsToFile.call(this, contents, 'bower.json');
this._writeContentsToFile(contents, 'bower.json');
},
afterInstall: function() {
@@ -147,21 +144,15 @@ module.exports = {
}
return entityName;
}
};
function readContentsFromFile(fileName) {
var packagePath = path.join(this._appBlueprint.path, 'files', fileName);
return fs.readJsonSync(packagePath);
}
function alphabetizeDependencies(contents) {
contents.dependencies = alphabetizeObjectKeys(contents.dependencies);
contents.devDependencies = alphabetizeObjectKeys(contents.devDependencies);
}
},
function writeContentsToFile(contents, fileName) {
var packagePath = path.join(this.path, 'files', fileName);
_readContentsFromFile: function(fileName) {
var packagePath = path.join(this._appBlueprint.path, 'files', fileName);
return fs.readJsonSync(packagePath);
},
fs.writeFileSync(packagePath, stringifyAndNormalize(contents));
}
_writeContentsToFile: function(contents, fileName) {
var packagePath = path.join(this.path, 'files', fileName);
fs.writeFileSync(packagePath, stringifyAndNormalize(contents));
},
};
@@ -2,22 +2,18 @@
"name": "<%= name %>",
"version": "0.0.0",
"description": "Small description for <%= name %> goes here",
"private": true,
"license": "MIT",
"author": "",
"directories": {
"doc": "doc",
"test": "tests"
},
"repository": "",
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember test"
},
"repository": "",
"engines": {
"node": ">= 0.12.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
@@ -40,5 +36,9 @@
"ember-resolver": "^2.0.3",
"ember-welcome-page": "^1.0.3",
"loader.js": "^4.0.10"
}
},
"engines": {
"node": ">= 0.12.0"
},
"private": true
}

This file was deleted.

Oops, something went wrong.
View
@@ -1,43 +1,39 @@
{
"name": "ember-cli",
"version": "2.9.0-beta.1",
"main": "lib/cli/index.js",
"description": "Command line tool for developing ambitious ember.js apps",
"keywords": [
"app",
"app-kit",
"cli",
"ember",
"ember-app-kit",
"ember.js",
"kit"
],
"homepage": "http://ember-cli.com/",
"trackingCode": "UA-49225444-1",
"bugs": {
"url": "https://github.com/ember-cli/ember-cli/issues"
},
"license": "MIT",
"author": "Stefan Penner, Robert Jackson and ember-cli contributors",
"main": "lib/cli/index.js",
"bin": {
"ember": "./bin/ember"
},
"repository": {
"type": "git",
"url": "https://github.com/ember-cli/ember-cli.git"
},
"scripts": {
"docs": "yuidoc",
"lint": "node tests/runner lint",
"test": "node tests/runner",
"test:debug": "node debug tests/runner",
"test-slow": "node tests/runner slow",
"test-all": "node tests/runner all",
"test-all:cover": "istanbul cover tests/runner.js all",
"test-all:debug": "node debug tests/runner all",
"test-all:cover": "istanbul cover tests/runner.js all"
},
"repository": {
"type": "git",
"url": "https://github.com/ember-cli/ember-cli.git"
},
"engines": {
"node": ">= 0.10.0"
},
"keywords": [
"ember.js",
"ember",
"cli",
"app",
"kit",
"app-kit",
"ember-app-kit"
],
"author": "Stefan Penner, Robert Jackson and ember-cli contributors",
"license": "MIT",
"bugs": {
"url": "https://github.com/ember-cli/ember-cli/issues"
"test-slow": "node tests/runner slow",
"test:debug": "node debug tests/runner"
},
"dependencies": {
"amd-name-resolver": "0.0.6",
@@ -53,7 +49,6 @@
"broccoli-funnel": "^1.0.6",
"broccoli-funnel-reducer": "^1.0.0",
"broccoli-merge-trees": "^1.1.3",
"ember-cli-broccoli-sane-watcher": "^2.0.3",
"broccoli-middleware": "^0.18.1",
"broccoli-source": "^1.1.0",
"broccoli-stew": "^1.2.0",
@@ -63,6 +58,7 @@
"configstore": "^2.0.0",
"core-object": "^2.0.2",
"diff": "^1.3.1",
"ember-cli-broccoli-sane-watcher": "^2.0.3",
"ember-cli-get-component-path-option": "^1.0.0",
"ember-cli-is-package-missing": "^1.0.0",
"ember-cli-legacy-blueprints": "^0.1.1",
@@ -90,8 +86,8 @@
"is-git-url": "^0.2.0",
"isbinaryfile": "^3.0.0",
"leek": "0.0.23",
"markdown-it": "7.0.1",
"lodash.template": "^4.2.5",
"markdown-it": "7.0.1",
"markdown-it-terminal": "0.0.4",
"minimatch": "^3.0.0",
"morgan": "^1.5.2",
@@ -109,6 +105,7 @@
"sane": "^1.1.1",
"semver": "^5.1.1",
"silent-error": "^1.0.0",
"sort-package-json": "^1.4.0",
"symlink-or-copy": "^1.0.1",
"temp": "0.8.3",
"testem": "^1.8.1",
@@ -137,7 +134,11 @@
"proxyquire": "^1.7.7",
"supertest": "^2.0.0",
"testdouble": "^1.3.0",
"yuidocjs": "0.10.2",
"yuidoc-ember-cli-theme": "^1.0.0"
}
"yuidoc-ember-cli-theme": "^1.0.0",
"yuidocjs": "0.10.2"
},
"engines": {
"node": ">= 0.10.0"
},
"trackingCode": "UA-49225444-1"
}
@@ -95,12 +95,12 @@ describe('blueprint - addon', function() {
{\n\
"name": "test-project-name",\n\
"description": "The default blueprint for ember-cli addons.",\n\
"scripts": {\n\
"test": "ember try:each"\n\
},\n\
"keywords": [\n\
"ember-addon"\n\
],\n\
"scripts": {\n\
"test": "ember try:each"\n\
},\n\
"dependencies": {},\n\
"devDependencies": {\n\
"ember-disable-prototype-extensions": "^1.1.0"\n\

This file was deleted.

Oops, something went wrong.

0 comments on commit 39bbd05

Please sign in to comment.