Skip to content

Commit

Permalink
chore: Added types
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlee2 committed Jun 12, 2023
1 parent d760207 commit 10d026f
Show file tree
Hide file tree
Showing 64 changed files with 453 additions and 145 deletions.
11 changes: 6 additions & 5 deletions bin/ember-codemod-pod-to-octane.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node
'use strict';

import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import { runCodemod } from '../src/index.js';
import type { CodemodOptions } from '../src/types/index.js';

// Provide a title to the process in `ps`
process.title = 'ember-codemod-pod-to-octane';

// Set codemod options
const { argv } = yargs(hideBin(process.argv))
const argv = yargs(hideBin(process.argv))
.option('pod-path', {
default: '',
describe: 'Namespace used for the pod layout',
Expand All @@ -26,13 +26,14 @@ const { argv } = yargs(hideBin(process.argv))
type: 'boolean',
})
.option('type', {
choices: ['addon', 'app', 'engine'],
choices: ['addon', 'app', 'engine'] as const,
demandOption: true,
describe: 'Type of your Ember project',
type: 'string',
});
})
.parseSync();

const codemodOptions = {
const codemodOptions: CodemodOptions = {
podPath: argv['pod-path'],
projectRoot: argv['root'] ?? process.cwd(),
projectType: argv['type'],
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
migrateEmberApp,
migrateEmberEngine,
} from './migration/index.js';
import type { CodemodOptions } from './types/index.js';

export function runCodemod(codemodOptions) {
export function runCodemod(codemodOptions: CodemodOptions): void {
switch (codemodOptions.projectType) {
case 'addon': {
migrateEmberAddon(codemodOptions);
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/addon/component-classes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentClasses(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentClasses(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('addon/components/**/component.{d.ts,js,ts}', {
Expand All @@ -13,7 +17,7 @@ export function migrationStrategyForComponentClasses(options) {
directory: 'addon/components',
file: 'component',
},
replace: (key) => {
replace: (key: string) => {
return `addon/components/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/addon/component-stylesheets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentStylesheets(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentStylesheets(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('addon/components/**/styles.{css,scss}', {
Expand All @@ -13,7 +17,7 @@ export function migrationStrategyForComponentStylesheets(options) {
directory: 'addon/components',
file: 'styles',
},
replace: (key) => {
replace: (key: string) => {
return `addon/components/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/addon/component-templates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentTemplates(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentTemplates(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('addon/components/**/template.hbs', {
Expand All @@ -13,7 +17,7 @@ export function migrationStrategyForComponentTemplates(options) {
directory: 'addon/components',
file: 'template',
},
replace: (key) => {
replace: (key: string) => {
return `addon/components/${key}`;
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/migration/ember-addon/addon/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { FilePathMap, Options } from '../../../types/index.js';
import { migrationStrategyForComponentClasses } from './component-classes.js';
import { migrationStrategyForComponentStylesheets } from './component-stylesheets.js';
import { migrationStrategyForComponentTemplates } from './component-templates.js';

export function migrationStrategyForAddonFolder(options) {
export function migrationStrategyForAddonFolder(options: Options): FilePathMap {
return new Map([
...migrationStrategyForComponentClasses(options),
...migrationStrategyForComponentStylesheets(options),
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/app/component-classes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentClasses(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentClasses(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('app/components/**/component.js', {
Expand All @@ -13,7 +17,7 @@ export function migrationStrategyForComponentClasses(options) {
directory: 'app/components',
file: 'component',
},
replace: (key) => {
replace: (key: string) => {
return `app/components/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/app/component-stylesheets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentStylesheets(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentStylesheets(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('app/components/**/styles.js', {
Expand All @@ -13,7 +17,7 @@ export function migrationStrategyForComponentStylesheets(options) {
directory: 'app/components',
file: 'styles',
},
replace: (key) => {
replace: (key: string) => {
return `app/components/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/app/component-templates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentTemplates(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentTemplates(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('app/components/**/template.js', {
Expand All @@ -13,7 +17,7 @@ export function migrationStrategyForComponentTemplates(options) {
directory: 'app/components',
file: 'template',
},
replace: (key) => {
replace: (key: string) => {
return `app/components/${key}`;
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/migration/ember-addon/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { FilePathMap, Options } from '../../../types/index.js';
import { migrationStrategyForComponentClasses } from './component-classes.js';
import { migrationStrategyForComponentStylesheets } from './component-stylesheets.js';
import { migrationStrategyForComponentTemplates } from './component-templates.js';

export function migrationStrategyForAppFolder(options) {
export function migrationStrategyForAppFolder(options: Options): FilePathMap {
return new Map([
...migrationStrategyForComponentClasses(options),
...migrationStrategyForComponentStylesheets(options),
Expand Down
3 changes: 2 additions & 1 deletion src/migration/ember-addon/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { moveFiles } from '@codemod-utils/files';

import type { CodemodOptions } from '../../types/index.js';
import { updatePathsInAppFolder } from '../../utils/ember-addon/app/components.js';
import { migrationStrategyForAddonFolder } from './addon/index.js';
import { migrationStrategyForAppFolder } from './app/index.js';
import { createOptions } from './steps/index.js';
import { migrationStrategyForTestsFolder } from './tests/index.js';

export function migrateEmberAddon(codemodOptions) {
export function migrateEmberAddon(codemodOptions: CodemodOptions): void {
const options = createOptions(codemodOptions);

const migrationStrategyAddon = migrationStrategyForAddonFolder(options);
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/steps/create-options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { readPackageJson } from '@codemod-utils/json';

function analyzePackageJson(codemodOptions) {
import type { CodemodOptions, Options } from '../../../types/index.js';

function analyzePackageJson(
codemodOptions: CodemodOptions,
): string | undefined {
const packageJson = readPackageJson(codemodOptions);

return packageJson.name;
}

export function createOptions(codemodOptions) {
export function createOptions(codemodOptions: CodemodOptions): Options {
const projectName = analyzePackageJson(codemodOptions);

return {
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-addon/tests/components.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponents(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponents(
options: Options,
): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles(
Expand All @@ -16,7 +20,7 @@ export function migrationStrategyForComponents(options) {
directory: 'tests/integration/components',
file: 'component-test',
},
replace: (key) => {
replace: (key: string) => {
return `tests/integration/components/${key}-test`;
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/migration/ember-addon/tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { FilePathMap, Options } from '../../../types/index.js';
import { migrationStrategyForComponents } from './components.js';

export function migrationStrategyForTestsFolder(options) {
export function migrationStrategyForTestsFolder(options: Options): FilePathMap {
return new Map([...migrationStrategyForComponents(options)]);
}
8 changes: 6 additions & 2 deletions src/migration/ember-app/app/component-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { join } from 'node:path';

import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentClasses(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentClasses(
options: Options,
): FilePathMapEntries {
const { podPath, projectRoot } = options;

const filePaths = findFiles(
Expand All @@ -18,7 +22,7 @@ export function migrationStrategyForComponentClasses(options) {
directory: join('app', podPath, 'components'),
file: 'component',
},
replace: (key) => {
replace: (key: string) => {
return `app/components/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-app/app/component-stylesheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { join } from 'node:path';

import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentStylesheets(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentStylesheets(
options: Options,
): FilePathMapEntries {
const { podPath, projectRoot } = options;

const filePaths = findFiles(
Expand All @@ -18,7 +22,7 @@ export function migrationStrategyForComponentStylesheets(options) {
directory: join('app', podPath, 'components'),
file: 'styles',
},
replace: (key) => {
replace: (key: string) => {
return `app/components/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-app/app/component-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { join } from 'node:path';

import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForComponentTemplates(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForComponentTemplates(
options: Options,
): FilePathMapEntries {
const { podPath, projectRoot } = options;

const filePaths = findFiles(
Expand All @@ -18,7 +22,7 @@ export function migrationStrategyForComponentTemplates(options) {
directory: join('app', podPath, 'components'),
file: 'template',
},
replace: (key) => {
replace: (key: string) => {
return `app/components/${key}`;
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/migration/ember-app/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FilePathMap, Options } from '../../../types/index.js';
import { migrationStrategyForComponentClasses } from './component-classes.js';
import { migrationStrategyForComponentStylesheets } from './component-stylesheets.js';
import { migrationStrategyForComponentTemplates } from './component-templates.js';
Expand All @@ -10,7 +11,7 @@ import { migrationStrategyForRouteStylesheets } from './route-stylesheets.js';
import { migrationStrategyForRouteTemplates } from './route-templates.js';
import { migrationStrategyForServices } from './services.js';

export function migrationStrategyForAppFolder(options) {
export function migrationStrategyForAppFolder(options: Options): FilePathMap {
return new Map([
...migrationStrategyForComponentClasses(options),
...migrationStrategyForComponentStylesheets(options),
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-app/app/route-adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { join } from 'node:path';

import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForRouteAdapters(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForRouteAdapters(
options: Options,
): FilePathMapEntries {
const { podPath, projectRoot } = options;

const filePaths = findFiles(join('app', podPath, '**', 'adapter.{js,ts}'), {
Expand All @@ -15,7 +19,7 @@ export function migrationStrategyForRouteAdapters(options) {
directory: join('app', podPath),
file: 'adapter',
},
replace: (key) => {
replace: (key: string) => {
return `app/adapters/${key}`;
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/migration/ember-app/app/route-controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { join } from 'node:path';

import { findFiles, renamePathByFile } from '@codemod-utils/files';

export function migrationStrategyForRouteControllers(options) {
import type { FilePathMapEntries, Options } from '../../../types/index.js';

export function migrationStrategyForRouteControllers(
options: Options,
): FilePathMapEntries {
const { podPath, projectRoot } = options;

const filePaths = findFiles(
Expand All @@ -18,7 +22,7 @@ export function migrationStrategyForRouteControllers(options) {
directory: join('app', podPath),
file: 'controller',
},
replace: (key) => {
replace: (key: string) => {
return `app/controllers/${key}`;
},
});
Expand Down
Loading

0 comments on commit 10d026f

Please sign in to comment.