Skip to content
Merged
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
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
'use strict';

const { sortPackageJson } = require('sort-package-json');

let date = new Date();

const description = 'The default blueprint for Embroider v2 addons.';

function stringifyAndNormalize(contents) {
return `${JSON.stringify(contents, null, 2)}\n`;
}

const replacers = {
'package.json'(content) {
return this.updatePackageJson(content);
},
};

module.exports = {
description,

Expand Down Expand Up @@ -60,6 +72,36 @@ module.exports = {

return files;
},

updatePackageJson(content) {
let contents = JSON.parse(content);
return stringifyAndNormalize(sortPackageJson(contents));
},

/**
* @override
*
* This modification of buildFileInfo allows our differing
* input files to output to a single file, depending on the options.
* For example:
*
* for javascript,
* _ts_eslint.config.mjs is deleted
* _js_eslint.config.mjs is renamed to eslint.config.mjs
*
* for typescript,
* _js_eslint.config.mjs is deleted
* _ts_eslint.config.mjs is renamed to eslint.config.mjs
*/
buildFileInfo(_intoDir, _templateVariables, file, _commandOptions) {
let fileInfo = this._super.buildFileInfo.apply(this, arguments);

if (file in replacers) {
fileInfo.replacer = replacers[file].bind(this);
}

return fileInfo;
},
};

function buildBlueprintOptions(blueprintOptions) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"prettier": "^3.5.3",
"release-plan": "^0.16.0"
},
"dependencies": {
"sort-package-json": "^3.4.0"
},
"packageManager": "[email protected]"
}
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
assertGeneratedCorrectly,
dirContents,
matchesFixture,
packageJsonAt,
SUPPORTED_PACKAGE_MANAGERS,
} from '../helpers.js';
import { existsSync } from 'node:fs';
import sortPackageJson from 'sort-package-json';

/**
* NOTE: tests run sequentially
Expand Down Expand Up @@ -108,6 +110,13 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
expect(exitCode).toEqual(0);
});

it('has a sorted package.json', async () => {
const originalPackageJson = await packageJsonAt(addonDir);
const sortedPackageJson = await sortPackageJson(originalPackageJson);

expect(JSON.stringify(sortedPackageJson)).toEqual(JSON.stringify(originalPackageJson));
});

describe('with fixture', () => {
beforeEach(async () => {
let addonFixture = fixturify.readSync('./fixtures/addon');
Expand Down