install-ember-testem 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Isaac J. Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # install-ember-testem
2
+
3
+ _Codemod to install `ember-testem`_
4
+
5
+
6
+ ## Usage
7
+
8
+ Step 1. Run codemod.
9
+
10
+ ```sh
11
+ cd <path/to/your/project>
12
+ pnpx install-ember-testem
13
+ ```
14
+
15
+ Step 2. Review the `build:test` and `test` scripts.
16
+
17
+
18
+ ### Limitations
19
+
20
+ The codemod is designed to cover typical cases. It is not designed to cover one-off cases.
21
+
22
+ To better meet your needs, consider cloning the repo and running the codemod locally.
23
+
24
+ ```sh
25
+ cd <path/to/cloned/repo>
26
+
27
+ # Compile TypeScript
28
+ pnpm build
29
+
30
+ # Run codemod
31
+ ./dist/bin/install-ember-testem.js --root <path/to/your/project>
32
+ ```
33
+
34
+
35
+ ## Compatibility
36
+
37
+ - Node.js v22 or above
38
+
39
+
40
+ ## Contributing
41
+
42
+ See the [Contributing](../../CONTRIBUTING.md) guide for details.
43
+
44
+
45
+ ## License
46
+
47
+ This project is licensed under the [MIT License](./LICENSE.md).
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
5
+ import { runCodemod } from '../src/index.js';
6
+ // Provide a title to the process in `ps`
7
+ process.title = 'install-ember-testem';
8
+ // Set codemod options
9
+ const argv = yargs(hideBin(process.argv))
10
+ .option('root', {
11
+ describe: 'Where to run the codemod',
12
+ type: 'string',
13
+ })
14
+ .parseSync();
15
+ const codemodOptions = {
16
+ projectRoot: argv['root'] ?? process.cwd(),
17
+ };
18
+ runCodemod(codemodOptions);
File without changes
@@ -0,0 +1,5 @@
1
+ import { createOptions, updatePackageJson } from './steps/index.js';
2
+ export function runCodemod(codemodOptions) {
3
+ const options = createOptions(codemodOptions);
4
+ updatePackageJson(options);
5
+ }
@@ -0,0 +1,13 @@
1
+ import { getPackageType, readPackageJson } from '@codemod-utils/package-json';
2
+ export function createOptions(codemodOptions) {
3
+ const { projectRoot } = codemodOptions;
4
+ const packageJson = readPackageJson({ projectRoot });
5
+ const packageType = getPackageType(packageJson);
6
+ if (packageType === 'node') {
7
+ throw new Error('Unable to find an Ember project');
8
+ }
9
+ return {
10
+ packageType,
11
+ projectRoot,
12
+ };
13
+ }
@@ -0,0 +1,2 @@
1
+ export * from './create-options.js';
2
+ export * from './update-package-json.js';
@@ -0,0 +1,2 @@
1
+ export * from './update-dependencies.js';
2
+ export * from './update-scripts.js';
@@ -0,0 +1,12 @@
1
+ import { convertToMap, convertToObject, } from '@codemod-utils/package-json';
2
+ const latestVersions = {
3
+ 'ember-testem': '^0.3.0',
4
+ };
5
+ export function updateDependencies(packageJson, options) {
6
+ const devDependencies = convertToMap(packageJson['devDependencies']);
7
+ devDependencies.set('ember-testem', latestVersions['ember-testem']);
8
+ if (options.packageType === 'v2-addon') {
9
+ // TODO
10
+ }
11
+ packageJson['devDependencies'] = convertToObject(devDependencies);
12
+ }
@@ -0,0 +1,56 @@
1
+ import { convertToMap, convertToObject, } from '@codemod-utils/package-json';
2
+ const mapArgumentNames = new Map([
3
+ ['-f', '-f'],
4
+ ['-m', '-m'],
5
+ ['--filter', '--filter'],
6
+ ['--module', '--module'],
7
+ ['--path', '--path'],
8
+ ['--test-port', '--port'],
9
+ ]);
10
+ function getTestArguments(testScript) {
11
+ const command = ['ember test', 'ember t'].find((command) => {
12
+ return testScript.includes(`${command} `) || testScript.endsWith(command);
13
+ });
14
+ if (!command) {
15
+ return '';
16
+ }
17
+ const index = testScript.indexOf(command);
18
+ const testArguments = testScript
19
+ .substring(index + command.length)
20
+ .trim()
21
+ .split(/\s+/);
22
+ const testArgumentsNew = testArguments.reduce((accumulator, token, index) => {
23
+ const argumentName = mapArgumentNames.get(token);
24
+ if (!argumentName) {
25
+ return accumulator;
26
+ }
27
+ accumulator.push(argumentName);
28
+ const argumentValue = testArguments.at(index + 1);
29
+ if (argumentValue && !mapArgumentNames.has(argumentValue)) {
30
+ accumulator.push(argumentValue);
31
+ }
32
+ return accumulator;
33
+ }, []);
34
+ return ' ' + testArgumentsNew.join(' ');
35
+ }
36
+ export function updateScripts(packageJson, options) {
37
+ const scripts = convertToMap(packageJson['scripts']);
38
+ const testScript = (scripts.get('test') ?? '');
39
+ if (testScript.includes('ember-test')) {
40
+ return;
41
+ }
42
+ switch (options.packageType) {
43
+ case 'v1-addon':
44
+ case 'v1-app': {
45
+ scripts.set('build:test', 'ember build --environment test');
46
+ break;
47
+ }
48
+ case 'v2-addon':
49
+ case 'v2-app': {
50
+ scripts.set('build:test', 'NODE_ENV=development vite build --config vite.test.config.mts --mode development');
51
+ break;
52
+ }
53
+ }
54
+ scripts.set('test', `pnpm build:test && ember-test${getTestArguments(testScript)}`);
55
+ packageJson['scripts'] = convertToObject(scripts);
56
+ }
@@ -0,0 +1,14 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import { EOL } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { readPackageJson } from '@codemod-utils/package-json';
5
+ import { updateDependencies, updateScripts, } from './update-package-json/index.js';
6
+ export function updatePackageJson(options) {
7
+ const { projectRoot } = options;
8
+ const packageJson = readPackageJson({ projectRoot });
9
+ updateDependencies(packageJson, options);
10
+ updateScripts(packageJson, options);
11
+ const destination = join(projectRoot, 'package.json');
12
+ const file = JSON.stringify(packageJson, null, 2).replaceAll('\n', EOL) + EOL;
13
+ writeFileSync(destination, file, 'utf8');
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { join } from 'node:path';
2
+ import { getFilePath } from '@codemod-utils/blueprints';
3
+ export const blueprintsRoot = join(getFilePath(import.meta.url), '../../blueprints');
@@ -0,0 +1 @@
1
+ export * from './blueprints/blueprints-root.js';
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "install-ember-testem",
3
+ "version": "0.1.0",
4
+ "description": "Codemod to install ember-testem",
5
+ "keywords": [
6
+ "codemod",
7
+ "ember-codemod",
8
+ "emberjs"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/ijlee2/ember-test.git",
13
+ "directory": "packages/ember-testem"
14
+ },
15
+ "license": "MIT",
16
+ "author": "Isaac J. Lee",
17
+ "type": "module",
18
+ "main": "dist/src/index.js",
19
+ "bin": {
20
+ "install-ember-testem": "dist/bin/install-ember-testem.js"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@codemod-utils/ast-javascript": "^4.3.3",
27
+ "@codemod-utils/blueprints": "^3.2.0",
28
+ "@codemod-utils/files": "^4.1.0",
29
+ "@codemod-utils/package-json": "^4.1.2",
30
+ "yargs": "^18.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "@codemod-utils/tests": "^3.3.0",
34
+ "@shared-configs/eslint-config-node": "0.0.0",
35
+ "@shared-configs/prettier": "0.0.0",
36
+ "@shared-configs/typescript": "0.0.0",
37
+ "@types/node": "^22.20.4",
38
+ "@types/yargs": "^17.0.35",
39
+ "concurrently": "^10.0.5",
40
+ "eslint": "^10.12.0",
41
+ "prettier": "^3.9.9",
42
+ "typescript": "^6.0.3"
43
+ },
44
+ "engines": {
45
+ "node": "22.* || >= 24"
46
+ },
47
+ "scripts": {
48
+ "build": "sh build.sh --production",
49
+ "format": "prettier . --cache --write",
50
+ "lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\"",
51
+ "lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\" && pnpm format",
52
+ "lint:format": "prettier . --cache --check",
53
+ "lint:js": "eslint . --cache",
54
+ "lint:js:fix": "eslint . --fix",
55
+ "lint:types": "tsc --noEmit",
56
+ "release:prepare": "changeset version",
57
+ "release:publish": "pnpm build && changeset publish",
58
+ "test": "sh build.sh --test && mt dist-for-testing --quiet"
59
+ }
60
+ }