Skip to content

Commit 92e4c8d

Browse files
authored
Added blueprints to package.json's files (#74)
* feature: Checked whether the addon has blueprint files * refactor: Added failing tests * bugfix: Added blueprints to files * refactor: Improved code readability --------- Co-authored-by: ijlee2 <[email protected]>
1 parent 7175c1f commit 92e4c8d

File tree

20 files changed

+363
-12
lines changed

20 files changed

+363
-12
lines changed

src/steps/analyze-addon.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,20 @@ function getPublicAssets(options: Options): Record<string, string> {
3131
);
3232
}
3333

34+
function hasBlueprints(options: Options): boolean {
35+
const { projectRoot } = options;
36+
37+
const filePaths = findFiles('blueprints/**/*', {
38+
projectRoot,
39+
});
40+
41+
return filePaths.length > 0;
42+
}
43+
3444
export function analyzeAddon(options: Options): Context {
3545
return {
3646
addon: {
47+
hasBlueprints: hasBlueprints(options),
3748
publicAssets: getPublicAssets(options),
3849
},
3950
projectRoot: {

src/steps/update-addon-package-json/update-other-fields.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Context, Options, PackageJson } from '../../types/index.js';
22

33
type Data = {
4+
hasBlueprints: boolean;
45
hasPublicAssets: boolean;
56
hasTypeScript: boolean;
67
publicAssets: Record<string, string>;
@@ -59,10 +60,14 @@ function updateExports(packageJson: PackageJson, data: Data): void {
5960
}
6061

6162
function updateFiles(packageJson: PackageJson, data: Data): void {
62-
const { hasPublicAssets, hasTypeScript } = data;
63+
const { hasBlueprints, hasPublicAssets, hasTypeScript } = data;
6364

6465
const files = new Set(['addon-main.cjs', 'dist']);
6566

67+
if (hasBlueprints) {
68+
files.add('blueprints');
69+
}
70+
6671
if (hasPublicAssets) {
6772
files.add('public');
6873
}
@@ -93,15 +98,14 @@ export function updateOtherFields(
9398
context: Context,
9499
options: Options,
95100
): void {
96-
const { addon } = context;
97-
const { packages } = options;
98-
99-
const hasPublicAssets = Object.keys(addon.publicAssets).length > 0;
101+
const { hasBlueprints, publicAssets } = context.addon;
102+
const { hasTypeScript } = options.packages.addon;
100103

101104
const data = {
102-
hasPublicAssets,
103-
hasTypeScript: packages.addon.hasTypeScript,
104-
publicAssets: addon.publicAssets,
105+
hasBlueprints,
106+
hasPublicAssets: Object.keys(publicAssets).length > 0,
107+
hasTypeScript,
108+
publicAssets,
105109
};
106110

107111
updateEmberAddon(packageJson, data);

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type CodemodOptions = {
99

1010
type Context = {
1111
addon: {
12+
hasBlueprints: boolean;
1213
publicAssets: Record<string, string>;
1314
};
1415
projectRoot: {

tests/fixtures/steps/update-addon-package-json/blueprints/input/ember-container-query/blueprints/some-command/files/some-folder/some-file.ts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
description: 'Generates something',
5+
};
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{
2+
"name": "ember-container-query",
3+
"version": "3.2.0",
4+
"description": "Container queries using Ember modifiers",
5+
"keywords": [
6+
"container-queries",
7+
"container-query",
8+
"element-queries",
9+
"element-query",
10+
"ember-addon",
11+
"ember-octane",
12+
"emberjs",
13+
"glint",
14+
"responsive-design"
15+
],
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/ijlee2/ember-container-query.git"
19+
},
20+
"license": "MIT",
21+
"author": "Isaac J. Lee",
22+
"directories": {
23+
"doc": "doc",
24+
"test": "tests"
25+
},
26+
"scripts": {
27+
"build": "ember build --environment=production",
28+
"build:test": "ember build --environment=test",
29+
"changelog": "lerna-changelog",
30+
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
31+
"lint:css": "stylelint \"tests/dummy/app/**/*.css\" --cache",
32+
"lint:css:fix": "stylelint \"tests/dummy/app/**/*.css\" --fix",
33+
"lint:dependency": "ember dependency-lint",
34+
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
35+
"lint:hbs": "ember-template-lint .",
36+
"lint:hbs:fix": "ember-template-lint . --fix",
37+
"lint:js": "eslint . --cache --ext=.js,.ts",
38+
"lint:js:fix": "eslint . --fix",
39+
"lint:types": "tsc --noEmit",
40+
"prepack": "ember ts:precompile",
41+
"postpack": "ember ts:clean",
42+
"start": "ember serve",
43+
"test": "DEVICE='w3-h3' ember test",
44+
"test:ember": "ember test",
45+
"test:ember-compatibility": "./node_modules/.bin/ember try:one"
46+
},
47+
"changelog": {
48+
"labels": {
49+
"breaking": "Breaking Change",
50+
"bug": "Bug Fix",
51+
"enhance: code": "Enhancement",
52+
"enhance: dependency": "Internal",
53+
"enhance: documentation": "Documentation",
54+
"user feedback": "User Feedback"
55+
}
56+
},
57+
"dependencies": {
58+
"ember-cli-babel": "^7.26.11",
59+
"ember-cli-htmlbars": "^6.1.1",
60+
"ember-cli-typescript": "^5.2.1",
61+
"ember-element-helper": "^0.6.1",
62+
"ember-modifier": "^3.2.7",
63+
"ember-resize-observer-service": "^1.1.0",
64+
"ember-test-selectors": "^6.0.0"
65+
},
66+
"devDependencies": {
67+
"@ember/optional-features": "^2.0.0",
68+
"@ember/test-helpers": "^2.9.3",
69+
"@embroider/test-setup": "^2.0.2",
70+
"@glimmer/component": "^1.1.2",
71+
"@glimmer/tracking": "^1.1.2",
72+
"@percy/cli": "^1.16.0",
73+
"@percy/ember": "^4.0.0",
74+
"@tsconfig/ember": "^2.0.0",
75+
"@types/ember__application": "^4.0.5",
76+
"@types/ember__array": "^4.0.3",
77+
"@types/ember__component": "^4.0.12",
78+
"@types/ember__controller": "^4.0.4",
79+
"@types/ember__debug": "^4.0.3",
80+
"@types/ember__destroyable": "^4.0.1",
81+
"@types/ember__engine": "^4.0.4",
82+
"@types/ember__error": "^4.0.2",
83+
"@types/ember__object": "^4.0.5",
84+
"@types/ember__polyfills": "^4.0.1",
85+
"@types/ember__routing": "^4.0.12",
86+
"@types/ember__runloop": "^4.0.2",
87+
"@types/ember__service": "^4.0.2",
88+
"@types/ember__string": "^3.0.10",
89+
"@types/ember__template": "^4.0.1",
90+
"@types/ember__test": "^4.0.1",
91+
"@types/ember__utils": "^4.0.2",
92+
"@types/htmlbars-inline-precompile": "^3.0.0",
93+
"@types/qunit": "^2.19.3",
94+
"@types/rsvp": "^4.0.4",
95+
"@typescript-eslint/eslint-plugin": "^5.48.0",
96+
"@typescript-eslint/parser": "^5.48.0",
97+
"broccoli-asset-rev": "^3.0.0",
98+
"concurrently": "^7.6.0",
99+
"d3-array": "^3.2.1",
100+
"d3-axis": "^3.0.0",
101+
"d3-scale": "^4.0.2",
102+
"d3-selection": "^3.0.0",
103+
"d3-shape": "^3.2.0",
104+
"ember-a11y-refocus": "^3.0.2",
105+
"ember-a11y-testing": "^5.1.0",
106+
"ember-auto-import": "^2.5.0",
107+
"ember-cli": "~4.9.2",
108+
"ember-cli-dependency-checker": "^3.3.1",
109+
"ember-cli-dependency-lint": "^2.0.1",
110+
"ember-cli-inject-live-reload": "^2.1.0",
111+
"ember-cli-netlify": "^0.4.1",
112+
"ember-cli-sri": "^2.1.1",
113+
"ember-cli-terser": "^4.0.2",
114+
"ember-css-modules": "^2.0.1",
115+
"ember-load-initializers": "^2.1.2",
116+
"ember-page-title": "^7.0.0",
117+
"ember-qunit": "^6.1.1",
118+
"ember-resolver": "^9.0.1",
119+
"ember-source": "~4.9.3",
120+
"ember-source-channel-url": "^3.0.0",
121+
"ember-svg-jar": "^2.4.2",
122+
"ember-template-lint": "^5.3.0",
123+
"ember-template-lint-plugin-prettier": "^4.1.0",
124+
"ember-truth-helpers": "^3.1.1",
125+
"ember-try": "^2.0.0",
126+
"eslint": "^8.31.0",
127+
"eslint-config-prettier": "^8.6.0",
128+
"eslint-plugin-ember": "^11.4.2",
129+
"eslint-plugin-n": "^15.6.0",
130+
"eslint-plugin-prettier": "^4.2.1",
131+
"eslint-plugin-qunit": "^7.3.4",
132+
"eslint-plugin-simple-import-sort": "^8.0.0",
133+
"eslint-plugin-typescript-sort-keys": "^2.1.0",
134+
"lerna-changelog": "^2.2.0",
135+
"loader.js": "^4.7.0",
136+
"prettier": "^2.8.1",
137+
"qunit": "^2.19.3",
138+
"qunit-dom": "^2.0.0",
139+
"stylelint": "^14.16.1",
140+
"stylelint-config-standard": "^29.0.0",
141+
"stylelint-no-unsupported-browser-features": "^6.0.1",
142+
"stylelint-order": "^6.0.0",
143+
"typescript": "^4.9.4",
144+
"webpack": "^5.75.0"
145+
},
146+
"engines": {
147+
"node": "14.* || 16.* || >= 18"
148+
},
149+
"ember": {
150+
"edition": "octane"
151+
},
152+
"ember-addon": {
153+
"configPath": "tests/dummy/config",
154+
"demoURL": "https://ember-container-query.netlify.app"
155+
}
156+
}

tests/fixtures/steps/update-addon-package-json/blueprints/output/ember-container-query/blueprints/some-command/files/some-folder/some-file.ts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
description: 'Generates something',
5+
};
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"name": "ember-container-query",
3+
"version": "3.2.0",
4+
"description": "Container queries using Ember modifiers",
5+
"keywords": [
6+
"container-queries",
7+
"container-query",
8+
"element-queries",
9+
"element-query",
10+
"ember-addon",
11+
"ember-octane",
12+
"emberjs",
13+
"glint",
14+
"responsive-design"
15+
],
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/ijlee2/ember-container-query.git"
19+
},
20+
"license": "MIT",
21+
"author": "Isaac J. Lee",
22+
"directories": {
23+
"doc": "doc",
24+
"test": "tests"
25+
},
26+
"scripts": {
27+
"build": "concurrently \"npm:build:*\" --names \"build:\"",
28+
"build:js": "rollup --config",
29+
"build:test": "ember build --environment=test",
30+
"build:types": "tsc",
31+
"changelog": "lerna-changelog",
32+
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
33+
"lint:css": "stylelint \"tests/dummy/app/**/*.css\" --cache",
34+
"lint:css:fix": "stylelint \"tests/dummy/app/**/*.css\" --fix",
35+
"lint:dependency": "ember dependency-lint",
36+
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
37+
"lint:hbs": "ember-template-lint .",
38+
"lint:hbs:fix": "ember-template-lint . --fix",
39+
"lint:js": "eslint . --cache --ext=.js,.ts",
40+
"lint:js:fix": "eslint . --fix",
41+
"lint:types": "tsc --emitDeclarationOnly false --noEmit",
42+
"prepack": "rollup --config",
43+
"start": "concurrently \"npm:start:*\" --names \"start:\"",
44+
"start:js": "rollup --config --watch --no-watch.clearScreen",
45+
"start:types": "tsc --watch",
46+
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
47+
"test:ember": "ember test",
48+
"test:ember-compatibility": "./node_modules/.bin/ember try:one"
49+
},
50+
"changelog": {
51+
"labels": {
52+
"breaking": "Breaking Change",
53+
"bug": "Bug Fix",
54+
"enhance: code": "Enhancement",
55+
"enhance: dependency": "Internal",
56+
"enhance: documentation": "Documentation",
57+
"user feedback": "User Feedback"
58+
}
59+
},
60+
"dependencies": {
61+
"@embroider/addon-shim": "^1.8.7",
62+
"decorator-transforms": "^1.0.1",
63+
"ember-element-helper": "^0.6.1",
64+
"ember-modifier": "^3.2.7",
65+
"ember-resize-observer-service": "^1.1.0",
66+
"ember-test-selectors": "^6.0.0"
67+
},
68+
"devDependencies": {
69+
"@babel/core": "^7.23.6",
70+
"@babel/plugin-transform-typescript": "^7.23.6",
71+
"@babel/runtime": "^7.23.6",
72+
"@embroider/addon-dev": "^4.1.3",
73+
"@rollup/plugin-babel": "^6.0.4",
74+
"@tsconfig/ember": "^2.0.0",
75+
"babel-plugin-ember-template-compilation": "^2.2.1",
76+
"concurrently": "^7.6.0",
77+
"rollup": "^4.9.1",
78+
"rollup-plugin-copy": "^3.5.0",
79+
"typescript": "^4.9.4"
80+
},
81+
"engines": {
82+
"node": "14.* || 16.* || >= 18"
83+
},
84+
"ember": {
85+
"edition": "octane"
86+
},
87+
"ember-addon": {
88+
"app-js": {},
89+
"main": "addon-main.cjs",
90+
"type": "addon",
91+
"version": 2
92+
},
93+
"exports": {
94+
".": {
95+
"types": "./declarations/index.d.ts",
96+
"default": "./dist/index.js"
97+
},
98+
"./*": {
99+
"types": "./declarations/*.d.ts",
100+
"default": "./dist/*.js"
101+
},
102+
"./addon-main.js": "./addon-main.cjs"
103+
},
104+
"files": [
105+
"addon-main.cjs",
106+
"blueprints",
107+
"declarations",
108+
"dist"
109+
],
110+
"typesVersions": {
111+
"*": {
112+
"*": [
113+
"declarations/*"
114+
]
115+
}
116+
}
117+
}

tests/helpers/shared-test-setups/customizations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const codemodOptions: CodemodOptions = {
1313

1414
const context: Context = {
1515
addon: {
16+
hasBlueprints: false,
1617
publicAssets: {},
1718
},
1819
projectRoot: {

0 commit comments

Comments
 (0)