ember-codemod-v1-to-v2 0.6.2 → 0.7.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 +6 -1
- package/dist/bin/ember-codemod-v1-to-v2.js +37 -0
- package/dist/blueprints/ember-addon/__addonLocation__/.eslintignore +8 -0
- package/dist/blueprints/ember-addon/__addonLocation__/addon-main.cjs +5 -0
- package/dist/blueprints/ember-addon/__addonLocation__/babel.config.json +9 -0
- package/dist/blueprints/ember-addon/__addonLocation__/rollup.config.mjs +64 -0
- package/dist/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts +14 -0
- package/dist/blueprints/ember-addon/__gitignore__ +24 -0
- package/dist/blueprints/ember-addon/__testAppLocation__/ember-cli-build.js +16 -0
- package/dist/blueprints/ember-addon/__testAppLocation__/types/global.d.ts +7 -0
- package/dist/blueprints/ember-addon/package.json +69 -0
- package/dist/blueprints/ember-addon/pnpm-workspace.yaml +3 -0
- package/{src → dist/src}/index.js +1 -2
- package/dist/src/migration/ember-addon/index.js +22 -0
- package/dist/src/migration/ember-addon/steps/analyze-addon.js +70 -0
- package/dist/src/migration/ember-addon/steps/create-files-from-blueprint.js +42 -0
- package/dist/src/migration/ember-addon/steps/create-options.js +73 -0
- package/dist/src/migration/ember-addon/steps/move-addon-files.js +59 -0
- package/dist/src/migration/ember-addon/steps/move-project-root-files.js +79 -0
- package/dist/src/migration/ember-addon/steps/move-test-app-files.js +65 -0
- package/dist/src/migration/ember-addon/steps/update-addon-package-json.js +138 -0
- package/dist/src/migration/ember-addon/steps/update-addon-tsconfig-json.js +26 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json.js +62 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-tsconfig-json.js +30 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils/blueprints/blueprints-root.js +4 -0
- package/dist/src/utils/blueprints/get-version.js +25 -0
- package/{src → dist/src}/utils/json/sanitize-json.js +3 -4
- package/package.json +31 -18
- package/bin/ember-codemod-v1-to-v2.js +0 -42
- package/src/migration/ember-addon/index.js +0 -39
- package/src/migration/ember-addon/steps/analyze-addon.js +0 -82
- package/src/migration/ember-addon/steps/create-files-from-blueprint.js +0 -60
- package/src/migration/ember-addon/steps/create-options.js +0 -93
- package/src/migration/ember-addon/steps/move-addon-files.js +0 -84
- package/src/migration/ember-addon/steps/move-project-root-files.js +0 -110
- package/src/migration/ember-addon/steps/move-test-app-files.js +0 -90
- package/src/migration/ember-addon/steps/update-addon-package-json.js +0 -173
- package/src/migration/ember-addon/steps/update-addon-tsconfig-json.js +0 -38
- package/src/migration/ember-addon/steps/update-test-app-package-json.js +0 -90
- package/src/migration/ember-addon/steps/update-test-app-tsconfig-json.js +0 -43
- package/src/utils/blueprints/blueprints-root.js +0 -8
- package/src/utils/blueprints/get-version.js +0 -28
- /package/{src → dist/blueprints}/blueprints/ember-addon/__addonLocation__/.eslintignore +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__addonLocation__/addon-main.cjs +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__addonLocation__/babel.config.json +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__addonLocation__/rollup.config.mjs +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__gitignore__ +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__testAppLocation__/ember-cli-build.js +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/__testAppLocation__/types/global.d.ts +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/package.json +0 -0
- /package/{src → dist/blueprints}/blueprints/ember-addon/pnpm-workspace.yaml +0 -0
- /package/{src → dist/src}/migration/ember-addon/steps/index.js +0 -0
- /package/{src → dist/src}/migration/index.js +0 -0
- /package/{src → dist/src}/utils/blueprints.js +0 -0
- /package/{src → dist/src}/utils/json.js +0 -0
package/README.md
CHANGED
|
@@ -102,7 +102,12 @@ To better meet your needs, consider cloning the repo and running the codemod loc
|
|
|
102
102
|
|
|
103
103
|
```sh
|
|
104
104
|
cd <your/cloned/repo>
|
|
105
|
-
|
|
105
|
+
|
|
106
|
+
# Compile TypeScript
|
|
107
|
+
pnpm build
|
|
108
|
+
|
|
109
|
+
# Run codemod
|
|
110
|
+
./dist/bin/ember-codemod-v1-to-v2.js --root=<your/project/path>
|
|
106
111
|
```
|
|
107
112
|
|
|
108
113
|
You can also look at another codemod called [`ember-addon-migrator`](https://github.com/NullVoxPopuli/ember-addon-migrator).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// eslint-disable-next-line n/shebang
|
|
3
|
+
'use strict';
|
|
4
|
+
import yargs from 'yargs';
|
|
5
|
+
import { hideBin } from 'yargs/helpers';
|
|
6
|
+
import { runCodemod } from '../src/index.js';
|
|
7
|
+
// Provide a title to the process in `ps`
|
|
8
|
+
process.title = 'ember-codemod-v1-to-v2';
|
|
9
|
+
// Set codemod options
|
|
10
|
+
const argv = yargs(hideBin(process.argv))
|
|
11
|
+
.option('addon-location', {
|
|
12
|
+
describe: 'Location of the addon package',
|
|
13
|
+
type: 'string',
|
|
14
|
+
})
|
|
15
|
+
.option('root', {
|
|
16
|
+
describe: 'Location of your Ember addon',
|
|
17
|
+
type: 'string',
|
|
18
|
+
})
|
|
19
|
+
.option('test-app-location', {
|
|
20
|
+
describe: 'Location of the test-app package',
|
|
21
|
+
type: 'string',
|
|
22
|
+
})
|
|
23
|
+
.option('test-app-name', {
|
|
24
|
+
describe: 'Name of the test-app package',
|
|
25
|
+
type: 'string',
|
|
26
|
+
})
|
|
27
|
+
.parseSync();
|
|
28
|
+
function castEmptyStringToUndefined(value) {
|
|
29
|
+
return value === '' ? undefined : value;
|
|
30
|
+
}
|
|
31
|
+
const codemodOptions = {
|
|
32
|
+
addonLocation: castEmptyStringToUndefined(argv['addon-location']),
|
|
33
|
+
projectRoot: argv['root'] ?? process.cwd(),
|
|
34
|
+
testAppLocation: castEmptyStringToUndefined(argv['test-app-location']),
|
|
35
|
+
testAppName: castEmptyStringToUndefined(argv['test-app-name']),
|
|
36
|
+
};
|
|
37
|
+
runCodemod(codemodOptions);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
<% if (options.packages.addon.hasTypeScript) { %> "presets": [["@babel/preset-typescript"]],
|
|
3
|
+
<% } %> "plugins": [
|
|
4
|
+
"@embroider/addon-dev/template-colocation-plugin",<% if (options.packages.addon.hasTypeScript) { %>
|
|
5
|
+
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],<% } %>
|
|
6
|
+
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
|
|
7
|
+
"@babel/plugin-proposal-class-properties"
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<% if (options.packages.addon.hasTypeScript) { %>import typescript from 'rollup-plugin-ts';<% } else { %>import { babel } from '@rollup/plugin-babel';<% } %>
|
|
2
|
+
import copy from 'rollup-plugin-copy';
|
|
3
|
+
import { Addon } from '@embroider/addon-dev/rollup';
|
|
4
|
+
|
|
5
|
+
const addon = new Addon({
|
|
6
|
+
srcDir: 'src',
|
|
7
|
+
destDir: 'dist',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
// This provides defaults that work well alongside `publicEntrypoints` below.
|
|
12
|
+
// You can augment this if you need to.
|
|
13
|
+
output: addon.output(),
|
|
14
|
+
|
|
15
|
+
plugins: [
|
|
16
|
+
// These are the modules that users should be able to import from your
|
|
17
|
+
// addon. Anything not listed here may get optimized away.
|
|
18
|
+
addon.publicEntrypoints([<%= context.addon.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
|
|
19
|
+
|
|
20
|
+
// These are the modules that should get reexported into the traditional
|
|
21
|
+
// "app" tree. Things in here should also be in publicEntrypoints above, but
|
|
22
|
+
// not everything in publicEntrypoints necessarily needs to go here.
|
|
23
|
+
addon.appReexports([<%= context.addon.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
|
|
24
|
+
|
|
25
|
+
// Follow the V2 Addon rules about dependencies. Your code can import from
|
|
26
|
+
// `dependencies` and `peerDependencies` as well as standard Ember-provided
|
|
27
|
+
// package names.
|
|
28
|
+
addon.dependencies(),
|
|
29
|
+
|
|
30
|
+
<% if (options.packages.addon.hasTypeScript) { %> // compile TypeScript to latest JavaScript, including Babel transpilation
|
|
31
|
+
typescript({
|
|
32
|
+
transpiler: 'babel',
|
|
33
|
+
browserslist: false,
|
|
34
|
+
transpileOnly: false,
|
|
35
|
+
}),
|
|
36
|
+
<% } else { %> // This babel config should *not* apply presets or compile away ES modules.
|
|
37
|
+
// It exists only to provide development niceties for you, like automatic
|
|
38
|
+
// template colocation.
|
|
39
|
+
//
|
|
40
|
+
// By default, this will load the actual babel config from the file
|
|
41
|
+
// babel.config.json.
|
|
42
|
+
babel({
|
|
43
|
+
babelHelpers: 'bundled',
|
|
44
|
+
}),
|
|
45
|
+
<% } %>
|
|
46
|
+
// Ensure that standalone .hbs files are properly integrated as Javascript.
|
|
47
|
+
addon.hbs(),
|
|
48
|
+
|
|
49
|
+
// addons are allowed to contain imports of .css files, which we want rollup
|
|
50
|
+
// to leave alone and keep in the published output.
|
|
51
|
+
addon.keepAssets(['**/*.css']),
|
|
52
|
+
|
|
53
|
+
// Remove leftover build artifacts when starting a new build.
|
|
54
|
+
addon.clean(),
|
|
55
|
+
|
|
56
|
+
// Copy Readme and License into published package
|
|
57
|
+
copy({
|
|
58
|
+
targets: [
|
|
59
|
+
{ src: '../README.md', dest: '.' },
|
|
60
|
+
{ src: '../LICENSE.md', dest: '.' },
|
|
61
|
+
],
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
};
|
package/dist/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Add any types here that you need for local development only.
|
|
2
|
+
// These will *not* be published as part of your addon, so be careful that your published code does not rely on them!
|
|
3
|
+
<% if (options.packages.addon.hasGlint) { %>
|
|
4
|
+
import '@glint/environment-ember-loose';
|
|
5
|
+
|
|
6
|
+
declare module '@glint/environment-ember-loose/registry' {
|
|
7
|
+
// Remove this once entries have been added! 👇
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
9
|
+
export default interface Registry {
|
|
10
|
+
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
|
|
11
|
+
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
<% } %>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# compiled output
|
|
2
|
+
/dist/
|
|
3
|
+
|
|
4
|
+
# dependencies
|
|
5
|
+
/node_modules/
|
|
6
|
+
|
|
7
|
+
# misc
|
|
8
|
+
/.env*
|
|
9
|
+
/.pnp*
|
|
10
|
+
/.eslintcache
|
|
11
|
+
/coverage/
|
|
12
|
+
/npm-debug.log*
|
|
13
|
+
/testem.log
|
|
14
|
+
/yarn-error.log
|
|
15
|
+
|
|
16
|
+
# ember-try
|
|
17
|
+
/.node_modules.ember-try/
|
|
18
|
+
/npm-shrinkwrap.json.ember-try
|
|
19
|
+
/package.json.ember-try
|
|
20
|
+
/package-lock.json.ember-try
|
|
21
|
+
/yarn.lock.ember-try
|
|
22
|
+
|
|
23
|
+
# broccoli-debug
|
|
24
|
+
/DEBUG/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaults) {
|
|
6
|
+
const app = new EmberApp(defaults, {
|
|
7
|
+
// Add options here
|
|
8
|
+
autoImport: {
|
|
9
|
+
watchDependencies: ['<%= options.packages.addon.name %>'],
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const { maybeEmbroider } = require('@embroider/test-setup');
|
|
14
|
+
|
|
15
|
+
return maybeEmbroider(app);
|
|
16
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<% if (options.packageManager.isNpm) { %>{
|
|
2
|
+
"name": "<%= options.packages.addon.name %>",
|
|
3
|
+
"version": "<%= options.packages.addon.version %>",
|
|
4
|
+
"private": true,
|
|
5
|
+
"repository": "",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "",
|
|
8
|
+
"workspaces": [
|
|
9
|
+
"<%= options.locations.addon %>",
|
|
10
|
+
"<%= options.locations.testApp %>"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "npm run build --workspace <%= options.packages.addon.name %>",
|
|
14
|
+
"lint": "npm run lint --workspaces --if-present",
|
|
15
|
+
"lint:fix": "npm run lint:fix --workspaces --if-present",
|
|
16
|
+
"prepare": "npm run build",
|
|
17
|
+
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
18
|
+
"start:addon": "npm start --workspace <%= options.packages.addon.name %>",
|
|
19
|
+
"start:test-app": "npm start --workspace <%= options.packages.testApp.name %>",
|
|
20
|
+
"test": "npm run test --workspaces --if-present"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
24
|
+
}
|
|
25
|
+
}<% } else if (options.packageManager.isPnpm) { %>{
|
|
26
|
+
"name": "<%= options.packages.addon.name %>",
|
|
27
|
+
"version": "<%= options.packages.addon.version %>",
|
|
28
|
+
"private": true,
|
|
29
|
+
"repository": "",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"author": "",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "pnpm --filter <%= options.packages.addon.name %> build",
|
|
34
|
+
"lint": "pnpm --filter '*' lint",
|
|
35
|
+
"lint:fix": "pnpm --filter '*' lint:fix",
|
|
36
|
+
"prepare": "pnpm build",
|
|
37
|
+
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
38
|
+
"start:addon": "pnpm --filter <%= options.packages.addon.name %> start",
|
|
39
|
+
"start:test-app": "pnpm --filter <%= options.packages.testApp.name %> start",
|
|
40
|
+
"test": "pnpm --filter '*' test"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
44
|
+
}
|
|
45
|
+
}<% } else if (options.packageManager.isYarn) { %>{
|
|
46
|
+
"name": "<%= options.packages.addon.name %>",
|
|
47
|
+
"version": "<%= options.packages.addon.version %>",
|
|
48
|
+
"private": true,
|
|
49
|
+
"repository": "",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"author": "",
|
|
52
|
+
"workspaces": [
|
|
53
|
+
"<%= options.locations.addon %>",
|
|
54
|
+
"<%= options.locations.testApp %>"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "yarn workspace <%= options.packages.addon.name %> run build",
|
|
58
|
+
"lint": "yarn workspaces run lint",
|
|
59
|
+
"lint:fix": "yarn workspaces run lint:fix",
|
|
60
|
+
"prepare": "yarn build",
|
|
61
|
+
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
62
|
+
"start:addon": "yarn workspace <%= options.packages.addon.name %> run start",
|
|
63
|
+
"start:test-app": "yarn workspace <%= options.packages.testApp.name %> run start",
|
|
64
|
+
"test": "yarn workspaces run test"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
68
|
+
}
|
|
69
|
+
}<% } %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { analyzeAddon, createFilesFromBlueprint, createOptions, moveAddonFiles, moveProjectRootFiles, moveTestAppFiles, updateAddonPackageJson, updateAddonTsConfigJson, updateTestAppPackageJson, updateTestAppTsConfigJson, } from './steps/index.js';
|
|
2
|
+
export function migrateEmberAddon(codemodOptions) {
|
|
3
|
+
const options = createOptions(codemodOptions);
|
|
4
|
+
const { isV1Addon } = options.packages.addon;
|
|
5
|
+
// Guarantee idempotency
|
|
6
|
+
if (!isV1Addon) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
// Prepare for migration
|
|
10
|
+
const context = analyzeAddon(options);
|
|
11
|
+
// Preserve code
|
|
12
|
+
moveAddonFiles(options);
|
|
13
|
+
moveTestAppFiles(options);
|
|
14
|
+
moveProjectRootFiles(options);
|
|
15
|
+
// Get the latest code from blueprint
|
|
16
|
+
createFilesFromBlueprint(context, options);
|
|
17
|
+
// Fine-tune individual files
|
|
18
|
+
updateAddonPackageJson(context, options);
|
|
19
|
+
updateAddonTsConfigJson(options);
|
|
20
|
+
updateTestAppPackageJson(options);
|
|
21
|
+
updateTestAppTsConfigJson(options);
|
|
22
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
|
|
2
|
+
import { getVersion } from '../../../utils/blueprints.js';
|
|
3
|
+
function getAppReexports(options) {
|
|
4
|
+
const { projectRoot } = options;
|
|
5
|
+
const filePaths = findFiles('app/**/*.js', {
|
|
6
|
+
projectRoot,
|
|
7
|
+
});
|
|
8
|
+
return filePaths
|
|
9
|
+
.map((filePath) => {
|
|
10
|
+
return renamePathByDirectory(filePath, {
|
|
11
|
+
from: 'app',
|
|
12
|
+
to: '',
|
|
13
|
+
});
|
|
14
|
+
})
|
|
15
|
+
.sort();
|
|
16
|
+
}
|
|
17
|
+
function getProjectRootDevDependencies(options) {
|
|
18
|
+
return {
|
|
19
|
+
concurrently: getVersion('concurrently', options),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getPublicAssets(options) {
|
|
23
|
+
const { projectRoot } = options;
|
|
24
|
+
const filePaths = findFiles('public/**/*', {
|
|
25
|
+
projectRoot,
|
|
26
|
+
});
|
|
27
|
+
return filePaths
|
|
28
|
+
.map((filePath) => {
|
|
29
|
+
return renamePathByDirectory(filePath, {
|
|
30
|
+
from: 'public',
|
|
31
|
+
to: '',
|
|
32
|
+
});
|
|
33
|
+
})
|
|
34
|
+
.sort();
|
|
35
|
+
}
|
|
36
|
+
function getPublicEntrypoints(options) {
|
|
37
|
+
const { projectRoot } = options;
|
|
38
|
+
const filePaths = findFiles('{addon,addon-test-support}/**/*.{js,ts}', {
|
|
39
|
+
projectRoot,
|
|
40
|
+
});
|
|
41
|
+
return filePaths
|
|
42
|
+
.map((filePath) => {
|
|
43
|
+
return renamePathByDirectory(filePath, {
|
|
44
|
+
from: 'addon',
|
|
45
|
+
to: '',
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
.map((filePath) => {
|
|
49
|
+
return renamePathByDirectory(filePath, {
|
|
50
|
+
from: 'addon-test-support',
|
|
51
|
+
to: 'test-support',
|
|
52
|
+
});
|
|
53
|
+
})
|
|
54
|
+
.map((filePath) => {
|
|
55
|
+
return filePath.replace(/ts$/, 'js');
|
|
56
|
+
})
|
|
57
|
+
.sort();
|
|
58
|
+
}
|
|
59
|
+
export function analyzeAddon(options) {
|
|
60
|
+
return {
|
|
61
|
+
addon: {
|
|
62
|
+
appReexports: getAppReexports(options),
|
|
63
|
+
publicAssets: getPublicAssets(options),
|
|
64
|
+
publicEntrypoints: getPublicEntrypoints(options),
|
|
65
|
+
},
|
|
66
|
+
projectRoot: {
|
|
67
|
+
devDependencies: getProjectRootDevDependencies(options),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { processTemplate } from '@codemod-utils/blueprints';
|
|
4
|
+
import { createFiles, findFiles } from '@codemod-utils/files';
|
|
5
|
+
import { blueprintsRoot } from '../../../utils/blueprints.js';
|
|
6
|
+
function getFilesToSkip(options) {
|
|
7
|
+
const { packageManager, packages } = options;
|
|
8
|
+
const files = new Set();
|
|
9
|
+
if (!packages.addon.hasTypeScript) {
|
|
10
|
+
files.add('__addonLocation__/unpublished-development-types/index.d.ts');
|
|
11
|
+
files.add('__testAppLocation__/types/global.d.ts');
|
|
12
|
+
}
|
|
13
|
+
if (!packageManager.isPnpm) {
|
|
14
|
+
files.add('pnpm-workspace.yaml');
|
|
15
|
+
}
|
|
16
|
+
return [...files];
|
|
17
|
+
}
|
|
18
|
+
function resolveBlueprintFilePath(blueprintFilePath, options) {
|
|
19
|
+
const { locations } = options;
|
|
20
|
+
return blueprintFilePath
|
|
21
|
+
.replace('__addonLocation__', locations.addon)
|
|
22
|
+
.replace('__gitignore__', '.gitignore')
|
|
23
|
+
.replace('__testAppLocation__', locations.testApp);
|
|
24
|
+
}
|
|
25
|
+
export function createFilesFromBlueprint(context, options) {
|
|
26
|
+
const filesToSkip = getFilesToSkip(options);
|
|
27
|
+
const cwd = join(blueprintsRoot, 'ember-addon');
|
|
28
|
+
const blueprintFilePaths = findFiles('**/*', {
|
|
29
|
+
ignoreList: filesToSkip,
|
|
30
|
+
projectRoot: cwd,
|
|
31
|
+
});
|
|
32
|
+
const fileMap = new Map(blueprintFilePaths.map((blueprintFilePath) => {
|
|
33
|
+
const filePath = resolveBlueprintFilePath(blueprintFilePath, options);
|
|
34
|
+
const blueprintFile = readFileSync(join(cwd, blueprintFilePath), 'utf8');
|
|
35
|
+
const file = processTemplate(blueprintFile, {
|
|
36
|
+
context,
|
|
37
|
+
options,
|
|
38
|
+
});
|
|
39
|
+
return [filePath, file];
|
|
40
|
+
}));
|
|
41
|
+
createFiles(fileMap, options);
|
|
42
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { findFiles, unionize } from '@codemod-utils/files';
|
|
2
|
+
import { readPackageJson, validatePackageJson } from '@codemod-utils/json';
|
|
3
|
+
function analyzePackageJson(codemodOptions) {
|
|
4
|
+
const { projectRoot } = codemodOptions;
|
|
5
|
+
const packageJson = readPackageJson({ projectRoot });
|
|
6
|
+
validatePackageJson(packageJson);
|
|
7
|
+
const { dependencies, devDependencies, 'ember-addon': emberAddon, name, version, } = packageJson;
|
|
8
|
+
const projectDependencies = new Map([
|
|
9
|
+
...Object.entries(dependencies ?? {}),
|
|
10
|
+
...Object.entries(devDependencies ?? {}),
|
|
11
|
+
]);
|
|
12
|
+
return {
|
|
13
|
+
dependencies: projectDependencies,
|
|
14
|
+
hasGlint: projectDependencies.has('@glint/core'),
|
|
15
|
+
hasTypeScript: projectDependencies.has('typescript'),
|
|
16
|
+
isV1Addon: Boolean(emberAddon),
|
|
17
|
+
name,
|
|
18
|
+
version,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function analyzePackageManager(codemodOptions) {
|
|
22
|
+
const { projectRoot } = codemodOptions;
|
|
23
|
+
const mapping = new Map([
|
|
24
|
+
['package-lock.json', 'npm'],
|
|
25
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
26
|
+
['yarn.lock', 'yarn'],
|
|
27
|
+
]);
|
|
28
|
+
const lockFiles = [...mapping.keys()];
|
|
29
|
+
const filePaths = findFiles(unionize(lockFiles), {
|
|
30
|
+
projectRoot,
|
|
31
|
+
});
|
|
32
|
+
if (filePaths.length !== 1) {
|
|
33
|
+
console.warn('WARNING: Package manager is unknown. Yarn will be assumed.');
|
|
34
|
+
return {
|
|
35
|
+
isNpm: false,
|
|
36
|
+
isPnpm: false,
|
|
37
|
+
isYarn: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const packageManager = mapping.get(filePaths[0]);
|
|
41
|
+
return {
|
|
42
|
+
isNpm: packageManager === 'npm',
|
|
43
|
+
isPnpm: packageManager === 'pnpm',
|
|
44
|
+
isYarn: packageManager === 'yarn',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function deriveAddonLocation(addonPackage) {
|
|
48
|
+
const hasScope = addonPackage.name.includes('/');
|
|
49
|
+
if (!hasScope) {
|
|
50
|
+
return addonPackage.name;
|
|
51
|
+
}
|
|
52
|
+
// eslint-disable-next-line no-unused-vars
|
|
53
|
+
const [_scope, packageName] = addonPackage.name.split('/');
|
|
54
|
+
return packageName;
|
|
55
|
+
}
|
|
56
|
+
export function createOptions(codemodOptions) {
|
|
57
|
+
const addonPackage = analyzePackageJson(codemodOptions);
|
|
58
|
+
const packageManager = analyzePackageManager(codemodOptions);
|
|
59
|
+
return {
|
|
60
|
+
locations: {
|
|
61
|
+
addon: codemodOptions.addonLocation ?? deriveAddonLocation(addonPackage),
|
|
62
|
+
testApp: codemodOptions.testAppLocation ?? 'test-app',
|
|
63
|
+
},
|
|
64
|
+
packageManager,
|
|
65
|
+
packages: {
|
|
66
|
+
addon: addonPackage,
|
|
67
|
+
testApp: {
|
|
68
|
+
name: codemodOptions.testAppName ?? 'test-app',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
projectRoot: codemodOptions.projectRoot,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { findFiles, mapFilePaths, moveFiles, removeFiles, } from '@codemod-utils/files';
|
|
2
|
+
function moveAddonFolder(options) {
|
|
3
|
+
const { locations, projectRoot } = options;
|
|
4
|
+
const filePaths = findFiles('addon/**/*', {
|
|
5
|
+
projectRoot,
|
|
6
|
+
});
|
|
7
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
8
|
+
from: 'addon',
|
|
9
|
+
to: `${locations.addon}/src`,
|
|
10
|
+
});
|
|
11
|
+
moveFiles(filePathMap, options);
|
|
12
|
+
}
|
|
13
|
+
function moveAddonTestSupportFolder(options) {
|
|
14
|
+
const { locations, projectRoot } = options;
|
|
15
|
+
const filePaths = findFiles('addon-test-support/**/*', {
|
|
16
|
+
projectRoot,
|
|
17
|
+
});
|
|
18
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
19
|
+
from: 'addon-test-support',
|
|
20
|
+
to: `${locations.addon}/src/test-support`,
|
|
21
|
+
});
|
|
22
|
+
moveFiles(filePathMap, options);
|
|
23
|
+
}
|
|
24
|
+
function moveBlueprintsFolder(options) {
|
|
25
|
+
const { locations, projectRoot } = options;
|
|
26
|
+
const filePaths = findFiles('blueprints/**/*', {
|
|
27
|
+
projectRoot,
|
|
28
|
+
});
|
|
29
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
30
|
+
from: 'blueprints',
|
|
31
|
+
to: `${locations.addon}/blueprints`,
|
|
32
|
+
});
|
|
33
|
+
moveFiles(filePathMap, options);
|
|
34
|
+
}
|
|
35
|
+
function movePublicFolder(options) {
|
|
36
|
+
const { locations, projectRoot } = options;
|
|
37
|
+
const filePaths = findFiles('public/**/*', {
|
|
38
|
+
projectRoot,
|
|
39
|
+
});
|
|
40
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
41
|
+
from: 'public',
|
|
42
|
+
to: `${locations.addon}/public`,
|
|
43
|
+
});
|
|
44
|
+
moveFiles(filePathMap, options);
|
|
45
|
+
}
|
|
46
|
+
function removeAppFolder(options) {
|
|
47
|
+
const { projectRoot } = options;
|
|
48
|
+
const filePaths = findFiles('app/**/*', {
|
|
49
|
+
projectRoot,
|
|
50
|
+
});
|
|
51
|
+
removeFiles(filePaths, options);
|
|
52
|
+
}
|
|
53
|
+
export function moveAddonFiles(options) {
|
|
54
|
+
moveAddonFolder(options);
|
|
55
|
+
moveAddonTestSupportFolder(options);
|
|
56
|
+
moveBlueprintsFolder(options);
|
|
57
|
+
movePublicFolder(options);
|
|
58
|
+
removeAppFolder(options);
|
|
59
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { copyFiles, findFiles, mapFilePaths, moveFiles, removeFiles, unionize, } from '@codemod-utils/files';
|
|
2
|
+
function copyToAddon(options) {
|
|
3
|
+
const { locations, projectRoot } = options;
|
|
4
|
+
const files = ['LICENSE.md', 'README.md'];
|
|
5
|
+
const filePaths = findFiles(unionize(files), {
|
|
6
|
+
projectRoot,
|
|
7
|
+
});
|
|
8
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
9
|
+
from: '',
|
|
10
|
+
to: locations.addon,
|
|
11
|
+
});
|
|
12
|
+
copyFiles(filePathMap, options);
|
|
13
|
+
}
|
|
14
|
+
function moveToAddonAndTestApp(options) {
|
|
15
|
+
const { locations, packages, projectRoot } = options;
|
|
16
|
+
const files = new Set([
|
|
17
|
+
'.eslintignore',
|
|
18
|
+
'.eslintrc.cjs',
|
|
19
|
+
'.eslintrc.js',
|
|
20
|
+
'.gitignore',
|
|
21
|
+
'.prettierignore',
|
|
22
|
+
'.prettierrc.cjs',
|
|
23
|
+
'.prettierrc.js',
|
|
24
|
+
'.stylelintignore',
|
|
25
|
+
'.stylelintrc.cjs',
|
|
26
|
+
'.stylelintrc.js',
|
|
27
|
+
'.template-lintrc.cjs',
|
|
28
|
+
'.template-lintrc.js',
|
|
29
|
+
'package.json',
|
|
30
|
+
]);
|
|
31
|
+
if (packages.addon.hasTypeScript) {
|
|
32
|
+
files.add('tsconfig.json');
|
|
33
|
+
}
|
|
34
|
+
const filePaths = findFiles(unionize([...files]), {
|
|
35
|
+
projectRoot,
|
|
36
|
+
});
|
|
37
|
+
let filePathMap = mapFilePaths(filePaths, {
|
|
38
|
+
from: '',
|
|
39
|
+
to: locations.addon,
|
|
40
|
+
});
|
|
41
|
+
copyFiles(filePathMap, options);
|
|
42
|
+
filePathMap = mapFilePaths(filePaths, {
|
|
43
|
+
from: '',
|
|
44
|
+
to: locations.testApp,
|
|
45
|
+
});
|
|
46
|
+
copyFiles(filePathMap, options);
|
|
47
|
+
removeFiles(filePaths, options);
|
|
48
|
+
}
|
|
49
|
+
function moveToTestApp(options) {
|
|
50
|
+
const { locations, projectRoot } = options;
|
|
51
|
+
const files = [
|
|
52
|
+
'.ember-cli',
|
|
53
|
+
'.watchmanconfig',
|
|
54
|
+
'ember-cli-build.js',
|
|
55
|
+
'testem.js',
|
|
56
|
+
];
|
|
57
|
+
const filePaths = findFiles(unionize(files), {
|
|
58
|
+
projectRoot,
|
|
59
|
+
});
|
|
60
|
+
const filePathMap = mapFilePaths(filePaths, {
|
|
61
|
+
from: '',
|
|
62
|
+
to: locations.testApp,
|
|
63
|
+
});
|
|
64
|
+
moveFiles(filePathMap, options);
|
|
65
|
+
}
|
|
66
|
+
function removeFromProjectRoot(options) {
|
|
67
|
+
const { projectRoot } = options;
|
|
68
|
+
const files = ['.npmignore', 'index.js'];
|
|
69
|
+
const filePaths = findFiles(unionize(files), {
|
|
70
|
+
projectRoot,
|
|
71
|
+
});
|
|
72
|
+
removeFiles(filePaths, options);
|
|
73
|
+
}
|
|
74
|
+
export function moveProjectRootFiles(options) {
|
|
75
|
+
copyToAddon(options);
|
|
76
|
+
moveToAddonAndTestApp(options);
|
|
77
|
+
moveToTestApp(options);
|
|
78
|
+
removeFromProjectRoot(options);
|
|
79
|
+
}
|