Skip to content

Commit d85a39c

Browse files
authored
Reorganized utilities and handled multiline comments in JSON (#10)
* refactor: Created a dedicated file for each function related to handling files * refactor: Grouped mapFilePaths under utilities for files * refactor: Simplified removeFiles * refactor: Grouped processTemplate under utilities for blueprints * refactor: Grouped decideVersion under utilities for blueprints * refactor: Removed hard-coded latest versions from blueprints * refactor: Grouped appReexports and publicEntrypoints under addon * refactor: Created a dedicated file for each function related to handling JSON * bugfix: Removed multiline comments in a JSON file * refactor: Extracted context to shared-test-setups Co-authored-by: ijlee2 <[email protected]>
1 parent d29895a commit d85a39c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+577
-353
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@babel/eslint-parser": "^7.19.1",
5050
"glob": "^8.1.0",
5151
"lodash.template": "^4.5.0",
52+
"strip-json-comments": "^5.0.0",
5253
"yargs": "^17.6.2"
5354
},
5455
"devDependencies": {

src/blueprints/ember-addon/__addonLocation__/rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export default {
1515
plugins: [
1616
// These are the modules that users should be able to import from your
1717
// addon. Anything not listed here may get optimized away.
18-
addon.publicEntrypoints([<%= context.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
18+
addon.publicEntrypoints([<%= context.addon.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
1919

2020
// These are the modules that should get reexported into the traditional
2121
// "app" tree. Things in here should also be in publicEntrypoints above, but
2222
// not everything in publicEntrypoints necessarily needs to go here.
23-
addon.appReexports([<%= context.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
23+
addon.appReexports([<%= context.addon.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
2424

2525
// Follow the V2 Addon rules about dependencies. Your code can import from
2626
// `dependencies` and `peerDependencies` as well as standard Ember-provided

src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export default {
1515
plugins: [
1616
// These are the modules that users should be able to import from your
1717
// addon. Anything not listed here may get optimized away.
18-
addon.publicEntrypoints([<%= context.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
18+
addon.publicEntrypoints([<%= context.addon.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
1919

2020
// These are the modules that should get reexported into the traditional
2121
// "app" tree. Things in here should also be in publicEntrypoints above, but
2222
// not everything in publicEntrypoints necessarily needs to go here.
23-
addon.appReexports([<%= context.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
23+
addon.appReexports([<%= context.addon.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
2424

2525
// Follow the V2 Addon rules about dependencies. Your code can import from
2626
// `dependencies` and `peerDependencies` as well as standard Ember-provided

src/blueprints/ember-addon/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"test": "npm run test --workspaces --if-present"
2121
},
2222
"devDependencies": {
23-
"concurrently": "<%= options.packages.addon.dependencies.get('concurrently') ?? '^7.6.0' %>",
24-
"prettier": "<%= options.packages.addon.dependencies.get('prettier') ?? '^2.8.3' %>"
23+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>",
24+
"prettier": "<%= context.projectRoot.devDependencies['prettier'] %>"
2525
}
2626
}<% } else if (options.packageManager.isPnpm) { %>{
2727
"name": "<%= options.packages.addon.name %>",
@@ -45,8 +45,8 @@
4545
"test": "pnpm --filter '*' test"
4646
},
4747
"devDependencies": {
48-
"concurrently": "<%= options.packages.addon.dependencies.get('concurrently') ?? '^7.6.0' %>",
49-
"prettier": "<%= options.packages.addon.dependencies.get('prettier') ?? '^2.8.3' %>"
48+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>",
49+
"prettier": "<%= context.projectRoot.devDependencies['prettier'] %>"
5050
}
5151
}<% } else if (options.packageManager.isYarn) { %>{
5252
"name": "<%= options.packages.addon.name %>",
@@ -70,7 +70,7 @@
7070
"test": "yarn workspaces run test"
7171
},
7272
"devDependencies": {
73-
"concurrently": "<%= options.packages.addon.dependencies.get('concurrently') ?? '^7.6.0' %>",
74-
"prettier": "<%= options.packages.addon.dependencies.get('prettier') ?? '^2.8.3' %>"
73+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>",
74+
"prettier": "<%= context.projectRoot.devDependencies['prettier'] %>"
7575
}
7676
}<% } %>

src/migration/ember-addon/steps/analyze-addon.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { join } from 'node:path';
22

33
import glob from 'glob';
44

5+
import { decideVersion } from '../../../utils/blueprints.js';
6+
57
function getAppReexports(options) {
68
const { projectRoot } = options;
79

@@ -12,6 +14,13 @@ function getAppReexports(options) {
1214
return filePaths;
1315
}
1416

17+
function getProjectRootDevDependencies(options) {
18+
return {
19+
concurrently: decideVersion('concurrently', options),
20+
prettier: decideVersion('prettier', options),
21+
};
22+
}
23+
1524
function getPublicEntrypoints(options) {
1625
const { projectRoot } = options;
1726

@@ -23,8 +32,13 @@ function getPublicEntrypoints(options) {
2332
}
2433

2534
export function analyzeAddon(options) {
26-
const appReexports = getAppReexports(options);
27-
const publicEntrypoints = getPublicEntrypoints(options);
28-
29-
return { appReexports, publicEntrypoints };
35+
return {
36+
addon: {
37+
appReexports: getAppReexports(options),
38+
publicEntrypoints: getPublicEntrypoints(options),
39+
},
40+
projectRoot: {
41+
devDependencies: getProjectRootDevDependencies(options),
42+
},
43+
};
3044
}

src/migration/ember-addon/steps/create-files-from-blueprint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { fileURLToPath } from 'node:url';
44

55
import glob from 'glob';
66

7+
import { processTemplate } from '../../../utils/blueprints.js';
78
import { createFiles } from '../../../utils/files.js';
8-
import { processTemplate } from '../../../utils/process-template.js';
99

1010
const __filename = fileURLToPath(import.meta.url);
1111
const __dirname = dirname(__filename);

src/migration/ember-addon/steps/move-addon-files.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import glob from 'glob';
22

3-
import { moveFiles, removeFiles } from '../../../utils/files.js';
4-
import { mapFilePaths } from '../../../utils/map-file-paths.js';
3+
import { mapFilePaths, moveFiles, removeFiles } from '../../../utils/files.js';
54

65
function moveAddonFolder(options) {
76
const { locations, projectRoot } = options;
@@ -63,12 +62,7 @@ function removeAppFolder(options) {
6362
nodir: true,
6463
});
6564

66-
const pathMapping = mapFilePaths(filePaths, {
67-
from: 'app',
68-
to: 'app',
69-
});
70-
71-
removeFiles(pathMapping, options);
65+
removeFiles(filePaths, options);
7266
}
7367

7468
export function moveAddonFiles(options) {

src/migration/ember-addon/steps/move-project-root-files.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import glob from 'glob';
22

3-
import { copyFiles, moveFiles, removeFiles } from '../../../utils/files.js';
4-
import { mapFilePaths } from '../../../utils/map-file-paths.js';
3+
import {
4+
copyFiles,
5+
mapFilePaths,
6+
moveFiles,
7+
removeFiles,
8+
} from '../../../utils/files.js';
59

610
function globPattern(files) {
711
if (files.length <= 1) {
@@ -72,12 +76,7 @@ function moveToAddonAndTestApp(options) {
7276

7377
copyFiles(pathMapping, options);
7478

75-
pathMapping = mapFilePaths(filePaths, {
76-
from: '',
77-
to: '',
78-
});
79-
80-
removeFiles(pathMapping, options);
79+
removeFiles(filePaths, options);
8180
}
8281

8382
function moveToTestApp(options) {
@@ -111,12 +110,7 @@ function removeFromProjectRoot(options) {
111110
cwd: projectRoot,
112111
});
113112

114-
const pathMapping = mapFilePaths(filePaths, {
115-
from: '',
116-
to: '',
117-
});
118-
119-
removeFiles(pathMapping, options);
113+
removeFiles(filePaths, options);
120114
}
121115

122116
export function moveProjectRootFiles(options) {

src/migration/ember-addon/steps/move-test-app-files.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { join } from 'node:path';
33

44
import glob from 'glob';
55

6-
import { moveFiles } from '../../../utils/files.js';
7-
import { mapFilePaths } from '../../../utils/map-file-paths.js';
6+
import { mapFilePaths, moveFiles } from '../../../utils/files.js';
87

98
function moveTestsFolder(options) {
109
const { locations, projectRoot } = options;

src/migration/ember-addon/steps/update-addon-package-json.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { readFileSync, writeFileSync } from 'node:fs';
22
import { join } from 'node:path';
33

4-
import {
5-
convertToMap,
6-
convertToObject,
7-
} from '../../../utils/convert-json-object.js';
8-
import { decideVersion } from '../../../utils/decide-version.js';
4+
import { decideVersion } from '../../../utils/blueprints.js';
5+
import { convertToMap, convertToObject } from '../../../utils/json.js';
96

107
function updateDependencies(packageJson, options) {
118
const dependencies = convertToMap(packageJson['dependencies']);

0 commit comments

Comments
 (0)