ember-codemod-v1-to-v2 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/package.json +8 -9
- package/src/blueprints/ember-addon/__gitignore__ +8 -9
- package/src/blueprints/ember-addon/package.json +3 -6
- package/src/migration/ember-addon/index.js +0 -2
- package/src/migration/ember-addon/steps/analyze-addon.js +4 -9
- package/src/migration/ember-addon/steps/create-files-from-blueprint.js +10 -25
- package/src/migration/ember-addon/steps/create-options.js +41 -25
- package/src/migration/ember-addon/steps/index.js +0 -1
- package/src/migration/ember-addon/steps/move-addon-files.js +11 -18
- package/src/migration/ember-addon/steps/move-project-root-files.js +6 -14
- package/src/migration/ember-addon/steps/move-test-app-files.js +9 -21
- package/src/migration/ember-addon/steps/update-addon-package-json.js +5 -2
- package/src/migration/ember-addon/steps/update-test-app-package-json.js +1 -1
- package/src/utils/blueprints/blueprints-root.js +13 -0
- package/src/utils/blueprints/decide-version.js +6 -7
- package/src/utils/blueprints.js +1 -0
- package/src/utils/files/find-files.js +28 -0
- package/src/utils/files/map-file-paths.js +1 -1
- package/src/utils/files.js +1 -0
- package/src/blueprints/ember-addon/.prettierignore +0 -25
- package/src/blueprints/ember-addon/.prettierrc.js +0 -5
- package/src/migration/ember-addon/steps/use-relative-paths.js +0 -89
package/README.md
CHANGED
|
@@ -8,7 +8,6 @@ _Codemod to convert Ember addons to v2 addon format_
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- Scaffolds files according to [`@embroider/addon-blueprint`](https://github.com/embroider-build/addon-blueprint)
|
|
11
|
-
- Switches Ember's "magic" import paths to relative paths
|
|
12
11
|
- Preserves your code whenever possible
|
|
13
12
|
- Supports [`ember-cli-typescript`](https://docs.ember-cli-typescript.com/) and [`glint`](https://typed-ember.gitbook.io/glint/)
|
|
14
13
|
- Focuses on maintainability and extensibility
|
|
@@ -116,7 +115,7 @@ You can also look at another codemod called [`ember-addon-migrator`](https://git
|
|
|
116
115
|
|
|
117
116
|
## Contributing
|
|
118
117
|
|
|
119
|
-
If you have an open-sourced addon that I can use as a
|
|
118
|
+
If you have an open-sourced addon (v1 or v2) that I can use as a reference, reach out to me on [Discord](https://discord.gg/emberjs) at `ijlee2`. Please star this project so that I can gauge its importance to you and the Ember community. ⭐
|
|
120
119
|
|
|
121
120
|
|
|
122
121
|
## Credits
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-v1-to-v2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Codemod to convert Ember addons to v2 addon format",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"changelog": "lerna-changelog",
|
|
32
32
|
"lint": "eslint . --cache",
|
|
33
33
|
"lint:fix": "eslint . --fix",
|
|
34
|
-
"start": "node ./src/index.js",
|
|
35
34
|
"test": "mt tests --quiet"
|
|
36
35
|
},
|
|
37
36
|
"changelog": {
|
|
@@ -45,24 +44,24 @@
|
|
|
45
44
|
}
|
|
46
45
|
},
|
|
47
46
|
"dependencies": {
|
|
48
|
-
"
|
|
49
|
-
"@babel/eslint-parser": "^7.19.1",
|
|
50
|
-
"glob": "^9.2.1",
|
|
47
|
+
"glob": "^10.2.2",
|
|
51
48
|
"lodash.template": "^4.5.0",
|
|
52
49
|
"strip-json-comments": "^5.0.0",
|
|
53
50
|
"yargs": "^17.7.1"
|
|
54
51
|
},
|
|
55
52
|
"devDependencies": {
|
|
53
|
+
"@babel/core": "^7.21.4",
|
|
54
|
+
"@babel/eslint-parser": "^7.21.3",
|
|
56
55
|
"@sondr3/minitest": "^0.1.1",
|
|
57
|
-
"eslint": "^8.
|
|
58
|
-
"eslint-config-prettier": "^8.
|
|
56
|
+
"eslint": "^8.39.0",
|
|
57
|
+
"eslint-config-prettier": "^8.8.0",
|
|
59
58
|
"eslint-plugin-import": "^2.27.5",
|
|
60
|
-
"eslint-plugin-n": "^15.
|
|
59
|
+
"eslint-plugin-n": "^15.7.0",
|
|
61
60
|
"eslint-plugin-prettier": "^4.2.1",
|
|
62
61
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
63
62
|
"fixturify": "^3.0.0",
|
|
64
63
|
"lerna-changelog": "^2.2.0",
|
|
65
|
-
"prettier": "^2.8.
|
|
64
|
+
"prettier": "^2.8.8"
|
|
66
65
|
},
|
|
67
66
|
"engines": {
|
|
68
67
|
"node": ">= 16"
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
-
|
|
3
1
|
# compiled output
|
|
4
|
-
dist/
|
|
2
|
+
/dist/
|
|
5
3
|
|
|
6
4
|
# dependencies
|
|
7
|
-
node_modules/
|
|
5
|
+
/node_modules/
|
|
8
6
|
|
|
9
7
|
# misc
|
|
10
8
|
/.env*
|
|
11
9
|
/.pnp*
|
|
12
|
-
/.
|
|
13
|
-
/.sass-cache
|
|
14
|
-
.eslintcache
|
|
15
|
-
/connect.lock
|
|
10
|
+
/.eslintcache
|
|
16
11
|
/coverage/
|
|
17
|
-
/libpeerconnection.log
|
|
18
12
|
/npm-debug.log*
|
|
19
13
|
/testem.log
|
|
20
14
|
/yarn-error.log
|
|
21
15
|
|
|
22
16
|
# ember-try
|
|
23
17
|
/.node_modules.ember-try/
|
|
18
|
+
/npm-shrinkwrap.json.ember-try
|
|
24
19
|
/package.json.ember-try
|
|
20
|
+
/package-lock.json.ember-try
|
|
25
21
|
/yarn.lock.ember-try
|
|
22
|
+
|
|
23
|
+
# broccoli-debug
|
|
24
|
+
/DEBUG/
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
"test": "npm run test --workspaces --if-present"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
24
|
-
"prettier": "<%= context.projectRoot.devDependencies['prettier'] %>"
|
|
23
|
+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
25
24
|
}
|
|
26
25
|
}<% } else if (options.packageManager.isPnpm) { %>{
|
|
27
26
|
"name": "<%= options.packages.addon.name %>",
|
|
@@ -41,8 +40,7 @@
|
|
|
41
40
|
"test": "pnpm --filter '*' test"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
45
|
-
"prettier": "<%= context.projectRoot.devDependencies['prettier'] %>"
|
|
43
|
+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
46
44
|
}
|
|
47
45
|
}<% } else if (options.packageManager.isYarn) { %>{
|
|
48
46
|
"name": "<%= options.packages.addon.name %>",
|
|
@@ -66,7 +64,6 @@
|
|
|
66
64
|
"test": "yarn workspaces run test"
|
|
67
65
|
},
|
|
68
66
|
"devDependencies": {
|
|
69
|
-
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
70
|
-
"prettier": "<%= context.projectRoot.devDependencies['prettier'] %>"
|
|
67
|
+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
71
68
|
}
|
|
72
69
|
}<% } %>
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
updateAddonTsconfigJson,
|
|
10
10
|
updateTestAppPackageJson,
|
|
11
11
|
updateTestAppTsconfigJson,
|
|
12
|
-
useRelativePaths,
|
|
13
12
|
} from './steps/index.js';
|
|
14
13
|
|
|
15
14
|
export function migrateEmberAddon(codemodOptions) {
|
|
@@ -23,7 +22,6 @@ export function migrateEmberAddon(codemodOptions) {
|
|
|
23
22
|
|
|
24
23
|
// Prepare for migration
|
|
25
24
|
const context = analyzeAddon(options);
|
|
26
|
-
useRelativePaths(options);
|
|
27
25
|
|
|
28
26
|
// Preserve code
|
|
29
27
|
moveAddonFiles(options);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { globSync } from 'glob';
|
|
2
|
-
|
|
3
1
|
import { decideVersion } from '../../../utils/blueprints.js';
|
|
4
|
-
import { renameDirectory } from '../../../utils/files.js';
|
|
2
|
+
import { findFiles, renameDirectory } from '../../../utils/files.js';
|
|
5
3
|
|
|
6
4
|
function getAppReexports(options) {
|
|
7
5
|
const { projectRoot } = options;
|
|
8
6
|
|
|
9
|
-
const filePaths =
|
|
7
|
+
const filePaths = findFiles('app/**/*.js', {
|
|
10
8
|
cwd: projectRoot,
|
|
11
9
|
});
|
|
12
10
|
|
|
@@ -23,17 +21,14 @@ function getAppReexports(options) {
|
|
|
23
21
|
function getProjectRootDevDependencies(options) {
|
|
24
22
|
return {
|
|
25
23
|
concurrently: decideVersion('concurrently', options),
|
|
26
|
-
prettier: decideVersion('prettier', options),
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
function getPublicAssets(options) {
|
|
31
28
|
const { projectRoot } = options;
|
|
32
29
|
|
|
33
|
-
const filePaths =
|
|
30
|
+
const filePaths = findFiles('public/**/*', {
|
|
34
31
|
cwd: projectRoot,
|
|
35
|
-
dot: true,
|
|
36
|
-
nodir: true,
|
|
37
32
|
});
|
|
38
33
|
|
|
39
34
|
return filePaths
|
|
@@ -49,7 +44,7 @@ function getPublicAssets(options) {
|
|
|
49
44
|
function getPublicEntrypoints(options) {
|
|
50
45
|
const { projectRoot } = options;
|
|
51
46
|
|
|
52
|
-
const filePaths =
|
|
47
|
+
const filePaths = findFiles('{addon,addon-test-support}/**/*.{js,ts}', {
|
|
53
48
|
cwd: projectRoot,
|
|
54
49
|
});
|
|
55
50
|
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { join } from 'node:path';
|
|
4
3
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { processTemplate } from '../../../utils/blueprints.js';
|
|
8
|
-
import { createFiles } from '../../../utils/files.js';
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = dirname(__filename);
|
|
12
|
-
|
|
13
|
-
function getBlueprintRoot() {
|
|
14
|
-
const codemodRoot = join(__dirname, '../../../..');
|
|
15
|
-
|
|
16
|
-
return join(codemodRoot, 'src/blueprints/ember-addon');
|
|
17
|
-
}
|
|
4
|
+
import { blueprintsRoot, processTemplate } from '../../../utils/blueprints.js';
|
|
5
|
+
import { createFiles, findFiles } from '../../../utils/files.js';
|
|
18
6
|
|
|
19
7
|
function getFilePath(blueprintFilePath, options) {
|
|
20
8
|
const { locations } = options;
|
|
@@ -43,15 +31,12 @@ function getFilesToSkip(options) {
|
|
|
43
31
|
}
|
|
44
32
|
|
|
45
33
|
export function createFilesFromBlueprint(context, options) {
|
|
46
|
-
const blueprintRoot = getBlueprintRoot();
|
|
47
|
-
|
|
48
34
|
const filesToSkip = getFilesToSkip(options);
|
|
35
|
+
const emberAddonBlueprintsRoot = join(blueprintsRoot, 'ember-addon');
|
|
49
36
|
|
|
50
|
-
const blueprintFilePaths =
|
|
51
|
-
cwd:
|
|
52
|
-
|
|
53
|
-
ignore: filesToSkip,
|
|
54
|
-
nodir: true,
|
|
37
|
+
const blueprintFilePaths = findFiles('**/*', {
|
|
38
|
+
cwd: emberAddonBlueprintsRoot,
|
|
39
|
+
ignoreList: filesToSkip,
|
|
55
40
|
});
|
|
56
41
|
|
|
57
42
|
const fileMapping = new Map(
|
|
@@ -59,8 +44,8 @@ export function createFilesFromBlueprint(context, options) {
|
|
|
59
44
|
const filePath = getFilePath(blueprintFilePath, options);
|
|
60
45
|
|
|
61
46
|
const blueprintFile = readFileSync(
|
|
62
|
-
join(
|
|
63
|
-
'utf8'
|
|
47
|
+
join(emberAddonBlueprintsRoot, blueprintFilePath),
|
|
48
|
+
'utf8',
|
|
64
49
|
);
|
|
65
50
|
|
|
66
51
|
const file = processTemplate(blueprintFile, {
|
|
@@ -69,7 +54,7 @@ export function createFilesFromBlueprint(context, options) {
|
|
|
69
54
|
});
|
|
70
55
|
|
|
71
56
|
return [filePath, file];
|
|
72
|
-
})
|
|
57
|
+
}),
|
|
73
58
|
);
|
|
74
59
|
|
|
75
60
|
createFiles(fileMapping, options);
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { findFiles, unionize } from '../../../utils/files.js';
|
|
5
|
+
|
|
6
|
+
function validatePackageJson({ name, version }) {
|
|
7
|
+
if (!name) {
|
|
8
|
+
throw new SyntaxError('Package name is missing.');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (name.includes('/')) {
|
|
12
|
+
// eslint-disable-next-line no-unused-vars
|
|
13
|
+
const [_scope, packageName] = name.split('/');
|
|
14
|
+
|
|
15
|
+
if (!packageName) {
|
|
16
|
+
throw new SyntaxError('Package name is missing.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!version) {
|
|
21
|
+
throw new SyntaxError('Package version is missing.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
5
24
|
|
|
6
25
|
function analyzePackageJson(codemodOptions) {
|
|
7
26
|
const { projectRoot } = codemodOptions;
|
|
@@ -9,7 +28,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
9
28
|
try {
|
|
10
29
|
const packageJsonFile = readFileSync(
|
|
11
30
|
join(projectRoot, 'package.json'),
|
|
12
|
-
'utf8'
|
|
31
|
+
'utf8',
|
|
13
32
|
);
|
|
14
33
|
|
|
15
34
|
const {
|
|
@@ -20,13 +39,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
20
39
|
version,
|
|
21
40
|
} = JSON.parse(packageJsonFile);
|
|
22
41
|
|
|
23
|
-
|
|
24
|
-
throw new SyntaxError('Package name is missing.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!version) {
|
|
28
|
-
throw new SyntaxError('Package version is missing.');
|
|
29
|
-
}
|
|
42
|
+
validatePackageJson({ name, version });
|
|
30
43
|
|
|
31
44
|
const projectDependencies = new Map([
|
|
32
45
|
...Object.entries(dependencies ?? {}),
|
|
@@ -43,7 +56,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
43
56
|
};
|
|
44
57
|
} catch (e) {
|
|
45
58
|
throw new SyntaxError(
|
|
46
|
-
`ERROR: package.json is missing or is not valid. (${e.message})\n
|
|
59
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`,
|
|
47
60
|
);
|
|
48
61
|
}
|
|
49
62
|
}
|
|
@@ -51,11 +64,19 @@ function analyzePackageJson(codemodOptions) {
|
|
|
51
64
|
function analyzePackageManager(codemodOptions) {
|
|
52
65
|
const { projectRoot } = codemodOptions;
|
|
53
66
|
|
|
54
|
-
const
|
|
67
|
+
const mapping = new Map([
|
|
68
|
+
['package-lock.json', 'npm'],
|
|
69
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
70
|
+
['yarn.lock', 'yarn'],
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
const lockFiles = [...mapping.keys()];
|
|
74
|
+
|
|
75
|
+
const filePaths = findFiles(unionize(lockFiles), {
|
|
55
76
|
cwd: projectRoot,
|
|
56
77
|
});
|
|
57
78
|
|
|
58
|
-
if (
|
|
79
|
+
if (filePaths.length !== 1) {
|
|
59
80
|
console.warn('WARNING: Package manager is unknown. Yarn will be assumed.');
|
|
60
81
|
|
|
61
82
|
return {
|
|
@@ -65,29 +86,24 @@ function analyzePackageManager(codemodOptions) {
|
|
|
65
86
|
};
|
|
66
87
|
}
|
|
67
88
|
|
|
68
|
-
const
|
|
89
|
+
const packageManager = mapping.get(filePaths[0]);
|
|
69
90
|
|
|
70
91
|
return {
|
|
71
|
-
isNpm:
|
|
72
|
-
isPnpm:
|
|
73
|
-
isYarn:
|
|
92
|
+
isNpm: packageManager === 'npm',
|
|
93
|
+
isPnpm: packageManager === 'pnpm',
|
|
94
|
+
isYarn: packageManager === 'yarn',
|
|
74
95
|
};
|
|
75
96
|
}
|
|
76
97
|
|
|
77
98
|
function deriveAddonLocation(addonPackage) {
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
const hasScope = addonPackage.name.includes('/');
|
|
100
|
+
|
|
101
|
+
if (!hasScope) {
|
|
80
102
|
return addonPackage.name;
|
|
81
103
|
}
|
|
82
104
|
|
|
83
105
|
// eslint-disable-next-line no-unused-vars
|
|
84
|
-
const [
|
|
85
|
-
|
|
86
|
-
if (!packageName) {
|
|
87
|
-
throw new SyntaxError(
|
|
88
|
-
`ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
|
|
89
|
-
);
|
|
90
|
-
}
|
|
106
|
+
const [_scope, packageName] = addonPackage.name.split('/');
|
|
91
107
|
|
|
92
108
|
return packageName;
|
|
93
109
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
findFiles,
|
|
3
|
+
mapFilePaths,
|
|
4
|
+
moveFiles,
|
|
5
|
+
removeFiles,
|
|
6
|
+
} from '../../../utils/files.js';
|
|
4
7
|
|
|
5
8
|
function moveAddonFolder(options) {
|
|
6
9
|
const { locations, projectRoot } = options;
|
|
7
10
|
|
|
8
|
-
const filePaths =
|
|
11
|
+
const filePaths = findFiles('addon/**/*', {
|
|
9
12
|
cwd: projectRoot,
|
|
10
|
-
dot: true,
|
|
11
|
-
nodir: true,
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
const pathMapping = mapFilePaths(filePaths, {
|
|
@@ -22,10 +23,8 @@ function moveAddonFolder(options) {
|
|
|
22
23
|
function moveAddonTestSupportFolder(options) {
|
|
23
24
|
const { locations, projectRoot } = options;
|
|
24
25
|
|
|
25
|
-
const filePaths =
|
|
26
|
+
const filePaths = findFiles('addon-test-support/**/*', {
|
|
26
27
|
cwd: projectRoot,
|
|
27
|
-
dot: true,
|
|
28
|
-
nodir: true,
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
const pathMapping = mapFilePaths(filePaths, {
|
|
@@ -39,10 +38,8 @@ function moveAddonTestSupportFolder(options) {
|
|
|
39
38
|
function moveBlueprintsFolder(options) {
|
|
40
39
|
const { locations, projectRoot } = options;
|
|
41
40
|
|
|
42
|
-
const filePaths =
|
|
41
|
+
const filePaths = findFiles('blueprints/**/*', {
|
|
43
42
|
cwd: projectRoot,
|
|
44
|
-
dot: true,
|
|
45
|
-
nodir: true,
|
|
46
43
|
});
|
|
47
44
|
|
|
48
45
|
const pathMapping = mapFilePaths(filePaths, {
|
|
@@ -56,10 +53,8 @@ function moveBlueprintsFolder(options) {
|
|
|
56
53
|
function movePublicFolder(options) {
|
|
57
54
|
const { locations, projectRoot } = options;
|
|
58
55
|
|
|
59
|
-
const filePaths =
|
|
56
|
+
const filePaths = findFiles('public/**/*', {
|
|
60
57
|
cwd: projectRoot,
|
|
61
|
-
dot: true,
|
|
62
|
-
nodir: true,
|
|
63
58
|
});
|
|
64
59
|
|
|
65
60
|
const pathMapping = mapFilePaths(filePaths, {
|
|
@@ -73,10 +68,8 @@ function movePublicFolder(options) {
|
|
|
73
68
|
function removeAppFolder(options) {
|
|
74
69
|
const { projectRoot } = options;
|
|
75
70
|
|
|
76
|
-
const filePaths =
|
|
71
|
+
const filePaths = findFiles('app/**/*', {
|
|
77
72
|
cwd: projectRoot,
|
|
78
|
-
dot: true,
|
|
79
|
-
nodir: true,
|
|
80
73
|
});
|
|
81
74
|
|
|
82
75
|
removeFiles(filePaths, options);
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import { globSync } from 'glob';
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
copyFiles,
|
|
3
|
+
findFiles,
|
|
5
4
|
mapFilePaths,
|
|
6
5
|
moveFiles,
|
|
7
6
|
removeFiles,
|
|
7
|
+
unionize,
|
|
8
8
|
} from '../../../utils/files.js';
|
|
9
9
|
|
|
10
|
-
function globPattern(files) {
|
|
11
|
-
if (files.length <= 1) {
|
|
12
|
-
return files.join(',');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return `{${files.join(',')}}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
10
|
function copyToAddon(options) {
|
|
19
11
|
const { locations, projectRoot } = options;
|
|
20
12
|
|
|
21
13
|
const files = ['LICENSE.md', 'README.md'];
|
|
22
14
|
|
|
23
|
-
const filePaths =
|
|
15
|
+
const filePaths = findFiles(unionize(files), {
|
|
24
16
|
cwd: projectRoot,
|
|
25
17
|
});
|
|
26
18
|
|
|
@@ -55,7 +47,7 @@ function moveToAddonAndTestApp(options) {
|
|
|
55
47
|
files.add('tsconfig.json');
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
const filePaths =
|
|
50
|
+
const filePaths = findFiles(unionize([...files]), {
|
|
59
51
|
cwd: projectRoot,
|
|
60
52
|
});
|
|
61
53
|
|
|
@@ -86,7 +78,7 @@ function moveToTestApp(options) {
|
|
|
86
78
|
'testem.js',
|
|
87
79
|
];
|
|
88
80
|
|
|
89
|
-
const filePaths =
|
|
81
|
+
const filePaths = findFiles(unionize(files), {
|
|
90
82
|
cwd: projectRoot,
|
|
91
83
|
});
|
|
92
84
|
|
|
@@ -103,7 +95,7 @@ function removeFromProjectRoot(options) {
|
|
|
103
95
|
|
|
104
96
|
const files = ['.npmignore', 'index.js'];
|
|
105
97
|
|
|
106
|
-
const filePaths =
|
|
98
|
+
const filePaths = findFiles(unionize(files), {
|
|
107
99
|
cwd: projectRoot,
|
|
108
100
|
});
|
|
109
101
|
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { mapFilePaths, moveFiles } from '../../../utils/files.js';
|
|
4
|
+
import { findFiles, mapFilePaths, moveFiles } from '../../../utils/files.js';
|
|
7
5
|
|
|
8
6
|
function moveTestsFolder(options) {
|
|
9
7
|
const { locations, projectRoot } = options;
|
|
10
8
|
|
|
11
|
-
let filePaths =
|
|
9
|
+
let filePaths = findFiles('tests/dummy/**/*', {
|
|
12
10
|
cwd: projectRoot,
|
|
13
|
-
dot: true,
|
|
14
|
-
nodir: true,
|
|
15
11
|
});
|
|
16
12
|
|
|
17
13
|
let pathMapping = mapFilePaths(filePaths, {
|
|
@@ -21,11 +17,9 @@ function moveTestsFolder(options) {
|
|
|
21
17
|
|
|
22
18
|
moveFiles(pathMapping, options);
|
|
23
19
|
|
|
24
|
-
filePaths =
|
|
20
|
+
filePaths = findFiles('tests/**/*', {
|
|
25
21
|
cwd: projectRoot,
|
|
26
|
-
|
|
27
|
-
ignore: 'tests/dummy/**/*',
|
|
28
|
-
nodir: true,
|
|
22
|
+
ignoreList: ['tests/dummy/**/*'],
|
|
29
23
|
});
|
|
30
24
|
|
|
31
25
|
pathMapping = mapFilePaths(filePaths, {
|
|
@@ -43,10 +37,8 @@ function moveTypesFolder(options) {
|
|
|
43
37
|
return;
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
let filePaths =
|
|
40
|
+
let filePaths = findFiles('types/dummy/**/*', {
|
|
47
41
|
cwd: projectRoot,
|
|
48
|
-
dot: true,
|
|
49
|
-
nodir: true,
|
|
50
42
|
});
|
|
51
43
|
|
|
52
44
|
let pathMapping = mapFilePaths(filePaths, {
|
|
@@ -56,11 +48,9 @@ function moveTypesFolder(options) {
|
|
|
56
48
|
|
|
57
49
|
moveFiles(pathMapping, options);
|
|
58
50
|
|
|
59
|
-
filePaths =
|
|
51
|
+
filePaths = findFiles('types/**/*', {
|
|
60
52
|
cwd: projectRoot,
|
|
61
|
-
|
|
62
|
-
ignore: 'types/dummy/**/*',
|
|
63
|
-
nodir: true,
|
|
53
|
+
ignoreList: ['types/dummy/**/*'],
|
|
64
54
|
});
|
|
65
55
|
|
|
66
56
|
pathMapping = mapFilePaths(filePaths, {
|
|
@@ -76,10 +66,8 @@ function renameDummy(options) {
|
|
|
76
66
|
|
|
77
67
|
// File extensions had been specified, partly to encode assumptions
|
|
78
68
|
// about Ember, and partly to avoid corrupting non-text files
|
|
79
|
-
const filePaths =
|
|
69
|
+
const filePaths = findFiles(`${locations.testApp}/**/*.{d.ts,html,js,ts}`, {
|
|
80
70
|
cwd: projectRoot,
|
|
81
|
-
dot: true,
|
|
82
|
-
nodir: true,
|
|
83
71
|
});
|
|
84
72
|
|
|
85
73
|
filePaths.forEach((filePath) => {
|
|
@@ -88,7 +76,7 @@ function renameDummy(options) {
|
|
|
88
76
|
|
|
89
77
|
const newFile = oldFile.replace(
|
|
90
78
|
new RegExp('dummy', 'g'),
|
|
91
|
-
packages.testApp.name
|
|
79
|
+
packages.testApp.name,
|
|
92
80
|
);
|
|
93
81
|
|
|
94
82
|
writeFileSync(oldPath, newFile, 'utf8');
|
|
@@ -85,7 +85,7 @@ function updateOtherFields(packageJson, context, options) {
|
|
|
85
85
|
|
|
86
86
|
return accumulator;
|
|
87
87
|
},
|
|
88
|
-
{}
|
|
88
|
+
{},
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
packageJson['ember-addon'] = {
|
|
@@ -108,6 +108,9 @@ function updateOtherFields(packageJson, context, options) {
|
|
|
108
108
|
packageJson['exports'] = {
|
|
109
109
|
'.': './dist/index.js',
|
|
110
110
|
'./*': {
|
|
111
|
+
/*
|
|
112
|
+
This object has an order dependency. The `default` key must appear last.
|
|
113
|
+
*/
|
|
111
114
|
types: './dist/*.d.ts',
|
|
112
115
|
default: './dist/*.js',
|
|
113
116
|
},
|
|
@@ -144,7 +147,7 @@ function updateScripts(packageJson) {
|
|
|
144
147
|
scripts.set('start', 'rollup --config --watch');
|
|
145
148
|
scripts.set(
|
|
146
149
|
'test',
|
|
147
|
-
"echo 'A v2 addon does not have tests, run tests in test-app'"
|
|
150
|
+
"echo 'A v2 addon does not have tests, run tests in test-app'",
|
|
148
151
|
);
|
|
149
152
|
|
|
150
153
|
packageJson['scripts'] = convertToObject(scripts);
|
|
@@ -63,7 +63,7 @@ function updateOtherFields(packageJson, options) {
|
|
|
63
63
|
delete packageJson['ember-addon'];
|
|
64
64
|
|
|
65
65
|
packageJson['keywords'] = (packageJson['keywords'] ?? []).filter(
|
|
66
|
-
(keyword) => keyword !== 'ember-addon'
|
|
66
|
+
(keyword) => keyword !== 'ember-addon',
|
|
67
67
|
);
|
|
68
68
|
|
|
69
69
|
packageJson['name'] = packages.testApp.name;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
|
|
7
|
+
function getBlueprintsRoot() {
|
|
8
|
+
const srcDirectory = join(__dirname, '../..');
|
|
9
|
+
|
|
10
|
+
return join(srcDirectory, 'blueprints');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const blueprintsRoot = getBlueprintsRoot();
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
const latestVersions = new Map([
|
|
2
|
-
['@babel/core', '7.21.
|
|
2
|
+
['@babel/core', '7.21.4'],
|
|
3
3
|
['@babel/plugin-proposal-class-properties', '7.18.6'],
|
|
4
4
|
['@babel/plugin-proposal-decorators', '7.21.0'],
|
|
5
|
-
['@babel/preset-typescript', '7.21.
|
|
5
|
+
['@babel/preset-typescript', '7.21.4'],
|
|
6
6
|
['@embroider/addon-dev', '3.0.0'],
|
|
7
7
|
['@embroider/addon-shim', '1.8.4'],
|
|
8
8
|
['@rollup/plugin-babel', '6.0.3'],
|
|
9
|
-
['concurrently', '
|
|
10
|
-
['ember-auto-import', '2.6.
|
|
9
|
+
['concurrently', '8.0.1'],
|
|
10
|
+
['ember-auto-import', '2.6.3'],
|
|
11
11
|
['ember-cli-babel', '7.26.11'],
|
|
12
12
|
['ember-cli-htmlbars', '6.2.0'],
|
|
13
|
-
['
|
|
14
|
-
['rollup', '3.18.0'],
|
|
13
|
+
['rollup', '3.21.0'],
|
|
15
14
|
['rollup-plugin-copy', '3.4.0'],
|
|
16
15
|
['rollup-plugin-ts', '3.2.0'],
|
|
17
16
|
]);
|
|
@@ -29,7 +28,7 @@ export function decideVersion(packageName, options) {
|
|
|
29
28
|
|
|
30
29
|
if (!latestVersion) {
|
|
31
30
|
throw new RangeError(
|
|
32
|
-
`ERROR: The latest version of \`${packageName}\` is unknown.\n
|
|
31
|
+
`ERROR: The latest version of \`${packageName}\` is unknown.\n`,
|
|
33
32
|
);
|
|
34
33
|
}
|
|
35
34
|
|
package/src/utils/blueprints.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { globSync } from 'glob';
|
|
2
|
+
|
|
3
|
+
export function findFiles(pattern, { cwd, ignoreList = [] }) {
|
|
4
|
+
if (!pattern) {
|
|
5
|
+
throw new RangeError('ERROR: The glob pattern is unknown.\n');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!cwd) {
|
|
9
|
+
throw new RangeError('ERROR: The current working directory is unknown.\n');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const filePaths = globSync(pattern, {
|
|
13
|
+
cwd,
|
|
14
|
+
dot: true,
|
|
15
|
+
ignore: ignoreList,
|
|
16
|
+
nodir: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return filePaths;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function unionize(files) {
|
|
23
|
+
if (files.length <= 1) {
|
|
24
|
+
return files.join(',');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return `{${files.join(',')}}`;
|
|
28
|
+
}
|
package/src/utils/files.js
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# unconventional js
|
|
2
|
-
/blueprints/*/files/
|
|
3
|
-
/vendor/
|
|
4
|
-
|
|
5
|
-
# compiled output
|
|
6
|
-
/dist/
|
|
7
|
-
/tmp/
|
|
8
|
-
|
|
9
|
-
# dependencies
|
|
10
|
-
/bower_components/
|
|
11
|
-
/node_modules/
|
|
12
|
-
|
|
13
|
-
# misc
|
|
14
|
-
/coverage/
|
|
15
|
-
!.*
|
|
16
|
-
.eslintcache
|
|
17
|
-
.lint-todo/
|
|
18
|
-
|
|
19
|
-
# ember-try
|
|
20
|
-
/.node_modules.ember-try/
|
|
21
|
-
/bower.json.ember-try
|
|
22
|
-
/npm-shrinkwrap.json.ember-try
|
|
23
|
-
/package.json.ember-try
|
|
24
|
-
/package-lock.json.ember-try
|
|
25
|
-
/yarn.lock.ember-try
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join, relative } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { globSync } from 'glob';
|
|
5
|
-
|
|
6
|
-
function normalizeRelativePath(relativePath) {
|
|
7
|
-
if (!relativePath.startsWith('..')) {
|
|
8
|
-
return `./${relativePath}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return relativePath;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function updateFile(oldFile, { filePath, projectName, projectRoot }) {
|
|
15
|
-
const regex = new RegExp(`(?:'|")(${projectName}/(.*/)*(.*))(?:'|")`, 'g');
|
|
16
|
-
const matchResults = [...oldFile.matchAll(regex)];
|
|
17
|
-
|
|
18
|
-
let newFile = oldFile;
|
|
19
|
-
|
|
20
|
-
matchResults.forEach((matchResult) => {
|
|
21
|
-
// eslint-disable-next-line no-unused-vars
|
|
22
|
-
const [_, oldPath, remainingDirectories, fileName] = matchResult;
|
|
23
|
-
|
|
24
|
-
const from = dirname(filePath);
|
|
25
|
-
const to = join(projectRoot, remainingDirectories);
|
|
26
|
-
|
|
27
|
-
const relativePath = join(relative(from, to), fileName);
|
|
28
|
-
const newPath = normalizeRelativePath(relativePath);
|
|
29
|
-
|
|
30
|
-
newFile = newFile.replace(oldPath, newPath);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return newFile;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function useRelativePathInAddonFolder(options) {
|
|
37
|
-
const { packages, projectRoot } = options;
|
|
38
|
-
|
|
39
|
-
// File extensions had been specified, partly to encode assumptions
|
|
40
|
-
// about Ember, and partly to avoid corrupting non-text files
|
|
41
|
-
const filePaths = globSync('addon/**/*.{d.ts,js,ts}', {
|
|
42
|
-
cwd: projectRoot,
|
|
43
|
-
dot: true,
|
|
44
|
-
nodir: true,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
filePaths.forEach((filePath) => {
|
|
48
|
-
const oldPath = join(projectRoot, filePath);
|
|
49
|
-
const oldFile = readFileSync(oldPath, 'utf8');
|
|
50
|
-
|
|
51
|
-
const newFile = updateFile(oldFile, {
|
|
52
|
-
filePath,
|
|
53
|
-
projectName: packages.addon.name,
|
|
54
|
-
projectRoot: 'addon',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
writeFileSync(oldPath, newFile, 'utf8');
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function useRelativePathInTestsDummyFolder(options) {
|
|
62
|
-
const { projectRoot } = options;
|
|
63
|
-
|
|
64
|
-
// File extensions had been specified, partly to encode assumptions
|
|
65
|
-
// about Ember, and partly to avoid corrupting non-text files
|
|
66
|
-
const filePaths = globSync('tests/dummy/**/*.{d.ts,js,ts}', {
|
|
67
|
-
cwd: projectRoot,
|
|
68
|
-
dot: true,
|
|
69
|
-
nodir: true,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
filePaths.forEach((filePath) => {
|
|
73
|
-
const oldPath = join(projectRoot, filePath);
|
|
74
|
-
const oldFile = readFileSync(oldPath, 'utf8');
|
|
75
|
-
|
|
76
|
-
const newFile = updateFile(oldFile, {
|
|
77
|
-
filePath,
|
|
78
|
-
projectName: 'dummy',
|
|
79
|
-
projectRoot: 'tests/dummy/app',
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
writeFileSync(oldPath, newFile, 'utf8');
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function useRelativePaths(options) {
|
|
87
|
-
useRelativePathInAddonFolder(options);
|
|
88
|
-
useRelativePathInTestsDummyFolder(options);
|
|
89
|
-
}
|