Skip to content

Commit 76dd59d

Browse files
Merge pull request #148 from ember-cli/nvp/sort-package-json
Sort the package.json, using the replacers strategy
2 parents 415b14c + da926f6 commit 76dd59d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
const stringUtil = require('ember-cli-string-utils');
44
const chalk = require('chalk');
55
const directoryForPackageName = require('./lib/directory-for-package-name');
6+
const { sortPackageJson } = require('sort-package-json');
7+
8+
function stringifyAndNormalize(contents) {
9+
return `${JSON.stringify(contents, null, 2)}\n`;
10+
}
11+
12+
const replacers = {
13+
'package.json'(...args) {
14+
return this.updatePackageJson(...args);
15+
},
16+
};
617

718
module.exports = {
819
description: 'The default blueprint for ember-cli projects.',
@@ -143,6 +154,10 @@ module.exports = {
143154
buildFileInfo(intoDir, templateVariables, file, options) {
144155
let fileInfo = this._super.buildFileInfo.apply(this, arguments);
145156

157+
if (file in replacers) {
158+
fileInfo.replacer = replacers[file].bind(this, templateVariables);
159+
}
160+
146161
if (file.includes('_js_')) {
147162
if (options.typescript) {
148163
return null;
@@ -167,4 +182,10 @@ module.exports = {
167182

168183
return fileInfo;
169184
},
185+
186+
updatePackageJson(options, content) {
187+
let contents = JSON.parse(content);
188+
189+
return stringifyAndNormalize(sortPackageJson(contents));
190+
},
170191
};

0 commit comments

Comments
 (0)