ember-codemod-v1-to-v2 0.5.0 → 0.5.2
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 +2 -0
- package/package.json +31 -30
- package/src/migration/ember-addon/steps/analyze-addon.js +4 -3
- package/src/migration/ember-addon/steps/create-files-from-blueprint.js +18 -19
- package/src/migration/ember-addon/steps/create-options.js +22 -58
- package/src/migration/ember-addon/steps/move-addon-files.js +9 -9
- package/src/migration/ember-addon/steps/move-project-root-files.js +9 -9
- package/src/migration/ember-addon/steps/move-test-app-files.js +9 -9
- package/src/migration/ember-addon/steps/update-addon-package-json.js +6 -4
- package/src/migration/ember-addon/steps/update-addon-tsconfig-json.js +3 -5
- package/src/migration/ember-addon/steps/update-test-app-package-json.js +4 -3
- package/src/migration/ember-addon/steps/update-test-app-tsconfig-json.js +3 -5
- package/src/utils/blueprints/blueprints-root.js +5 -10
- package/src/utils/blueprints/get-version.js +28 -0
- package/src/utils/blueprints.js +1 -2
- package/src/utils/json.js +0 -2
- package/src/utils/blueprints/decide-version.js +0 -36
- package/src/utils/blueprints/process-template.js +0 -12
- package/src/utils/files/copy-files.js +0 -19
- package/src/utils/files/create-files.js +0 -17
- package/src/utils/files/find-files.js +0 -28
- package/src/utils/files/map-file-paths.js +0 -25
- package/src/utils/files/move-files.js +0 -22
- package/src/utils/files/remove-directory-if-empty.js +0 -19
- package/src/utils/files/remove-files.js +0 -15
- package/src/utils/files.js +0 -7
- package/src/utils/json/convert-to-map.js +0 -3
- package/src/utils/json/convert-to-object.js +0 -5
package/README.md
CHANGED
|
@@ -115,6 +115,8 @@ You can also look at another codemod called [`ember-addon-migrator`](https://git
|
|
|
115
115
|
|
|
116
116
|
## Contributing
|
|
117
117
|
|
|
118
|
+
See the [Contributing](CONTRIBUTING.md) guide for details.
|
|
119
|
+
|
|
118
120
|
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. ⭐
|
|
119
121
|
|
|
120
122
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-v1-to-v2",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Codemod to convert Ember addons to v2 addon format",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -17,53 +17,54 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": "Isaac J. Lee",
|
|
20
|
-
"main": "src/index.js",
|
|
21
20
|
"type": "module",
|
|
21
|
+
"main": "src/index.js",
|
|
22
22
|
"bin": "./bin/ember-codemod-v1-to-v2.js",
|
|
23
|
+
"directories": {
|
|
24
|
+
"test": "tests"
|
|
25
|
+
},
|
|
23
26
|
"files": [
|
|
24
27
|
"bin/",
|
|
25
28
|
"src/"
|
|
26
29
|
],
|
|
27
|
-
"directories": {
|
|
28
|
-
"test": "tests"
|
|
29
|
-
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"changelog": "lerna-changelog",
|
|
32
|
-
"lint": "eslint . --cache",
|
|
33
|
-
"lint:fix": "eslint . --fix",
|
|
34
|
-
"test": "mt tests --quiet"
|
|
35
|
-
},
|
|
36
|
-
"changelog": {
|
|
37
|
-
"labels": {
|
|
38
|
-
"breaking": "Breaking Change",
|
|
39
|
-
"bug": "Bug Fix",
|
|
40
|
-
"enhance: code": "Enhancement",
|
|
41
|
-
"enhance: dependency": "Internal",
|
|
42
|
-
"enhance: documentation": "Documentation",
|
|
43
|
-
"user feedback": "User Feedback"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
30
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
31
|
+
"@codemod-utils/blueprints": "^0.1.1",
|
|
32
|
+
"@codemod-utils/files": "^0.1.0",
|
|
33
|
+
"@codemod-utils/json": "^0.1.1",
|
|
49
34
|
"strip-json-comments": "^5.0.0",
|
|
50
|
-
"yargs": "^17.7.
|
|
35
|
+
"yargs": "^17.7.2"
|
|
51
36
|
},
|
|
52
37
|
"devDependencies": {
|
|
53
|
-
"@babel/core": "^7.21.
|
|
54
|
-
"@babel/eslint-parser": "^7.21.
|
|
38
|
+
"@babel/core": "^7.21.8",
|
|
39
|
+
"@babel/eslint-parser": "^7.21.8",
|
|
40
|
+
"@codemod-utils/tests": "^0.1.0",
|
|
55
41
|
"@sondr3/minitest": "^0.1.1",
|
|
56
|
-
"eslint": "^8.
|
|
42
|
+
"eslint": "^8.40.0",
|
|
57
43
|
"eslint-config-prettier": "^8.8.0",
|
|
58
44
|
"eslint-plugin-import": "^2.27.5",
|
|
59
|
-
"eslint-plugin-n": "^
|
|
45
|
+
"eslint-plugin-n": "^16.0.0",
|
|
60
46
|
"eslint-plugin-prettier": "^4.2.1",
|
|
61
47
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
62
|
-
"fixturify": "^3.0.0",
|
|
63
48
|
"lerna-changelog": "^2.2.0",
|
|
64
49
|
"prettier": "^2.8.8"
|
|
65
50
|
},
|
|
66
51
|
"engines": {
|
|
67
52
|
"node": ">= 16"
|
|
53
|
+
},
|
|
54
|
+
"changelog": {
|
|
55
|
+
"labels": {
|
|
56
|
+
"breaking": "Breaking Change",
|
|
57
|
+
"bug": "Bug Fix",
|
|
58
|
+
"enhance: code": "Enhancement",
|
|
59
|
+
"enhance: dependency": "Internal",
|
|
60
|
+
"enhance: documentation": "Documentation",
|
|
61
|
+
"user feedback": "User Feedback"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"changelog": "lerna-changelog",
|
|
66
|
+
"lint": "eslint . --cache",
|
|
67
|
+
"lint:fix": "eslint . --fix",
|
|
68
|
+
"test": "mt tests --quiet"
|
|
68
69
|
}
|
|
69
|
-
}
|
|
70
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { findFiles, renameDirectory } from '@codemod-utils/files';
|
|
2
|
+
|
|
3
|
+
import { getVersion } from '../../../utils/blueprints.js';
|
|
3
4
|
|
|
4
5
|
function getAppReexports(options) {
|
|
5
6
|
const { projectRoot } = options;
|
|
@@ -20,7 +21,7 @@ function getAppReexports(options) {
|
|
|
20
21
|
|
|
21
22
|
function getProjectRootDevDependencies(options) {
|
|
22
23
|
return {
|
|
23
|
-
concurrently:
|
|
24
|
+
concurrently: getVersion('concurrently', options),
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { createFiles, findFiles } from '
|
|
4
|
+
import { processTemplate } from '@codemod-utils/blueprints';
|
|
5
|
+
import { createFiles, findFiles } from '@codemod-utils/files';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const { locations } = options;
|
|
9
|
-
|
|
10
|
-
return blueprintFilePath
|
|
11
|
-
.replace('__addonLocation__', locations.addon)
|
|
12
|
-
.replace('__gitignore__', '.gitignore')
|
|
13
|
-
.replace('__testAppLocation__', locations.testApp);
|
|
14
|
-
}
|
|
7
|
+
import { blueprintsRoot } from '../../../utils/blueprints.js';
|
|
15
8
|
|
|
16
9
|
function getFilesToSkip(options) {
|
|
17
10
|
const { packageManager, packages } = options;
|
|
@@ -30,23 +23,29 @@ function getFilesToSkip(options) {
|
|
|
30
23
|
return [...files];
|
|
31
24
|
}
|
|
32
25
|
|
|
26
|
+
function resolveBlueprintFilePath(blueprintFilePath, options) {
|
|
27
|
+
const { locations } = options;
|
|
28
|
+
|
|
29
|
+
return blueprintFilePath
|
|
30
|
+
.replace('__addonLocation__', locations.addon)
|
|
31
|
+
.replace('__gitignore__', '.gitignore')
|
|
32
|
+
.replace('__testAppLocation__', locations.testApp);
|
|
33
|
+
}
|
|
34
|
+
|
|
33
35
|
export function createFilesFromBlueprint(context, options) {
|
|
34
36
|
const filesToSkip = getFilesToSkip(options);
|
|
35
|
-
const
|
|
37
|
+
const cwd = join(blueprintsRoot, 'ember-addon');
|
|
36
38
|
|
|
37
39
|
const blueprintFilePaths = findFiles('**/*', {
|
|
38
|
-
cwd
|
|
40
|
+
cwd,
|
|
39
41
|
ignoreList: filesToSkip,
|
|
40
42
|
});
|
|
41
43
|
|
|
42
|
-
const
|
|
44
|
+
const fileMap = new Map(
|
|
43
45
|
blueprintFilePaths.map((blueprintFilePath) => {
|
|
44
|
-
const filePath =
|
|
46
|
+
const filePath = resolveBlueprintFilePath(blueprintFilePath, options);
|
|
45
47
|
|
|
46
|
-
const blueprintFile = readFileSync(
|
|
47
|
-
join(emberAddonBlueprintsRoot, blueprintFilePath),
|
|
48
|
-
'utf8',
|
|
49
|
-
);
|
|
48
|
+
const blueprintFile = readFileSync(join(cwd, blueprintFilePath), 'utf8');
|
|
50
49
|
|
|
51
50
|
const file = processTemplate(blueprintFile, {
|
|
52
51
|
context,
|
|
@@ -57,5 +56,5 @@ export function createFilesFromBlueprint(context, options) {
|
|
|
57
56
|
}),
|
|
58
57
|
);
|
|
59
58
|
|
|
60
|
-
createFiles(
|
|
59
|
+
createFiles(fileMap, options);
|
|
61
60
|
}
|
|
@@ -1,64 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
}
|
|
1
|
+
import { findFiles, unionize } from '@codemod-utils/files';
|
|
2
|
+
import { readPackageJson } from '@codemod-utils/json';
|
|
24
3
|
|
|
25
4
|
function analyzePackageJson(codemodOptions) {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
name,
|
|
39
|
-
version,
|
|
40
|
-
} = JSON.parse(packageJsonFile);
|
|
41
|
-
|
|
42
|
-
validatePackageJson({ name, version });
|
|
43
|
-
|
|
44
|
-
const projectDependencies = new Map([
|
|
45
|
-
...Object.entries(dependencies ?? {}),
|
|
46
|
-
...Object.entries(devDependencies ?? {}),
|
|
47
|
-
]);
|
|
5
|
+
const {
|
|
6
|
+
dependencies,
|
|
7
|
+
devDependencies,
|
|
8
|
+
'ember-addon': emberAddon,
|
|
9
|
+
name,
|
|
10
|
+
version,
|
|
11
|
+
} = readPackageJson(codemodOptions);
|
|
12
|
+
|
|
13
|
+
const projectDependencies = new Map([
|
|
14
|
+
...Object.entries(dependencies ?? {}),
|
|
15
|
+
...Object.entries(devDependencies ?? {}),
|
|
16
|
+
]);
|
|
48
17
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} catch (e) {
|
|
58
|
-
throw new SyntaxError(
|
|
59
|
-
`ERROR: package.json is missing or is not valid. (${e.message})\n`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
18
|
+
return {
|
|
19
|
+
dependencies: projectDependencies,
|
|
20
|
+
hasGlint: projectDependencies.has('@glint/core'),
|
|
21
|
+
hasTypeScript: projectDependencies.has('typescript'),
|
|
22
|
+
isV1Addon: Boolean(emberAddon),
|
|
23
|
+
name,
|
|
24
|
+
version,
|
|
25
|
+
};
|
|
62
26
|
}
|
|
63
27
|
|
|
64
28
|
function analyzePackageManager(codemodOptions) {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
mapFilePaths,
|
|
4
4
|
moveFiles,
|
|
5
5
|
removeFiles,
|
|
6
|
-
} from '
|
|
6
|
+
} from '@codemod-utils/files';
|
|
7
7
|
|
|
8
8
|
function moveAddonFolder(options) {
|
|
9
9
|
const { locations, projectRoot } = options;
|
|
@@ -12,12 +12,12 @@ function moveAddonFolder(options) {
|
|
|
12
12
|
cwd: projectRoot,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
16
16
|
from: 'addon',
|
|
17
17
|
to: `${locations.addon}/src`,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
moveFiles(
|
|
20
|
+
moveFiles(filePathMap, options);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function moveAddonTestSupportFolder(options) {
|
|
@@ -27,12 +27,12 @@ function moveAddonTestSupportFolder(options) {
|
|
|
27
27
|
cwd: projectRoot,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
31
31
|
from: 'addon-test-support',
|
|
32
32
|
to: `${locations.addon}/src/test-support`,
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
moveFiles(
|
|
35
|
+
moveFiles(filePathMap, options);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function moveBlueprintsFolder(options) {
|
|
@@ -42,12 +42,12 @@ function moveBlueprintsFolder(options) {
|
|
|
42
42
|
cwd: projectRoot,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
46
46
|
from: 'blueprints',
|
|
47
47
|
to: `${locations.addon}/blueprints`,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
moveFiles(
|
|
50
|
+
moveFiles(filePathMap, options);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function movePublicFolder(options) {
|
|
@@ -57,12 +57,12 @@ function movePublicFolder(options) {
|
|
|
57
57
|
cwd: projectRoot,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
const
|
|
60
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
61
61
|
from: 'public',
|
|
62
62
|
to: `${locations.addon}/public`,
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
moveFiles(
|
|
65
|
+
moveFiles(filePathMap, options);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
function removeAppFolder(options) {
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
moveFiles,
|
|
6
6
|
removeFiles,
|
|
7
7
|
unionize,
|
|
8
|
-
} from '
|
|
8
|
+
} from '@codemod-utils/files';
|
|
9
9
|
|
|
10
10
|
function copyToAddon(options) {
|
|
11
11
|
const { locations, projectRoot } = options;
|
|
@@ -16,12 +16,12 @@ function copyToAddon(options) {
|
|
|
16
16
|
cwd: projectRoot,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
20
20
|
from: '',
|
|
21
21
|
to: locations.addon,
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
copyFiles(
|
|
24
|
+
copyFiles(filePathMap, options);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function moveToAddonAndTestApp(options) {
|
|
@@ -51,19 +51,19 @@ function moveToAddonAndTestApp(options) {
|
|
|
51
51
|
cwd: projectRoot,
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
let
|
|
54
|
+
let filePathMap = mapFilePaths(filePaths, {
|
|
55
55
|
from: '',
|
|
56
56
|
to: locations.addon,
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
copyFiles(
|
|
59
|
+
copyFiles(filePathMap, options);
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
filePathMap = mapFilePaths(filePaths, {
|
|
62
62
|
from: '',
|
|
63
63
|
to: locations.testApp,
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
copyFiles(
|
|
66
|
+
copyFiles(filePathMap, options);
|
|
67
67
|
|
|
68
68
|
removeFiles(filePaths, options);
|
|
69
69
|
}
|
|
@@ -82,12 +82,12 @@ function moveToTestApp(options) {
|
|
|
82
82
|
cwd: projectRoot,
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
const
|
|
85
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
86
86
|
from: '',
|
|
87
87
|
to: locations.testApp,
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
moveFiles(
|
|
90
|
+
moveFiles(filePathMap, options);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
function removeFromProjectRoot(options) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { findFiles, mapFilePaths, moveFiles } from '
|
|
4
|
+
import { findFiles, mapFilePaths, moveFiles } from '@codemod-utils/files';
|
|
5
5
|
|
|
6
6
|
function moveTestsFolder(options) {
|
|
7
7
|
const { locations, projectRoot } = options;
|
|
@@ -10,24 +10,24 @@ function moveTestsFolder(options) {
|
|
|
10
10
|
cwd: projectRoot,
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
let
|
|
13
|
+
let filePathMap = mapFilePaths(filePaths, {
|
|
14
14
|
from: 'tests/dummy',
|
|
15
15
|
to: locations.testApp,
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
moveFiles(
|
|
18
|
+
moveFiles(filePathMap, options);
|
|
19
19
|
|
|
20
20
|
filePaths = findFiles('tests/**/*', {
|
|
21
21
|
cwd: projectRoot,
|
|
22
22
|
ignoreList: ['tests/dummy/**/*'],
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
filePathMap = mapFilePaths(filePaths, {
|
|
26
26
|
from: 'tests',
|
|
27
27
|
to: `${locations.testApp}/tests`,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
moveFiles(
|
|
30
|
+
moveFiles(filePathMap, options);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function moveTypesFolder(options) {
|
|
@@ -41,24 +41,24 @@ function moveTypesFolder(options) {
|
|
|
41
41
|
cwd: projectRoot,
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
let
|
|
44
|
+
let filePathMap = mapFilePaths(filePaths, {
|
|
45
45
|
from: 'types/dummy',
|
|
46
46
|
to: `${locations.testApp}/types/${packages.testApp.name}`,
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
moveFiles(
|
|
49
|
+
moveFiles(filePathMap, options);
|
|
50
50
|
|
|
51
51
|
filePaths = findFiles('types/**/*', {
|
|
52
52
|
cwd: projectRoot,
|
|
53
53
|
ignoreList: ['types/dummy/**/*'],
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
filePathMap = mapFilePaths(filePaths, {
|
|
57
57
|
from: 'types',
|
|
58
58
|
to: `${locations.testApp}/types`,
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
moveFiles(
|
|
61
|
+
moveFiles(filePathMap, options);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function renameDummy(options) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
5
|
+
|
|
6
|
+
import { getVersion } from '../../../utils/blueprints.js';
|
|
6
7
|
|
|
7
8
|
function updateDependencies(packageJson, options) {
|
|
8
9
|
const dependencies = convertToMap(packageJson['dependencies']);
|
|
@@ -21,7 +22,7 @@ function updateDependencies(packageJson, options) {
|
|
|
21
22
|
const packagesToInstall = ['@embroider/addon-shim'];
|
|
22
23
|
|
|
23
24
|
packagesToInstall.sort().forEach((packageName) => {
|
|
24
|
-
const version =
|
|
25
|
+
const version = getVersion(packageName, options);
|
|
25
26
|
|
|
26
27
|
dependencies.set(packageName, version);
|
|
27
28
|
});
|
|
@@ -50,6 +51,7 @@ function updateDevDependencies(packageJson, options) {
|
|
|
50
51
|
'@babel/core',
|
|
51
52
|
'@babel/plugin-proposal-class-properties',
|
|
52
53
|
'@babel/plugin-proposal-decorators',
|
|
54
|
+
'@babel/runtime',
|
|
53
55
|
'@embroider/addon-dev',
|
|
54
56
|
'@rollup/plugin-babel',
|
|
55
57
|
'rollup',
|
|
@@ -63,7 +65,7 @@ function updateDevDependencies(packageJson, options) {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
[...packagesToInstall].sort().forEach((packageName) => {
|
|
66
|
-
const version =
|
|
68
|
+
const version = getVersion(packageName, options);
|
|
67
69
|
|
|
68
70
|
devDependencies.set(packageName, version);
|
|
69
71
|
});
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sanitizeJson,
|
|
8
|
-
} from '../../../utils/json.js';
|
|
4
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
5
|
+
|
|
6
|
+
import { sanitizeJson } from '../../../utils/json.js';
|
|
9
7
|
|
|
10
8
|
function updateCompilerOptions(tsconfigJson) {
|
|
11
9
|
const compilerOptions = convertToMap(tsconfigJson['compilerOptions']);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
5
|
+
|
|
6
|
+
import { getVersion } from '../../../utils/blueprints.js';
|
|
6
7
|
|
|
7
8
|
function moveDependenciesToDevDependencies(packageJson, options) {
|
|
8
9
|
const { packages } = options;
|
|
@@ -24,7 +25,7 @@ function moveDependenciesToDevDependencies(packageJson, options) {
|
|
|
24
25
|
.filter((packageName) => dependencies.has(packageName))
|
|
25
26
|
.sort()
|
|
26
27
|
.forEach((packageName) => {
|
|
27
|
-
const version =
|
|
28
|
+
const version = getVersion(packageName, options);
|
|
28
29
|
|
|
29
30
|
devDependencies.set(packageName, version);
|
|
30
31
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sanitizeJson,
|
|
8
|
-
} from '../../../utils/json.js';
|
|
4
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
5
|
+
|
|
6
|
+
import { sanitizeJson } from '../../../utils/json.js';
|
|
9
7
|
|
|
10
8
|
function updateCompilerOptions(tsconfigJson, options) {
|
|
11
9
|
const { packages } = options;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
1
|
+
import { join } from 'node:path';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
const __dirname = dirname(__filename);
|
|
3
|
+
import { getFilePath } from '@codemod-utils/blueprints';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const fileURL = import.meta.url;
|
|
6
|
+
const srcDirectory = join(getFilePath(fileURL), '../..');
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const blueprintsRoot = getBlueprintsRoot();
|
|
8
|
+
export const blueprintsRoot = join(srcDirectory, 'blueprints');
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { decideVersion } from '@codemod-utils/blueprints';
|
|
2
|
+
|
|
3
|
+
const latestVersions = new Map([
|
|
4
|
+
['@babel/core', '7.21.8'],
|
|
5
|
+
['@babel/plugin-proposal-class-properties', '7.18.6'],
|
|
6
|
+
['@babel/plugin-proposal-decorators', '7.21.0'],
|
|
7
|
+
['@babel/preset-typescript', '7.21.5'],
|
|
8
|
+
['@babel/runtime', '7.21.5'],
|
|
9
|
+
['@embroider/addon-dev', '3.0.0'],
|
|
10
|
+
['@embroider/addon-shim', '1.8.4'],
|
|
11
|
+
['@rollup/plugin-babel', '6.0.3'],
|
|
12
|
+
['concurrently', '8.0.1'],
|
|
13
|
+
['ember-auto-import', '2.6.3'],
|
|
14
|
+
['ember-cli-babel', '7.26.11'],
|
|
15
|
+
['ember-cli-htmlbars', '6.2.0'],
|
|
16
|
+
['rollup', '3.21.3'],
|
|
17
|
+
['rollup-plugin-copy', '3.4.0'],
|
|
18
|
+
['rollup-plugin-ts', '3.2.0'],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export function getVersion(packageName, options) {
|
|
22
|
+
const { packages } = options;
|
|
23
|
+
|
|
24
|
+
return decideVersion(packageName, {
|
|
25
|
+
dependencies: packages.addon.dependencies,
|
|
26
|
+
latestVersions,
|
|
27
|
+
});
|
|
28
|
+
}
|
package/src/utils/blueprints.js
CHANGED
package/src/utils/json.js
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const latestVersions = new Map([
|
|
2
|
-
['@babel/core', '7.21.4'],
|
|
3
|
-
['@babel/plugin-proposal-class-properties', '7.18.6'],
|
|
4
|
-
['@babel/plugin-proposal-decorators', '7.21.0'],
|
|
5
|
-
['@babel/preset-typescript', '7.21.4'],
|
|
6
|
-
['@embroider/addon-dev', '3.0.0'],
|
|
7
|
-
['@embroider/addon-shim', '1.8.4'],
|
|
8
|
-
['@rollup/plugin-babel', '6.0.3'],
|
|
9
|
-
['concurrently', '8.0.1'],
|
|
10
|
-
['ember-auto-import', '2.6.3'],
|
|
11
|
-
['ember-cli-babel', '7.26.11'],
|
|
12
|
-
['ember-cli-htmlbars', '6.2.0'],
|
|
13
|
-
['rollup', '3.21.0'],
|
|
14
|
-
['rollup-plugin-copy', '3.4.0'],
|
|
15
|
-
['rollup-plugin-ts', '3.2.0'],
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
export function decideVersion(packageName, options) {
|
|
19
|
-
const { packages } = options;
|
|
20
|
-
|
|
21
|
-
const installedVersion = packages.addon.dependencies.get(packageName);
|
|
22
|
-
|
|
23
|
-
if (installedVersion) {
|
|
24
|
-
return installedVersion;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const latestVersion = latestVersions.get(packageName);
|
|
28
|
-
|
|
29
|
-
if (!latestVersion) {
|
|
30
|
-
throw new RangeError(
|
|
31
|
-
`ERROR: The latest version of \`${packageName}\` is unknown.\n`,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return `^${latestVersion}`;
|
|
36
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* https://github.com/ember-cli/ember-cli/blob/v4.9.2/lib/utilities/process-template.js */
|
|
2
|
-
import template from 'lodash.template';
|
|
3
|
-
|
|
4
|
-
export function processTemplate(file, data) {
|
|
5
|
-
const settings = {
|
|
6
|
-
escape: /<%-([\s\S]+?)%>/g,
|
|
7
|
-
evaluate: /<%([\s\S]+?)%>/g,
|
|
8
|
-
interpolate: /<%=([\s\S]+?)%>/g,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
return template(file, settings)(data);
|
|
12
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function copyFiles(pathMapping, options) {
|
|
5
|
-
const { projectRoot } = options;
|
|
6
|
-
|
|
7
|
-
pathMapping.forEach((newPath, oldPath) => {
|
|
8
|
-
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
9
|
-
|
|
10
|
-
const newAbsolutePath = join(projectRoot, newPath);
|
|
11
|
-
const newDirectory = dirname(newAbsolutePath);
|
|
12
|
-
|
|
13
|
-
if (!existsSync(newDirectory)) {
|
|
14
|
-
mkdirSync(newDirectory, { recursive: true });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
copyFileSync(oldAbsolutePath, newAbsolutePath);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function createFiles(fileMapping, options) {
|
|
5
|
-
const { projectRoot } = options;
|
|
6
|
-
|
|
7
|
-
fileMapping.forEach((file, newPath) => {
|
|
8
|
-
const newAbsolutePath = join(projectRoot, newPath);
|
|
9
|
-
const newDirectory = dirname(newAbsolutePath);
|
|
10
|
-
|
|
11
|
-
if (!existsSync(newDirectory)) {
|
|
12
|
-
mkdirSync(newDirectory, { recursive: true });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
writeFileSync(newAbsolutePath, file, 'utf8');
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
|
|
3
|
-
export function renameDirectory(oldPath, { from, to }) {
|
|
4
|
-
if (from === '') {
|
|
5
|
-
return join(to, oldPath);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!oldPath.startsWith(`${from}/`)) {
|
|
9
|
-
return oldPath;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return join(to, oldPath.replace(`${from}/`, ''));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function mapFilePaths(filePaths, directory) {
|
|
16
|
-
const { from, to } = directory;
|
|
17
|
-
|
|
18
|
-
return new Map(
|
|
19
|
-
filePaths.map((filePath) => {
|
|
20
|
-
const newPath = renameDirectory(filePath, { from, to });
|
|
21
|
-
|
|
22
|
-
return [filePath, newPath];
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { removeDirectoryIfEmpty } from './remove-directory-if-empty.js';
|
|
5
|
-
|
|
6
|
-
export function moveFiles(pathMapping, options) {
|
|
7
|
-
const { projectRoot } = options;
|
|
8
|
-
|
|
9
|
-
pathMapping.forEach((newPath, oldPath) => {
|
|
10
|
-
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
11
|
-
|
|
12
|
-
const newAbsolutePath = join(projectRoot, newPath);
|
|
13
|
-
const newDirectory = dirname(newAbsolutePath);
|
|
14
|
-
|
|
15
|
-
if (!existsSync(newDirectory)) {
|
|
16
|
-
mkdirSync(newDirectory, { recursive: true });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
renameSync(oldAbsolutePath, newAbsolutePath);
|
|
20
|
-
removeDirectoryIfEmpty({ oldPath, projectRoot });
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { readdirSync, rmSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function removeDirectoryIfEmpty({ oldPath, projectRoot }) {
|
|
5
|
-
const directories = dirname(oldPath).split('/');
|
|
6
|
-
const depth = directories.length;
|
|
7
|
-
|
|
8
|
-
for (let i = 0; i < depth; i++) {
|
|
9
|
-
const directory = join(projectRoot, ...directories);
|
|
10
|
-
const numFilesLeft = readdirSync(directory).length;
|
|
11
|
-
|
|
12
|
-
if (numFilesLeft > 0) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
rmSync(directory, { recursive: true });
|
|
17
|
-
directories.pop();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { removeDirectoryIfEmpty } from './remove-directory-if-empty.js';
|
|
5
|
-
|
|
6
|
-
export function removeFiles(oldPaths, options) {
|
|
7
|
-
const { projectRoot } = options;
|
|
8
|
-
|
|
9
|
-
oldPaths.forEach((oldPath) => {
|
|
10
|
-
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
11
|
-
|
|
12
|
-
rmSync(oldAbsolutePath);
|
|
13
|
-
removeDirectoryIfEmpty({ oldPath, projectRoot });
|
|
14
|
-
});
|
|
15
|
-
}
|
package/src/utils/files.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './files/copy-files.js';
|
|
2
|
-
export * from './files/create-files.js';
|
|
3
|
-
export * from './files/find-files.js';
|
|
4
|
-
export * from './files/map-file-paths.js';
|
|
5
|
-
export * from './files/move-files.js';
|
|
6
|
-
export * from './files/remove-directory-if-empty.js';
|
|
7
|
-
export * from './files/remove-files.js';
|