Skip to content

Commit 0715811

Browse files
authored
Introduced TypeScript (#41)
* chore: Configured eslint and prettier * chore: Installed typescript * chore: Patched @codemod-utils packages * chore: Updated file extension * chore: Added types * chore: Fixed capitalization * bugfix: Prevented typescript from compiling or type-checking blueprints --------- Co-authored-by: ijlee2 <[email protected]>
1 parent 7df71c5 commit 0715811

File tree

123 files changed

+1071
-234
lines changed

Some content is hidden

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

123 files changed

+1071
-234
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# compiled output
22
/dist/
3+
/dist-for-testing/
34
/tmp/
45

56
# dependencies
@@ -8,5 +9,5 @@
89
# misc
910
!.*
1011
.*/
11-
/src/blueprints/
12+
/blueprints/
1213
/tests/fixtures/

.eslintrc.cjs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,58 @@
22

33
module.exports = {
44
root: true,
5-
parser: '@babel/eslint-parser',
5+
parser: '@typescript-eslint/parser',
66
parserOptions: {
77
ecmaVersion: 'latest',
8-
requireConfigFile: false,
98
sourceType: 'module',
109
},
11-
plugins: ['simple-import-sort'],
10+
plugins: ['@typescript-eslint', 'simple-import-sort', 'typescript-sort-keys'],
1211
extends: [
1312
'eslint:recommended',
1413
'plugin:import/recommended',
14+
'plugin:import/typescript',
1515
'plugin:n/recommended',
1616
'plugin:prettier/recommended',
17+
'plugin:typescript-sort-keys/recommended',
1718
],
1819
rules: {
1920
curly: 'error',
2021
'simple-import-sort/exports': 'error',
2122
'simple-import-sort/imports': 'error',
2223
},
23-
env: {
24-
es6: true,
25-
node: true,
24+
settings: {
25+
'import/resolver': {
26+
node: true,
27+
typescript: true,
28+
},
2629
},
27-
overrides: [],
30+
overrides: [
31+
// TypeScript files
32+
{
33+
files: ['**/*.{cts,ts}'],
34+
extends: [
35+
'plugin:@typescript-eslint/eslint-recommended',
36+
'plugin:@typescript-eslint/recommended',
37+
],
38+
rules: {
39+
'@typescript-eslint/array-type': 'error',
40+
},
41+
},
42+
// TypeScript and JavaScript files
43+
{
44+
files: ['**/*.{cjs,cts,js,ts}'],
45+
rules: {
46+
'import/no-duplicates': 'error',
47+
},
48+
},
49+
// Node files
50+
{
51+
files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'],
52+
env: {
53+
browser: false,
54+
node: true,
55+
},
56+
extends: ['plugin:n/recommended'],
57+
},
58+
],
2859
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# compiled output
22
dist/
3+
dist-for-testing/
34
tmp/
45

56
# dependencies

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# compiled output
2-
/dist/
2+
/dist-for-testing/
33
/tmp/
44

55
# dependencies

.prettierrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module.exports = {
44
overrides: [
55
{
6-
files: '*.{cjs,js}',
6+
files: '*.{cjs,cts,js,mjs,mts,ts}',
77
options: {
88
printWidth: 80,
99
singleQuote: true,

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ To better meet your needs, consider cloning the repo and running the codemod loc
102102

103103
```sh
104104
cd <your/cloned/repo>
105-
./bin/ember-codemod-v1-to-v2.js --root=<your/project/path>
105+
106+
# Compile TypeScript
107+
pnpm build
108+
109+
# Run codemod
110+
./dist/bin/ember-codemod-v1-to-v2.js --root=<your/project/path>
106111
```
107112

108113
You can also look at another codemod called [`ember-addon-migrator`](https://github.com/NullVoxPopuli/ember-addon-migrator).

bin/ember-codemod-v1-to-v2.js renamed to bin/ember-codemod-v1-to-v2.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/usr/bin/env node
2+
// eslint-disable-next-line n/shebang
23
'use strict';
34

45
import yargs from 'yargs';
56
import { hideBin } from 'yargs/helpers';
67

78
import { runCodemod } from '../src/index.js';
9+
import type { CodemodOptions } from '../src/types/index.js';
810

911
// Provide a title to the process in `ps`
1012
process.title = 'ember-codemod-v1-to-v2';
1113

1214
// Set codemod options
13-
const { argv } = yargs(hideBin(process.argv))
15+
const argv = yargs(hideBin(process.argv))
1416
.option('addon-location', {
1517
describe: 'Location of the addon package',
1618
type: 'string',
@@ -26,13 +28,14 @@ const { argv } = yargs(hideBin(process.argv))
2628
.option('test-app-name', {
2729
describe: 'Name of the test-app package',
2830
type: 'string',
29-
});
31+
})
32+
.parseSync();
3033

31-
function castEmptyStringToUndefined(string) {
32-
return string === '' ? undefined : string;
34+
function castEmptyStringToUndefined(value?: string): string | undefined {
35+
return value === '' ? undefined : value;
3336
}
3437

35-
const codemodOptions = {
38+
const codemodOptions: CodemodOptions = {
3639
addonLocation: castEmptyStringToUndefined(argv['addon-location']),
3740
projectRoot: argv['root'] ?? process.cwd(),
3841
testAppLocation: castEmptyStringToUndefined(argv['test-app-location']),

0 commit comments

Comments
 (0)