diff --git a/.changeset/swift-foxes-brake.md b/.changeset/swift-foxes-brake.md new file mode 100644 index 00000000..b5f7446d --- /dev/null +++ b/.changeset/swift-foxes-brake.md @@ -0,0 +1,5 @@ +--- +"@codemod-utils/cli": minor +--- + +Created @codemod-utils/cli diff --git a/README.md b/README.md index 323aa13c..2f53848f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,11 @@ _Utilities for writing codemods_ ## What is it? -`@codemod-utils` provides a set of **tools and conventions** to help you write codemods. +`@codemod-utils` provides a set of **tools and conventions** to help you write codemods. Use `@codemod-utils/cli` to get started. + +```sh +npx @codemod-utils/cli --name +``` ### Package overview @@ -15,6 +19,7 @@ _Utilities for writing codemods_ - [`@codemod-utils/ast-javascript`](/packages/ast/javascript/README.md) - [`@codemod-utils/ast-template`](/packages/ast/template/README.md) - [`@codemod-utils/blueprints`](/packages/blueprints/README.md) +- [`@codemod-utils/cli`](/packages/cli/README.md) - [`@codemod-utils/ember-cli-string`](/packages/ember-cli-string/README.md) - [`@codemod-utils/files`](/packages/files/README.md) - [`@codemod-utils/json`](/packages/json/README.md) diff --git a/packages/cli/.eslintignore b/packages/cli/.eslintignore new file mode 100644 index 00000000..771057c8 --- /dev/null +++ b/packages/cli/.eslintignore @@ -0,0 +1,13 @@ +# compiled output +/dist/ +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +!.* +.*/ +/src/blueprints/ +/tests/fixtures/ diff --git a/packages/cli/.eslintrc.cjs b/packages/cli/.eslintrc.cjs new file mode 100644 index 00000000..40a081a2 --- /dev/null +++ b/packages/cli/.eslintrc.cjs @@ -0,0 +1,7 @@ +'use strict'; + +require('@shared-configs/eslint-config-node/patch'); + +module.exports = { + extends: ['@shared-configs/eslint-config-node/typescript'], +}; diff --git a/packages/cli/.npmignore b/packages/cli/.npmignore new file mode 100644 index 00000000..7856b458 --- /dev/null +++ b/packages/cli/.npmignore @@ -0,0 +1,22 @@ +# compiled output +/tmp/ + +# dependencies +/node_modules/ + +# misc +/.DS_Store +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.cjs +/.git/ +/.github/ +/.gitignore +/.pnpm-debug.log +/.prettierignore +/.prettierrc.cjs +/build.sh +/codemod-test-fixture.sh +/codemod-test-fixtures.sh +/tests/ diff --git a/packages/cli/.prettierrc.cjs b/packages/cli/.prettierrc.cjs new file mode 100644 index 00000000..038d697a --- /dev/null +++ b/packages/cli/.prettierrc.cjs @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('@shared-configs/prettier'); diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md new file mode 100644 index 00000000..5efd0275 --- /dev/null +++ b/packages/cli/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog for @codemod-utils/cli diff --git a/packages/cli/LICENSE.md b/packages/cli/LICENSE.md new file mode 100644 index 00000000..030bef44 --- /dev/null +++ b/packages/cli/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2023 Isaac J. Lee + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/packages/cli/README.md b/packages/cli/README.md new file mode 100644 index 00000000..793c3bc4 --- /dev/null +++ b/packages/cli/README.md @@ -0,0 +1,97 @@ +[![This project uses GitHub Actions for continuous integration.](https://github.com/ijlee2/codemod-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/ijlee2/codemod-utils/actions/workflows/ci.yml) + +# @codemod-utils/cli + +_CLI to create a codemod_ + + +## Usage + +Use `npx` to run `@codemod-utils/cli` and provide the codemod's name. (Alternatively, you can globally install `@codemod-utils/cli`.) + +```sh +npx @codemod-utils/cli --name +``` + +This will create a folder named ``. Change to this directory, then run the following scripts: + +```sh +# Install dependencies +pnpm install + +# Push to a (new) GitHub repository +git init +git add . +git commit -m "Initial commit" +git branch -M main +git remote add origin git@github.com:/.git +git push -u origin main +``` + + +### Arguments + +You must pass `--name` to name your codemod. + +```sh +npx @codemod-utils/cli --name ember-codemod-v1-to-v2 +``` + + +
+Optional: Add @codemod-utils packages + +By default, `@codemod-utils/cli` only installs [`@codemod-utils/files`](../files/README.md) and [`@codemod-utils/tests`](../tests/README.md). To add more utilities, pass `--addon` and the list of package names. + +```sh +npx @codemod-utils/cli --addon blueprints json +``` + +The available package names are: + +- [`ast-javascript`](../ast/javascript/README.md) +- [`ast-template`](../ast/template/README.md) +- [`blueprints`](../blueprints/README.md) +- [`ember-cli-string`](../ember-cli-string/README.md) +- [`json`](../json/README.md) + +
+ + +
+Optional: Specify the project root + +Pass `--root` to run the codemod somewhere else (i.e. not in the current directory). + +```sh +npx @codemod-utils/cli --root= +``` + +
+ + +
+Optional: Create a JavaScript project + +By default, `@codemod-utils/cli` creates a TypeScript project to help you maintain and extend the codemod. To create a JavaScript project, set `--typescript` to `false`. + +```sh +npx @codemod-utils/cli --typescript false +``` + +
+ + +## Compatibility + +- Node.js v16 or above + + +## Contributing + +See the [Contributing](../../CONTRIBUTING.md) guide for details. + + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/cli/bin/cli.ts b/packages/cli/bin/cli.ts new file mode 100644 index 00000000..531afee6 --- /dev/null +++ b/packages/cli/bin/cli.ts @@ -0,0 +1,50 @@ +#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'use strict'; + +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +import { createCodemod } from '../src/migration/index.js'; +import type { CodemodOptions } from '../src/types/index.js'; + +// Provide a title to the process in `ps` +process.title = '@codemod-utils/cli'; + +// Set codemod options +const argv = yargs(hideBin(process.argv)) + .option('addon', { + choices: [ + 'ast-javascript', + 'ast-template', + 'blueprints', + 'ember-cli-string', + 'json', + ] as const, + describe: 'Optional @codemod-utils packages to install', + type: 'array', + }) + .option('name', { + demandOption: true, + describe: 'Name of your codemod', + type: 'string', + }) + .option('root', { + describe: 'Where to run @codemod-utils/cli', + type: 'string', + }) + .option('typescript', { + default: true, + describe: 'Create a TypeScript project?', + type: 'boolean', + }) + .parseSync(); + +const codemodOptions: CodemodOptions = { + addons: new Set(argv['addon']), + hasTypeScript: argv['typescript'], + name: argv['name'], + projectRoot: argv['root'] ?? process.cwd(), +}; + +createCodemod(codemodOptions); diff --git a/packages/cli/build.sh b/packages/cli/build.sh new file mode 100755 index 00000000..94a6267e --- /dev/null +++ b/packages/cli/build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +COMMAND="cli" +ENVIRONMENT=$1 + +if [ $ENVIRONMENT = "--production" ] +then + # Clean slate + rm -rf "dist" + + # Compile TypeScript + tsc --project "tsconfig.build.json" + + # Configure files + chmod +x "dist/bin/$COMMAND.js" + + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist/src/blueprints" + fi + + echo "SUCCESS: Built dist.\n" + +elif [ $ENVIRONMENT = "--test" ] +then + # Clean slate + rm -rf "dist-for-testing" + + # Compile TypeScript + tsc --project "tsconfig.json" + + # Configure files + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist-for-testing/src/blueprints" + fi + + echo "SUCCESS: Built dist-for-testing.\n" + +fi diff --git a/packages/cli/codemod-test-fixture.sh b/packages/cli/codemod-test-fixture.sh new file mode 100755 index 00000000..56c04a96 --- /dev/null +++ b/packages/cli/codemod-test-fixture.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix the expected output of a test fixture after updating the source code. +# +# B. Usage +# +# For named arguments, do not include `=` between the flag and the value. +# Positional arguments are to appear at the end. +# +# ./codemod-test-fixture.sh [OPTIONAL-FLAGS] +# +#--------- + +# Get named arguments for the binary +while getopts ":N:" flag +do + case $flag in + N) NAMED_ARGUMENTS=$OPTARG;; + esac +done + +# Get fixture name +FIXTURE=${@:$OPTIND:1} + +if [ ! $FIXTURE ] +then + echo "ERROR: Please specify the fixture name.\n" + exit 1 +elif [ ! -d "tests/fixtures/$FIXTURE/input" ] +then + echo "ERROR: Input folder \`tests/fixtures/$FIXTURE/input\` does not exist.\n" + exit 1 +fi + +rm -r "tests/fixtures/$FIXTURE/output" +cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output" + +./dist/bin/cli.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output" + +echo "SUCCESS: Updated the output of $FIXTURE.\n" diff --git a/packages/cli/codemod-test-fixtures.sh b/packages/cli/codemod-test-fixtures.sh new file mode 100755 index 00000000..562956d4 --- /dev/null +++ b/packages/cli/codemod-test-fixtures.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix all test fixtures after updating the source code. +# +# B. Usage +# +# ./codemod-test-fixtures.sh +# +#--------- + +# Compile TypeScript +pnpm build + +./codemod-test-fixture.sh \ + -N "--name ember-codemod-pod-to-octane --typescript false" \ + javascript + +./codemod-test-fixture.sh \ + -N "--addon ast-javascript ast-template blueprints ember-cli-string json --name ember-codemod-args-to-signature --typescript false" \ + javascript-with-addons + +./codemod-test-fixture.sh \ + -N "--name ember-codemod-pod-to-octane" \ + typescript + +./codemod-test-fixture.sh \ + -N "--addon ast-javascript ast-template blueprints ember-cli-string json --name ember-codemod-args-to-signature" \ + typescript-with-addons diff --git a/packages/cli/package.json b/packages/cli/package.json new file mode 100644 index 00000000..87991073 --- /dev/null +++ b/packages/cli/package.json @@ -0,0 +1,55 @@ +{ + "name": "@codemod-utils/cli", + "version": "0.0.0", + "description": "CLI to create a codemod", + "keywords": [ + "codemod", + "ember-codemod" + ], + "repository": { + "type": "git", + "url": "git@github.com:ijlee2/codemod-utils.git" + }, + "license": "MIT", + "author": "Isaac J. Lee", + "type": "module", + "main": "dist/src/index.js", + "bin": "dist/bin/cli.js", + "directories": { + "test": "tests" + }, + "files": [ + "dist" + ], + "scripts": { + "build": "./build.sh --production", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "lint:types": "tsc --noEmit", + "test": "./build.sh --test && mt dist-for-testing --quiet" + }, + "dependencies": { + "@codemod-utils/blueprints": "workspace:*", + "@codemod-utils/files": "workspace:*", + "@codemod-utils/json": "workspace:*", + "yargs": "^17.7.2" + }, + "devDependencies": { + "@codemod-utils/tests": "workspace:*", + "@shared-configs/eslint-config-node": "workspace:*", + "@shared-configs/prettier": "workspace:*", + "@shared-configs/typescript": "workspace:*", + "@sondr3/minitest": "^0.1.1", + "@types/node": "^16.11.7", + "@types/yargs": "^17.0.24", + "concurrently": "^8.2.0", + "eslint": "^8.44.0", + "prettier": "^2.8.8", + "typescript": "^5.1.6" + }, + "engines": { + "node": "16.* || >= 18" + } +} diff --git a/packages/cli/src/blueprints/.eslintignore b/packages/cli/src/blueprints/.eslintignore new file mode 100644 index 00000000..771057c8 --- /dev/null +++ b/packages/cli/src/blueprints/.eslintignore @@ -0,0 +1,13 @@ +# compiled output +/dist/ +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +!.* +.*/ +/src/blueprints/ +/tests/fixtures/ diff --git a/packages/cli/src/blueprints/.eslintrc.cjs b/packages/cli/src/blueprints/.eslintrc.cjs new file mode 100644 index 00000000..e5749379 --- /dev/null +++ b/packages/cli/src/blueprints/.eslintrc.cjs @@ -0,0 +1,99 @@ +'use strict'; + +<% if (options.codemod.hasTypeScript) { %>module.exports = { + root: true, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + plugins: ['@typescript-eslint', 'simple-import-sort', 'typescript-sort-keys'], + extends: [ + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'plugin:n/recommended', + 'plugin:prettier/recommended', + 'plugin:typescript-sort-keys/recommended', + ], + rules: { + curly: 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', + }, + settings: { + 'import/resolver': { + node: true, + typescript: true, + }, + }, + overrides: [ + // TypeScript files + { + files: ['**/*.{cts,ts}'], + extends: [ + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + ], + rules: { + '@typescript-eslint/array-type': 'error', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + }, + }, + // TypeScript and JavaScript files + { + files: ['**/*.{cjs,cts,js,ts}'], + rules: { + 'import/no-duplicates': 'error', + }, + }, + // Node files + { + files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'], + env: { + browser: false, + node: true, + }, + extends: ['plugin:n/recommended'], + }, + ], +};<% } else { %>module.exports = { + root: true, + parser: '@babel/eslint-parser', + parserOptions: { + ecmaVersion: 'latest', + requireConfigFile: false, + sourceType: 'module', + }, + plugins: ['simple-import-sort'], + extends: [ + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:n/recommended', + 'plugin:prettier/recommended', + ], + rules: { + curly: 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', + }, + overrides: [ + // JavaScript files + { + files: ['**/*.js'], + rules: { + 'import/no-duplicates': 'error', + }, + }, + // Node files + { + files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'], + env: { + browser: false, + node: true, + }, + extends: ['plugin:n/recommended'], + }, + ], +};<% } %> diff --git a/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md new file mode 100644 index 00000000..a2f5aa1c --- /dev/null +++ b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md @@ -0,0 +1,27 @@ +--- +name: Ask for better documentation +about: Ask for better documentation +title: '' +labels: 'enhance: documentation' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve documentation. + +Here, documentation can mean a few different things, including README, code comments, and tests. Anything that will help everyone understand how to use `<%= options.codemod.name %>`! + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md new file mode 100644 index 00000000..aa30de0f --- /dev/null +++ b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md @@ -0,0 +1,27 @@ +--- +name: Ask for new feature or refactor +about: Ask for new feature or refactor +title: '' +labels: 'enhance: code' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve `<%= options.codemod.name %>`. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request already. + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/report-bug.md b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/report-bug.md new file mode 100644 index 00000000..140b92c9 --- /dev/null +++ b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/report-bug.md @@ -0,0 +1,38 @@ +--- +name: Report bug +about: Report bug +title: '' +labels: bug +assignees: '' + +--- + +Hello! Thanks for taking time to make a bug report. + +Before you make a new issue, please search for similar issues. It's possible that someone has reported this bug already. + + +## Describe the bug 🐞 + +A clear and concise description of the bug. + + +## Expected behavior 🤔 + +A clear and concise description of what you expected to see. + + +## Minimal reproduction 🔬 + +Describe steps to reproduce the issue. + +1. ... +1. ... +1. ... + +If possible, please share a repo with the minimum files to reproduce the issue. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/report-outdated-dependency.md b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/report-outdated-dependency.md new file mode 100644 index 00000000..3fb22da0 --- /dev/null +++ b/packages/cli/src/blueprints/.github/ISSUE_TEMPLATE/report-outdated-dependency.md @@ -0,0 +1,35 @@ +--- +name: Report outdated dependency +about: Report outdated dependency +title: '' +labels: 'enhance: dependency' +assignees: '' + +--- + +Hello! Thanks for taking time to make an outdated dependency report. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request for update already. + + +## List outdated dependencies 🔗 + +When you ran `pnpm outdated`, what did you see? + +```sh +┌────────────────────────┬─────────┬────────┐ +│ Package │ Current │ Latest │ +├────────────────────────┼─────────┼────────┤ +│ @sondr3/minitest (dev) │ 0.1.1 │ 0.1.2 │ +└────────────────────────┴─────────┴────────┘ +``` + + +## Risk analysis ⚠️ + +Are there breaking changes that we should be aware of? Please add links to the `CHANGELOG`s, if they are available. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/src/blueprints/.github/workflows/ci.yml b/packages/cli/src/blueprints/.github/workflows/ci.yml new file mode 100644 index 00000000..5a6e74c7 --- /dev/null +++ b/packages/cli/src/blueprints/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +env: + NODE_VERSION: 16 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm lint + + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test diff --git a/packages/cli/src/blueprints/.npmignore b/packages/cli/src/blueprints/.npmignore new file mode 100644 index 00000000..fc33b3b8 --- /dev/null +++ b/packages/cli/src/blueprints/.npmignore @@ -0,0 +1,25 @@ +# compiled output +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +/.DS_Store +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.cjs +/.git/ +/.github/ +/.gitignore +/.pnpm-debug.log +/.prettierignore +/.prettierrc.cjs +/build.sh +/codemod-test-fixture.sh +/codemod-test-fixtures.sh +/CONTRIBUTING.md +/create-test-fixture.sh +/tests/ diff --git a/packages/cli/src/blueprints/.prettierrc.cjs b/packages/cli/src/blueprints/.prettierrc.cjs new file mode 100644 index 00000000..7de3332b --- /dev/null +++ b/packages/cli/src/blueprints/.prettierrc.cjs @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + overrides: [ + { + <% if (options.codemod.hasTypeScript) { %>files: '*.{cjs,cts,js,mjs,mts,ts}',<% } else { %>files: '*.{cjs,js,mjs}',<% } %> + options: { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + }, + }, + ], +}; diff --git a/packages/cli/src/blueprints/CHANGELOG.md b/packages/cli/src/blueprints/CHANGELOG.md new file mode 100644 index 00000000..825c32f0 --- /dev/null +++ b/packages/cli/src/blueprints/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/cli/src/blueprints/CONTRIBUTING.md b/packages/cli/src/blueprints/CONTRIBUTING.md new file mode 100644 index 00000000..b0ab17f0 --- /dev/null +++ b/packages/cli/src/blueprints/CONTRIBUTING.md @@ -0,0 +1,86 @@ +# Contributing to <%= options.codemod.name %> + +Open source projects like `<%= options.codemod.name %>` live on your words of encouragement and contribution. Please give feedback, report issues, or submit pull requests! + +Here are some guidelines to help you and everyone else. + + +## Local development + +
+Install dependencies + +1. Fork and clone this repo. + + ```sh + git clone git@github.com:/<%= options.codemod.name %>.git + ``` + +1. Change directory. + + ```sh + cd <%= options.codemod.name %> + ``` + +1. Use [`pnpm`](https://pnpm.io/installation) to install dependencies. + + ```sh + pnpm install + ``` + +
+ + +
+Lint files + +1. When you write code, please check that it meets the linting rules. + + ```sh + pnpm lint + ``` + +1. You can run `lint:fix` to automatically fix linting errors. + + ```sh + pnpm lint:fix + ``` + +
+ + +
+Run tests + +1. When you write code, please check that all tests continue to pass. + + ```sh + pnpm test + ``` + +
+ + +
+ +Publish packages (for admins) + +1. Generate a [personal access token](https://github.com/settings/tokens/) in GitHub, with default values for scopes (none selected). + +1. Run the `changelog` script. This generates a text that you can add to `CHANGELOG.md`. + + ```sh + GITHUB_AUTH= pnpm changelog + ``` + +1. The package follows [semantic versioning](https://semver.org/). Update the version in `package.json` accordingly. + +1. Create a tag and provide release notes. The tag name should match the package version. + +1. Publish the package. + + ```sh + pnpm publish + ``` + +
diff --git a/packages/cli/src/blueprints/LICENSE.md b/packages/cli/src/blueprints/LICENSE.md new file mode 100644 index 00000000..94385605 --- /dev/null +++ b/packages/cli/src/blueprints/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2023 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/packages/cli/src/blueprints/README.md b/packages/cli/src/blueprints/README.md new file mode 100644 index 00000000..de7b12e1 --- /dev/null +++ b/packages/cli/src/blueprints/README.md @@ -0,0 +1,58 @@ +# <%= options.codemod.name %> + +_Codemod to [PROVIDE A SHORT DESCRIPTION.]_ + + +## Usage + +### Arguments + +[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.] + +
+Optional: Specify the project root + +Pass `--root` to run the codemod somewhere else (i.e. not in the current directory). + +```sh +npx <%= options.codemod.name %> --root= +``` + +
+ + +### Limitations + +The codemod is designed to cover typical cases. It is not designed to cover one-off cases. + +To better meet your needs, consider cloning the repo and running the codemod locally. + +<% if (options.codemod.hasTypeScript) { %>```sh +cd + +# Compile TypeScript +pnpm build + +# Run codemod +./dist/bin/<%= options.codemod.name %>.js --root= +```<% } else { %>```sh +cd + +# Run codemod +./bin/<%= options.codemod.name %>.js --root= +```<% } %> + + +## Compatibility + +- Node.js v16 or above + + +## Contributing + +See the [Contributing](CONTRIBUTING.md) guide for details. + + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/cli/src/blueprints/__gitignore__ b/packages/cli/src/blueprints/__gitignore__ new file mode 100644 index 00000000..cc33aa0e --- /dev/null +++ b/packages/cli/src/blueprints/__gitignore__ @@ -0,0 +1,12 @@ +# compiled output +dist/ +dist-for-testing/ +tmp/ + +# dependencies +node_modules/ + +# misc +.DS_Store +.env* +.eslintcache diff --git a/packages/cli/src/blueprints/bin/__codemod-name__.__js__ b/packages/cli/src/blueprints/bin/__codemod-name__.__js__ new file mode 100644 index 00000000..e8279e73 --- /dev/null +++ b/packages/cli/src/blueprints/bin/__codemod-name__.__js__ @@ -0,0 +1,50 @@ +<% if (options.codemod.hasTypeScript) { %>#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'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 = '<%= options.codemod.name %>'; + +// Set codemod options +const argv = yargs(hideBin(process.argv)) + .option('root', { + describe: 'Where to run the codemod', + type: 'string', + }) + .parseSync(); + +const codemodOptions: CodemodOptions = { + projectRoot: argv['root'] ?? process.cwd(), +}; + +runCodemod(codemodOptions);<% } else { %>#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'use strict'; + +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +import { runCodemod } from '../src/index.js'; + +// Provide a title to the process in `ps` +process.title = '<%= options.codemod.name %>'; + +// Set codemod options +const argv = yargs(hideBin(process.argv)) + .option('root', { + describe: 'Where to run the codemod', + type: 'string', + }) + .parseSync(); + +const codemodOptions = { + projectRoot: argv['root'] ?? process.cwd(), +}; + +runCodemod(codemodOptions);<% } %> diff --git a/packages/cli/src/blueprints/build.sh b/packages/cli/src/blueprints/build.sh new file mode 100644 index 00000000..2258fde2 --- /dev/null +++ b/packages/cli/src/blueprints/build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +COMMAND="<%= options.codemod.name %>" +ENVIRONMENT=$1 + +if [ $ENVIRONMENT = "--production" ] +then + # Clean slate + rm -rf "dist" + + # Compile TypeScript + tsc --project "tsconfig.build.json" + + # Configure files + chmod +x "dist/bin/$COMMAND.js" + + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist/src/blueprints" + fi + + echo "SUCCESS: Built dist.\n" + +elif [ $ENVIRONMENT = "--test" ] +then + # Clean slate + rm -rf "dist-for-testing" + + # Compile TypeScript + tsc --project "tsconfig.json" + + # Configure files + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist-for-testing/src/blueprints" + fi + + echo "SUCCESS: Built dist-for-testing.\n" + +fi diff --git a/packages/cli/src/blueprints/codemod-test-fixture.sh b/packages/cli/src/blueprints/codemod-test-fixture.sh new file mode 100644 index 00000000..5b08ff68 --- /dev/null +++ b/packages/cli/src/blueprints/codemod-test-fixture.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix the expected output of a test fixture after updating the source code. +# +# B. Usage +# +# For named arguments, do not include `=` between the flag and the value. +# Positional arguments are to appear at the end. +# +# ./codemod-test-fixture.sh [OPTIONAL-FLAGS] +# +#--------- + +# Get named arguments for the binary +while getopts ":N:" flag +do + case $flag in + N) NAMED_ARGUMENTS=$OPTARG;; + esac +done + +# Get fixture name +FIXTURE=${@:$OPTIND:1} + +if [ ! $FIXTURE ] +then + echo "ERROR: Please specify the fixture name.\n" + exit 1 +elif [ ! -d "tests/fixtures/$FIXTURE/input" ] +then + echo "ERROR: Input folder \`tests/fixtures/$FIXTURE/input\` does not exist.\n" + exit 1 +fi + +rm -r "tests/fixtures/$FIXTURE/output" +cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output" + +./dist/bin/<%= options.codemod.name %>.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output" + +echo "SUCCESS: Updated the output of $FIXTURE.\n" diff --git a/packages/cli/src/blueprints/codemod-test-fixtures.sh b/packages/cli/src/blueprints/codemod-test-fixtures.sh new file mode 100644 index 00000000..9bbd5a69 --- /dev/null +++ b/packages/cli/src/blueprints/codemod-test-fixtures.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix all test fixtures after updating the source code. +# +# B. Usage +# +# ./codemod-test-fixtures.sh +# +#--------- + +# Compile TypeScript +<% if (options.codemod.hasTypeScript) { %>pnpm build<% } else { %># pnpm build<% } %> + +./codemod-test-fixture.sh \ + -N "" \ + sample-project diff --git a/packages/cli/src/blueprints/package.json b/packages/cli/src/blueprints/package.json new file mode 100644 index 00000000..575e3f62 --- /dev/null +++ b/packages/cli/src/blueprints/package.json @@ -0,0 +1,98 @@ +<% if (options.codemod.hasTypeScript) { %>{ + "name": "<%= options.codemod.name %>", + "version": "0.0.0", + "private": true, + "description": "Small description for <%= options.codemod.name %> goes here", + "keywords": [ + "codemod", + "ember-codemod", + "emberjs" + ], + "repository": "", + "license": "MIT", + "author": "", + "type": "module", + "main": "dist/src/index.js", + "bin": "dist/bin/<%= options.codemod.name %>.js", + "directories": { + "test": "tests" + }, + "files": [ + "dist" + ], + "scripts": { + "build": "./build.sh --production", + "changelog": "lerna-changelog", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "lint:types": "tsc --noEmit", + "prepare": "pnpm build", + "test": "./build.sh --test && mt dist-for-testing --quiet" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": "16.* || >= 18" + }, + "changelog": { + "labels": { + "breaking": "Breaking Change", + "bug": "Bug Fix", + "enhance: code": "Enhancement", + "enhance: dependency": "Internal", + "enhance: documentation": "Documentation" + } + }, + "pnpm": { + "overrides": { + "eslint-plugin-import@2.27.5>tsconfig-paths": "^4.2.0" + } + } +}<% } else { %>{ + "name": "<%= options.codemod.name %>", + "version": "0.0.0", + "private": true, + "description": "Small description for <%= options.codemod.name %> goes here", + "keywords": [ + "codemod", + "ember-codemod", + "emberjs" + ], + "repository": "", + "license": "MIT", + "author": "", + "type": "module", + "main": "src/index.js", + "bin": "bin/<%= options.codemod.name %>.js", + "directories": { + "test": "tests" + }, + "files": [ + "bin", + "src" + ], + "scripts": { + "changelog": "lerna-changelog", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "test": "mt --quiet" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": "16.* || >= 18" + }, + "changelog": { + "labels": { + "breaking": "Breaking Change", + "bug": "Bug Fix", + "enhance: code": "Enhancement", + "enhance: dependency": "Internal", + "enhance: documentation": "Documentation" + } + } +}<% } %> diff --git a/packages/cli/src/blueprints/src/blueprints/.gitkeep b/packages/cli/src/blueprints/src/blueprints/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/src/blueprints/src/index.__js__ b/packages/cli/src/blueprints/src/index.__js__ new file mode 100644 index 00000000..fc16e303 --- /dev/null +++ b/packages/cli/src/blueprints/src/index.__js__ @@ -0,0 +1,16 @@ +<% if (options.codemod.hasTypeScript) { %>import { addEndOfLine, createOptions } from './steps/index.js'; +import type { CodemodOptions } from './types/index.js'; + +export function runCodemod(codemodOptions: CodemodOptions): void { + const options = createOptions(codemodOptions); + + // TODO: Replace with actual steps + addEndOfLine(options); +}<% } else { %>import { addEndOfLine, createOptions } from './steps/index.js'; + +export function runCodemod(codemodOptions) { + const options = createOptions(codemodOptions); + + // TODO: Replace with actual steps + addEndOfLine(options); +}<% } %> diff --git a/packages/cli/src/blueprints/src/steps/add-end-of-line.__js__ b/packages/cli/src/blueprints/src/steps/add-end-of-line.__js__ new file mode 100644 index 00000000..fd27ad42 --- /dev/null +++ b/packages/cli/src/blueprints/src/steps/add-end-of-line.__js__ @@ -0,0 +1,49 @@ +<% if (options.codemod.hasTypeScript) { %>import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { createFiles, findFiles } from '@codemod-utils/files'; + +import type { Options } from '../types/index.js'; + +export function addEndOfLine(options: Options): void { + const { projectRoot } = options; + + const filePaths = findFiles('**/*.txt', { + projectRoot, + }); + + const fileMap = new Map( + filePaths.map((filePath) => { + const file = readFileSync(join(projectRoot, filePath), 'utf8'); + + const newFile = file.endsWith('\n') ? file : `${file}\n`; + + return [filePath, newFile]; + }), + ); + + createFiles(fileMap, options); +}<% } else { %>import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { createFiles, findFiles } from '@codemod-utils/files'; + +export function addEndOfLine(options) { + const { projectRoot } = options; + + const filePaths = findFiles('**/*.txt', { + projectRoot, + }); + + const fileMap = new Map( + filePaths.map((filePath) => { + const file = readFileSync(join(projectRoot, filePath), 'utf8'); + + const newFile = file.endsWith('\n') ? file : `${file}\n`; + + return [filePath, newFile]; + }), + ); + + createFiles(fileMap, options); +}<% } %> diff --git a/packages/cli/src/blueprints/src/steps/create-options.__js__ b/packages/cli/src/blueprints/src/steps/create-options.__js__ new file mode 100644 index 00000000..c72cbfc9 --- /dev/null +++ b/packages/cli/src/blueprints/src/steps/create-options.__js__ @@ -0,0 +1,15 @@ +<% if (options.codemod.hasTypeScript) { %>import type { CodemodOptions, Options } from '../types/index.js'; + +export function createOptions(codemodOptions: CodemodOptions): Options { + const { projectRoot } = codemodOptions; + + return { + projectRoot, + }; +}<% } else { %>export function createOptions(codemodOptions) { + const { projectRoot } = codemodOptions; + + return { + projectRoot, + }; +}<% } %> diff --git a/packages/cli/src/blueprints/src/steps/index.__js__ b/packages/cli/src/blueprints/src/steps/index.__js__ new file mode 100644 index 00000000..5435fe02 --- /dev/null +++ b/packages/cli/src/blueprints/src/steps/index.__js__ @@ -0,0 +1,2 @@ +export * from './add-end-of-line.js'; +export * from './create-options.js'; diff --git a/packages/cli/src/blueprints/src/types/index.ts b/packages/cli/src/blueprints/src/types/index.ts new file mode 100644 index 00000000..e9bbbebc --- /dev/null +++ b/packages/cli/src/blueprints/src/types/index.ts @@ -0,0 +1,9 @@ +type CodemodOptions = { + projectRoot: string; +}; + +type Options = { + projectRoot: string; +}; + +export type { CodemodOptions, Options }; diff --git a/packages/cli/src/blueprints/src/utils/blueprints.__js__ b/packages/cli/src/blueprints/src/utils/blueprints.__js__ new file mode 100644 index 00000000..1e540879 --- /dev/null +++ b/packages/cli/src/blueprints/src/utils/blueprints.__js__ @@ -0,0 +1 @@ +export * from './blueprints/blueprints-root.js'; diff --git a/packages/cli/src/blueprints/src/utils/blueprints/blueprints-root.__js__ b/packages/cli/src/blueprints/src/utils/blueprints/blueprints-root.__js__ new file mode 100644 index 00000000..237d2fb9 --- /dev/null +++ b/packages/cli/src/blueprints/src/utils/blueprints/blueprints-root.__js__ @@ -0,0 +1,7 @@ +import { join } from 'node:path'; + +import { getFilePath } from '@codemod-utils/blueprints'; + +const fileURL = import.meta.url; + +export const blueprintsRoot = join(getFilePath(fileURL), '../../blueprints'); diff --git a/packages/cli/src/blueprints/tests/fixtures/sample-project/index.__js__ b/packages/cli/src/blueprints/tests/fixtures/sample-project/index.__js__ new file mode 100644 index 00000000..a8a96766 --- /dev/null +++ b/packages/cli/src/blueprints/tests/fixtures/sample-project/index.__js__ @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('sample-project/input'); +const outputProject = convertFixtureToJson('sample-project/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/src/blueprints/tests/fixtures/sample-project/input/file.txt b/packages/cli/src/blueprints/tests/fixtures/sample-project/input/file.txt new file mode 100644 index 00000000..6769dd60 --- /dev/null +++ b/packages/cli/src/blueprints/tests/fixtures/sample-project/input/file.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/packages/cli/src/blueprints/tests/fixtures/sample-project/output/file.txt b/packages/cli/src/blueprints/tests/fixtures/sample-project/output/file.txt new file mode 100644 index 00000000..cd087558 --- /dev/null +++ b/packages/cli/src/blueprints/tests/fixtures/sample-project/output/file.txt @@ -0,0 +1 @@ +Hello world! diff --git a/packages/cli/src/blueprints/tests/helpers/shared-test-setups/sample-project.__js__ b/packages/cli/src/blueprints/tests/helpers/shared-test-setups/sample-project.__js__ new file mode 100644 index 00000000..129d4cc7 --- /dev/null +++ b/packages/cli/src/blueprints/tests/helpers/shared-test-setups/sample-project.__js__ @@ -0,0 +1,19 @@ +<% if (options.codemod.hasTypeScript) { %>import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + projectRoot: 'tmp/sample-project', +}; + +const options: Options = { + projectRoot: 'tmp/sample-project', +}; + +export { codemodOptions, options };<% } else { %>const codemodOptions = { + projectRoot: 'tmp/sample-project', +}; + +const options = { + projectRoot: 'tmp/sample-project', +}; + +export { codemodOptions, options };<% } %> diff --git a/packages/cli/src/blueprints/tests/index/sample-project.test.__js__ b/packages/cli/src/blueprints/tests/index/sample-project.test.__js__ new file mode 100644 index 00000000..7a97215f --- /dev/null +++ b/packages/cli/src/blueprints/tests/index/sample-project.test.__js__ @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { runCodemod } from '../../src/index.js'; +import { + inputProject, + outputProject, +} from '../fixtures/sample-project/index.js'; +import { codemodOptions } from '../helpers/shared-test-setups/sample-project.js'; + +test('index > sample-project', function () { + loadFixture(inputProject, codemodOptions); + + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/src/blueprints/tests/steps/add-end-of-line/base-case.test.__js__ b/packages/cli/src/blueprints/tests/steps/add-end-of-line/base-case.test.__js__ new file mode 100644 index 00000000..cf5dfe06 --- /dev/null +++ b/packages/cli/src/blueprints/tests/steps/add-end-of-line/base-case.test.__js__ @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > base case', function () { + const inputProject = { + 'file.txt': 'Hello world!', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/src/blueprints/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.__js__ b/packages/cli/src/blueprints/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.__js__ new file mode 100644 index 00000000..2340e587 --- /dev/null +++ b/packages/cli/src/blueprints/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.__js__ @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file ends with newline)', function () { + const inputProject = { + 'file.txt': 'Hello world!\n', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/src/blueprints/tests/steps/add-end-of-line/edge-case-file-is-empty.test.__js__ b/packages/cli/src/blueprints/tests/steps/add-end-of-line/edge-case-file-is-empty.test.__js__ new file mode 100644 index 00000000..218b3c4e --- /dev/null +++ b/packages/cli/src/blueprints/tests/steps/add-end-of-line/edge-case-file-is-empty.test.__js__ @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file is empty)', function () { + const inputProject = { + 'file.txt': '', + }; + + const outputProject = { + 'file.txt': '\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/src/blueprints/tests/steps/create-options/sample-project.test.__js__ b/packages/cli/src/blueprints/tests/steps/create-options/sample-project.test.__js__ new file mode 100644 index 00000000..fbfe0291 --- /dev/null +++ b/packages/cli/src/blueprints/tests/steps/create-options/sample-project.test.__js__ @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | create-options > sample-project', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/src/blueprints/tests/utils/blueprints/blueprints-root.test.__js__ b/packages/cli/src/blueprints/tests/utils/blueprints/blueprints-root.test.__js__ new file mode 100644 index 00000000..df5ed4f0 --- /dev/null +++ b/packages/cli/src/blueprints/tests/utils/blueprints/blueprints-root.test.__js__ @@ -0,0 +1,7 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { blueprintsRoot } from '../../../src/utils/blueprints.js'; + +test('utils | blueprints | blueprints-root', function () { + assert.strictEqual(blueprintsRoot.endsWith('src/blueprints'), true); +}); diff --git a/packages/cli/src/blueprints/tsconfig.build.json b/packages/cli/src/blueprints/tsconfig.build.json new file mode 100644 index 00000000..6ff3bf82 --- /dev/null +++ b/packages/cli/src/blueprints/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "@tsconfig/node16/tsconfig", + "@tsconfig/strictest/tsconfig", + "@tsconfig/esm/tsconfig" + ], + "compilerOptions": { + "declaration": false, + "moduleResolution": "NodeNext", + "outDir": "dist" + }, + "include": ["bin", "src"], + "exclude": ["src/blueprints"] +} diff --git a/packages/cli/src/blueprints/tsconfig.json b/packages/cli/src/blueprints/tsconfig.json new file mode 100644 index 00000000..dfd1d499 --- /dev/null +++ b/packages/cli/src/blueprints/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "@tsconfig/node16/tsconfig", + "@tsconfig/strictest/tsconfig", + "@tsconfig/esm/tsconfig" + ], + "compilerOptions": { + "declaration": false, + "moduleResolution": "NodeNext", + "outDir": "dist-for-testing" + }, + "include": ["bin", "src", "tests"], + "exclude": ["src/blueprints", "tests/fixtures"] +} diff --git a/packages/cli/src/migration/index.ts b/packages/cli/src/migration/index.ts new file mode 100644 index 00000000..44d16eab --- /dev/null +++ b/packages/cli/src/migration/index.ts @@ -0,0 +1,13 @@ +import type { CodemodOptions } from '../types/index.js'; +import { + createFilesFromBlueprints, + createOptions, + updatePackageJson, +} from './steps/index.js'; + +export function createCodemod(codemodOptions: CodemodOptions): void { + const options = createOptions(codemodOptions); + + createFilesFromBlueprints(options); + updatePackageJson(options); +} diff --git a/packages/cli/src/migration/steps/create-files-from-blueprints.ts b/packages/cli/src/migration/steps/create-files-from-blueprints.ts new file mode 100644 index 00000000..3e64c5c6 --- /dev/null +++ b/packages/cli/src/migration/steps/create-files-from-blueprints.ts @@ -0,0 +1,98 @@ +import { chmodSync, readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { processTemplate } from '@codemod-utils/blueprints'; +import { createFiles, findFiles } from '@codemod-utils/files'; + +import type { Options } from '../../types/index.js'; +import { blueprintsRoot } from '../../utils/blueprints.js'; + +function getFilesToSkip(options: Options): string[] { + const { codemod } = options; + + const files = new Set(); + + if (!codemod.addons.has('blueprints')) { + files.add('src/blueprints/.gitkeep'); + files.add('src/utils/blueprints/blueprints-root.__js__'); + files.add('src/utils/blueprints.__js__'); + files.add('tests/utils/blueprints/blueprints-root.test.__js__'); + } + + if (!codemod.hasTypeScript) { + files.add('build.sh'); + files.add('src/types/index.ts'); + files.add('tsconfig.build.json'); + files.add('tsconfig.json'); + } + + return Array.from(files); +} + +function resolveBlueprintFilePath( + blueprintFilePath: string, + options: Options, +): string { + const { codemod } = options; + + return blueprintFilePath + .replace('__codemod-name__', codemod.name) + .replace('__gitignore__', '.gitignore') + .replace('.__js__', codemod.hasTypeScript ? '.ts' : '.js'); +} + +function updateFilePermissions(options: Options) { + const { codemod, projectRoot } = options; + + const files = new Set([ + 'codemod-test-fixture.sh', + 'codemod-test-fixtures.sh', + ]); + + if (codemod.hasTypeScript) { + files.add(`bin/${codemod.name}.ts`); + files.add('build.sh'); + } else { + files.add(`bin/${codemod.name}.js`); + } + + Array.from(files).forEach((file) => { + const filePath = join(projectRoot, codemod.name, file); + + chmodSync(filePath, 0o755); + }); +} + +export function createFilesFromBlueprints(options: Options): void { + const { codemod } = options; + + const filesToSkip = getFilesToSkip(options); + + const blueprintFilePaths = findFiles('**/*', { + ignoreList: filesToSkip, + projectRoot: blueprintsRoot, + }); + + const fileMap = new Map( + blueprintFilePaths.map((blueprintFilePath) => { + const filePath = join( + codemod.name, + resolveBlueprintFilePath(blueprintFilePath, options), + ); + + const blueprintFile = readFileSync( + join(blueprintsRoot, blueprintFilePath), + 'utf8', + ); + + const file = processTemplate(blueprintFile, { + options, + }); + + return [filePath, file]; + }), + ); + + createFiles(fileMap, options); + updateFilePermissions(options); +} diff --git a/packages/cli/src/migration/steps/create-options.ts b/packages/cli/src/migration/steps/create-options.ts new file mode 100644 index 00000000..7b2db002 --- /dev/null +++ b/packages/cli/src/migration/steps/create-options.ts @@ -0,0 +1,14 @@ +import type { CodemodOptions, Options } from '../../types/index.js'; + +export function createOptions(codemodOptions: CodemodOptions): Options { + const { addons, hasTypeScript, name, projectRoot } = codemodOptions; + + return { + codemod: { + addons, + hasTypeScript, + name, + }, + projectRoot, + }; +} diff --git a/packages/cli/src/migration/steps/index.ts b/packages/cli/src/migration/steps/index.ts new file mode 100644 index 00000000..13085d1c --- /dev/null +++ b/packages/cli/src/migration/steps/index.ts @@ -0,0 +1,3 @@ +export * from './create-files-from-blueprints.js'; +export * from './create-options.js'; +export * from './update-package-json.js'; diff --git a/packages/cli/src/migration/steps/update-package-json.ts b/packages/cli/src/migration/steps/update-package-json.ts new file mode 100644 index 00000000..312041b6 --- /dev/null +++ b/packages/cli/src/migration/steps/update-package-json.ts @@ -0,0 +1,97 @@ +import { writeFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { + convertToMap, + convertToObject, + type PackageJson, + readPackageJson, +} from '@codemod-utils/json'; + +import type { Options } from '../../types/index.js'; +import { getVersion } from '../../utils/blueprints.js'; + +function updateDependencies(packageJson: PackageJson, options: Options): void { + const { codemod } = options; + + const dependencies = convertToMap(packageJson['dependencies']); + + const packagesToInstall = new Set(['@codemod-utils/files', 'yargs']); + + codemod.addons.forEach((identifier) => { + packagesToInstall.add(`@codemod-utils/${identifier}`); + }); + + Array.from(packagesToInstall).forEach((packageName) => { + const version = getVersion(packageName); + + dependencies.set(packageName, version); + }); + + packageJson['dependencies'] = convertToObject(dependencies); +} + +function updateDevDependencies( + packageJson: PackageJson, + options: Options, +): void { + const { codemod } = options; + + const devDependencies = convertToMap(packageJson['devDependencies']); + + const packagesToInstall = new Set([ + '@babel/core', + '@babel/eslint-parser', + '@codemod-utils/tests', + 'concurrently', + 'eslint', + 'eslint-config-prettier', + 'eslint-plugin-import', + 'eslint-plugin-n', + 'eslint-plugin-prettier', + 'eslint-plugin-simple-import-sort', + 'lerna-changelog', + 'prettier', + ]); + + if (codemod.hasTypeScript) { + packagesToInstall.delete('@babel/eslint-parser'); + packagesToInstall.add('@tsconfig/esm'); + packagesToInstall.add('@tsconfig/node16'); + packagesToInstall.add('@tsconfig/strictest'); + packagesToInstall.add('@types/node'); + packagesToInstall.add('@types/yargs'); + packagesToInstall.add('@typescript-eslint/eslint-plugin'); + packagesToInstall.add('@typescript-eslint/parser'); + packagesToInstall.add('eslint-import-resolver-typescript'); + packagesToInstall.add('eslint-plugin-typescript-sort-keys'); + packagesToInstall.add('typescript'); + } + + Array.from(packagesToInstall).forEach((packageName) => { + const version = getVersion(packageName); + + devDependencies.set(packageName, version); + }); + + // Pin @sondr3/minitest to v0.1.1 (to support Node 16) + devDependencies.set('@sondr3/minitest', '0.1.1'); + + packageJson['devDependencies'] = convertToObject(devDependencies); +} + +export function updatePackageJson(options: Options): void { + const { codemod, projectRoot } = options; + + const packageJson = readPackageJson({ + projectRoot: join(projectRoot, codemod.name), + }); + + updateDependencies(packageJson, options); + updateDevDependencies(packageJson, options); + + const destination = join(projectRoot, codemod.name, 'package.json'); + const file = JSON.stringify(packageJson, null, 2) + '\n'; + + writeFileSync(destination, file, 'utf8'); +} diff --git a/packages/cli/src/types/index.ts b/packages/cli/src/types/index.ts new file mode 100644 index 00000000..0ff90d89 --- /dev/null +++ b/packages/cli/src/types/index.ts @@ -0,0 +1,24 @@ +type Addon = + | 'ast-javascript' + | 'ast-template' + | 'blueprints' + | 'ember-cli-string' + | 'json'; + +type CodemodOptions = { + addons: Set; + hasTypeScript: boolean; + name: string; + projectRoot: string; +}; + +type Options = { + codemod: { + addons: Set; + hasTypeScript: boolean; + name: string; + }; + projectRoot: string; +}; + +export type { CodemodOptions, Options }; diff --git a/packages/cli/src/utils/blueprints.ts b/packages/cli/src/utils/blueprints.ts new file mode 100644 index 00000000..4b5711a7 --- /dev/null +++ b/packages/cli/src/utils/blueprints.ts @@ -0,0 +1,2 @@ +export * from './blueprints/blueprints-root.js'; +export * from './blueprints/get-version.js'; diff --git a/packages/cli/src/utils/blueprints/blueprints-root.ts b/packages/cli/src/utils/blueprints/blueprints-root.ts new file mode 100644 index 00000000..237d2fb9 --- /dev/null +++ b/packages/cli/src/utils/blueprints/blueprints-root.ts @@ -0,0 +1,7 @@ +import { join } from 'node:path'; + +import { getFilePath } from '@codemod-utils/blueprints'; + +const fileURL = import.meta.url; + +export const blueprintsRoot = join(getFilePath(fileURL), '../../blueprints'); diff --git a/packages/cli/src/utils/blueprints/get-version.ts b/packages/cli/src/utils/blueprints/get-version.ts new file mode 100644 index 00000000..4814a3a2 --- /dev/null +++ b/packages/cli/src/utils/blueprints/get-version.ts @@ -0,0 +1,41 @@ +import { decideVersion } from '@codemod-utils/blueprints'; + +const latestVersions = new Map([ + ['@babel/core', '7.22.8'], + ['@babel/eslint-parser', '7.22.7'], + ['@codemod-utils/ast-javascript', '0.3.0'], + ['@codemod-utils/ast-template', '0.3.0'], + ['@codemod-utils/blueprints', '0.2.1'], + ['@codemod-utils/ember-cli-string', '0.1.0'], + ['@codemod-utils/files', '0.5.1'], + ['@codemod-utils/json', '0.3.2'], + ['@codemod-utils/tests', '0.2.4'], + ['@sondr3/minitest', '0.1.1'], + ['@tsconfig/esm', '1.0.4'], + ['@tsconfig/node16', '16.1.0'], + ['@tsconfig/strictest', '2.0.1'], + ['@types/node', '16.11.7'], + ['@types/yargs', '17.0.24'], + ['@typescript-eslint/eslint-plugin', '5.61.0'], + ['@typescript-eslint/parser', '5.61.0'], + ['concurrently', '8.2.0'], + ['eslint', '8.44.0'], + ['eslint-config-prettier', '8.8.0'], + ['eslint-import-resolver-typescript', '3.5.5'], + ['eslint-plugin-import', '2.27.5'], + ['eslint-plugin-n', '16.0.1'], + ['eslint-plugin-prettier', '4.2.1'], + ['eslint-plugin-simple-import-sort', '10.0.0'], + ['eslint-plugin-typescript-sort-keys', '2.3.0'], + ['lerna-changelog', '2.2.0'], + ['prettier', '2.8.8'], + ['typescript', '5.1.6'], + ['yargs', '17.7.2'], +]); + +export function getVersion(packageName: string): string { + return decideVersion(packageName, { + dependencies: new Map(), + latestVersions, + }); +} diff --git a/packages/cli/tests/fixtures/javascript-with-addons/index.js b/packages/cli/tests/fixtures/javascript-with-addons/index.js new file mode 100644 index 00000000..a2e20e05 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/index.js @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('javascript-with-addons/input'); +const outputProject = convertFixtureToJson('javascript-with-addons/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/input/.gitkeep b/packages/cli/tests/fixtures/javascript-with-addons/input/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/.gitkeep b/packages/cli/tests/fixtures/javascript-with-addons/output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.eslintignore b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.eslintignore new file mode 100644 index 00000000..771057c8 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.eslintignore @@ -0,0 +1,13 @@ +# compiled output +/dist/ +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +!.* +.*/ +/src/blueprints/ +/tests/fixtures/ diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.eslintrc.cjs b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.eslintrc.cjs new file mode 100644 index 00000000..fd7b3a94 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.eslintrc.cjs @@ -0,0 +1,41 @@ +'use strict'; + +module.exports = { + root: true, + parser: '@babel/eslint-parser', + parserOptions: { + ecmaVersion: 'latest', + requireConfigFile: false, + sourceType: 'module', + }, + plugins: ['simple-import-sort'], + extends: [ + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:n/recommended', + 'plugin:prettier/recommended', + ], + rules: { + curly: 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', + }, + overrides: [ + // JavaScript files + { + files: ['**/*.js'], + rules: { + 'import/no-duplicates': 'error', + }, + }, + // Node files + { + files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'], + env: { + browser: false, + node: true, + }, + extends: ['plugin:n/recommended'], + }, + ], +}; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md new file mode 100644 index 00000000..e3ec7c1d --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md @@ -0,0 +1,27 @@ +--- +name: Ask for better documentation +about: Ask for better documentation +title: '' +labels: 'enhance: documentation' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve documentation. + +Here, documentation can mean a few different things, including README, code comments, and tests. Anything that will help everyone understand how to use `ember-codemod-args-to-signature`! + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md new file mode 100644 index 00000000..b561c5fd --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md @@ -0,0 +1,27 @@ +--- +name: Ask for new feature or refactor +about: Ask for new feature or refactor +title: '' +labels: 'enhance: code' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve `ember-codemod-args-to-signature`. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request already. + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-bug.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-bug.md new file mode 100644 index 00000000..140b92c9 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-bug.md @@ -0,0 +1,38 @@ +--- +name: Report bug +about: Report bug +title: '' +labels: bug +assignees: '' + +--- + +Hello! Thanks for taking time to make a bug report. + +Before you make a new issue, please search for similar issues. It's possible that someone has reported this bug already. + + +## Describe the bug 🐞 + +A clear and concise description of the bug. + + +## Expected behavior 🤔 + +A clear and concise description of what you expected to see. + + +## Minimal reproduction 🔬 + +Describe steps to reproduce the issue. + +1. ... +1. ... +1. ... + +If possible, please share a repo with the minimum files to reproduce the issue. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-outdated-dependency.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-outdated-dependency.md new file mode 100644 index 00000000..3fb22da0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-outdated-dependency.md @@ -0,0 +1,35 @@ +--- +name: Report outdated dependency +about: Report outdated dependency +title: '' +labels: 'enhance: dependency' +assignees: '' + +--- + +Hello! Thanks for taking time to make an outdated dependency report. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request for update already. + + +## List outdated dependencies 🔗 + +When you ran `pnpm outdated`, what did you see? + +```sh +┌────────────────────────┬─────────┬────────┐ +│ Package │ Current │ Latest │ +├────────────────────────┼─────────┼────────┤ +│ @sondr3/minitest (dev) │ 0.1.1 │ 0.1.2 │ +└────────────────────────┴─────────┴────────┘ +``` + + +## Risk analysis ⚠️ + +Are there breaking changes that we should be aware of? Please add links to the `CHANGELOG`s, if they are available. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/workflows/ci.yml b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/workflows/ci.yml new file mode 100644 index 00000000..5a6e74c7 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +env: + NODE_VERSION: 16 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm lint + + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.gitignore b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.gitignore new file mode 100644 index 00000000..cc33aa0e --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.gitignore @@ -0,0 +1,12 @@ +# compiled output +dist/ +dist-for-testing/ +tmp/ + +# dependencies +node_modules/ + +# misc +.DS_Store +.env* +.eslintcache diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.npmignore b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.npmignore new file mode 100644 index 00000000..fc33b3b8 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.npmignore @@ -0,0 +1,25 @@ +# compiled output +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +/.DS_Store +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.cjs +/.git/ +/.github/ +/.gitignore +/.pnpm-debug.log +/.prettierignore +/.prettierrc.cjs +/build.sh +/codemod-test-fixture.sh +/codemod-test-fixtures.sh +/CONTRIBUTING.md +/create-test-fixture.sh +/tests/ diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.prettierrc.cjs b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.prettierrc.cjs new file mode 100644 index 00000000..cc9c6600 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/.prettierrc.cjs @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + overrides: [ + { + files: '*.{cjs,js,mjs}', + options: { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + }, + }, + ], +}; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/CHANGELOG.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/CHANGELOG.md new file mode 100644 index 00000000..825c32f0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/CONTRIBUTING.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/CONTRIBUTING.md new file mode 100644 index 00000000..8781a164 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/CONTRIBUTING.md @@ -0,0 +1,86 @@ +# Contributing to ember-codemod-args-to-signature + +Open source projects like `ember-codemod-args-to-signature` live on your words of encouragement and contribution. Please give feedback, report issues, or submit pull requests! + +Here are some guidelines to help you and everyone else. + + +## Local development + +
+Install dependencies + +1. Fork and clone this repo. + + ```sh + git clone git@github.com:/ember-codemod-args-to-signature.git + ``` + +1. Change directory. + + ```sh + cd ember-codemod-args-to-signature + ``` + +1. Use [`pnpm`](https://pnpm.io/installation) to install dependencies. + + ```sh + pnpm install + ``` + +
+ + +
+Lint files + +1. When you write code, please check that it meets the linting rules. + + ```sh + pnpm lint + ``` + +1. You can run `lint:fix` to automatically fix linting errors. + + ```sh + pnpm lint:fix + ``` + +
+ + +
+Run tests + +1. When you write code, please check that all tests continue to pass. + + ```sh + pnpm test + ``` + +
+ + +
+ +Publish packages (for admins) + +1. Generate a [personal access token](https://github.com/settings/tokens/) in GitHub, with default values for scopes (none selected). + +1. Run the `changelog` script. This generates a text that you can add to `CHANGELOG.md`. + + ```sh + GITHUB_AUTH= pnpm changelog + ``` + +1. The package follows [semantic versioning](https://semver.org/). Update the version in `package.json` accordingly. + +1. Create a tag and provide release notes. The tag name should match the package version. + +1. Publish the package. + + ```sh + pnpm publish + ``` + +
diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/LICENSE.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/LICENSE.md new file mode 100644 index 00000000..94385605 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2023 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/README.md b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/README.md new file mode 100644 index 00000000..f72b1d44 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/README.md @@ -0,0 +1,50 @@ +# ember-codemod-args-to-signature + +_Codemod to [PROVIDE A SHORT DESCRIPTION.]_ + + +## Usage + +### Arguments + +[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.] + +
+Optional: Specify the project root + +Pass `--root` to run the codemod somewhere else (i.e. not in the current directory). + +```sh +npx ember-codemod-args-to-signature --root= +``` + +
+ + +### Limitations + +The codemod is designed to cover typical cases. It is not designed to cover one-off cases. + +To better meet your needs, consider cloning the repo and running the codemod locally. + +```sh +cd + +# Run codemod +./bin/ember-codemod-args-to-signature.js --root= +``` + + +## Compatibility + +- Node.js v16 or above + + +## Contributing + +See the [Contributing](CONTRIBUTING.md) guide for details. + + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/bin/ember-codemod-args-to-signature.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/bin/ember-codemod-args-to-signature.js new file mode 100755 index 00000000..952236cc --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/bin/ember-codemod-args-to-signature.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'use strict'; + +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +import { runCodemod } from '../src/index.js'; + +// Provide a title to the process in `ps` +process.title = 'ember-codemod-args-to-signature'; + +// Set codemod options +const argv = yargs(hideBin(process.argv)) + .option('root', { + describe: 'Where to run the codemod', + type: 'string', + }) + .parseSync(); + +const codemodOptions = { + projectRoot: argv['root'] ?? process.cwd(), +}; + +runCodemod(codemodOptions); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixture.sh b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixture.sh new file mode 100755 index 00000000..a78a4ae9 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixture.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix the expected output of a test fixture after updating the source code. +# +# B. Usage +# +# For named arguments, do not include `=` between the flag and the value. +# Positional arguments are to appear at the end. +# +# ./codemod-test-fixture.sh [OPTIONAL-FLAGS] +# +#--------- + +# Get named arguments for the binary +while getopts ":N:" flag +do + case $flag in + N) NAMED_ARGUMENTS=$OPTARG;; + esac +done + +# Get fixture name +FIXTURE=${@:$OPTIND:1} + +if [ ! $FIXTURE ] +then + echo "ERROR: Please specify the fixture name.\n" + exit 1 +elif [ ! -d "tests/fixtures/$FIXTURE/input" ] +then + echo "ERROR: Input folder \`tests/fixtures/$FIXTURE/input\` does not exist.\n" + exit 1 +fi + +rm -r "tests/fixtures/$FIXTURE/output" +cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output" + +./dist/bin/ember-codemod-args-to-signature.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output" + +echo "SUCCESS: Updated the output of $FIXTURE.\n" diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixtures.sh b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixtures.sh new file mode 100755 index 00000000..6b06b5f0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixtures.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix all test fixtures after updating the source code. +# +# B. Usage +# +# ./codemod-test-fixtures.sh +# +#--------- + +# Compile TypeScript +# pnpm build + +./codemod-test-fixture.sh \ + -N "" \ + sample-project diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/package.json b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/package.json new file mode 100644 index 00000000..413ca5cf --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/package.json @@ -0,0 +1,68 @@ +{ + "name": "ember-codemod-args-to-signature", + "version": "0.0.0", + "private": true, + "description": "Small description for ember-codemod-args-to-signature goes here", + "keywords": [ + "codemod", + "ember-codemod", + "emberjs" + ], + "repository": "", + "license": "MIT", + "author": "", + "type": "module", + "main": "src/index.js", + "bin": "bin/ember-codemod-args-to-signature.js", + "directories": { + "test": "tests" + }, + "files": [ + "bin", + "src" + ], + "scripts": { + "changelog": "lerna-changelog", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "test": "mt --quiet" + }, + "dependencies": { + "@codemod-utils/ast-javascript": "^0.3.0", + "@codemod-utils/ast-template": "^0.3.0", + "@codemod-utils/blueprints": "^0.2.1", + "@codemod-utils/ember-cli-string": "^0.1.0", + "@codemod-utils/files": "^0.5.1", + "@codemod-utils/json": "^0.3.2", + "yargs": "^17.7.2" + }, + "devDependencies": { + "@babel/core": "^7.22.8", + "@babel/eslint-parser": "^7.22.7", + "@codemod-utils/tests": "^0.2.4", + "@sondr3/minitest": "0.1.1", + "concurrently": "^8.2.0", + "eslint": "^8.44.0", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-n": "^16.0.1", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-simple-import-sort": "^10.0.0", + "lerna-changelog": "^2.2.0", + "prettier": "^2.8.8" + }, + "engines": { + "node": "16.* || >= 18" + }, + "changelog": { + "labels": { + "breaking": "Breaking Change", + "bug": "Bug Fix", + "enhance: code": "Enhancement", + "enhance: dependency": "Internal", + "enhance: documentation": "Documentation" + } + } +} diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/blueprints/.gitkeep b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/blueprints/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/index.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/index.js new file mode 100644 index 00000000..86600b69 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/index.js @@ -0,0 +1,8 @@ +import { addEndOfLine, createOptions } from './steps/index.js'; + +export function runCodemod(codemodOptions) { + const options = createOptions(codemodOptions); + + // TODO: Replace with actual steps + addEndOfLine(options); +} diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/add-end-of-line.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/add-end-of-line.js new file mode 100644 index 00000000..c7e4f10e --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/add-end-of-line.js @@ -0,0 +1,24 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { createFiles, findFiles } from '@codemod-utils/files'; + +export function addEndOfLine(options) { + const { projectRoot } = options; + + const filePaths = findFiles('**/*.txt', { + projectRoot, + }); + + const fileMap = new Map( + filePaths.map((filePath) => { + const file = readFileSync(join(projectRoot, filePath), 'utf8'); + + const newFile = file.endsWith('\n') ? file : `${file}\n`; + + return [filePath, newFile]; + }), + ); + + createFiles(fileMap, options); +} diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/create-options.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/create-options.js new file mode 100644 index 00000000..ef6336db --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/create-options.js @@ -0,0 +1,7 @@ +export function createOptions(codemodOptions) { + const { projectRoot } = codemodOptions; + + return { + projectRoot, + }; +} diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/index.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/index.js new file mode 100644 index 00000000..5435fe02 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/steps/index.js @@ -0,0 +1,2 @@ +export * from './add-end-of-line.js'; +export * from './create-options.js'; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints.js new file mode 100644 index 00000000..1e540879 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints.js @@ -0,0 +1 @@ +export * from './blueprints/blueprints-root.js'; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints/blueprints-root.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints/blueprints-root.js new file mode 100644 index 00000000..237d2fb9 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints/blueprints-root.js @@ -0,0 +1,7 @@ +import { join } from 'node:path'; + +import { getFilePath } from '@codemod-utils/blueprints'; + +const fileURL = import.meta.url; + +export const blueprintsRoot = join(getFilePath(fileURL), '../../blueprints'); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/index.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/index.js new file mode 100644 index 00000000..a8a96766 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/index.js @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('sample-project/input'); +const outputProject = convertFixtureToJson('sample-project/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/input/file.txt b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/input/file.txt new file mode 100644 index 00000000..6769dd60 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/input/file.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/output/file.txt b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/output/file.txt new file mode 100644 index 00000000..cd087558 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/output/file.txt @@ -0,0 +1 @@ +Hello world! diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/helpers/shared-test-setups/sample-project.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/helpers/shared-test-setups/sample-project.js new file mode 100644 index 00000000..8b286802 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/helpers/shared-test-setups/sample-project.js @@ -0,0 +1,9 @@ +const codemodOptions = { + projectRoot: 'tmp/sample-project', +}; + +const options = { + projectRoot: 'tmp/sample-project', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/index/sample-project.test.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/index/sample-project.test.js new file mode 100644 index 00000000..7a97215f --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/index/sample-project.test.js @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { runCodemod } from '../../src/index.js'; +import { + inputProject, + outputProject, +} from '../fixtures/sample-project/index.js'; +import { codemodOptions } from '../helpers/shared-test-setups/sample-project.js'; + +test('index > sample-project', function () { + loadFixture(inputProject, codemodOptions); + + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/base-case.test.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/base-case.test.js new file mode 100644 index 00000000..cf5dfe06 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/base-case.test.js @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > base case', function () { + const inputProject = { + 'file.txt': 'Hello world!', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.js new file mode 100644 index 00000000..2340e587 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.js @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file ends with newline)', function () { + const inputProject = { + 'file.txt': 'Hello world!\n', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-is-empty.test.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-is-empty.test.js new file mode 100644 index 00000000..218b3c4e --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-is-empty.test.js @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file is empty)', function () { + const inputProject = { + 'file.txt': '', + }; + + const outputProject = { + 'file.txt': '\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/create-options/sample-project.test.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/create-options/sample-project.test.js new file mode 100644 index 00000000..fbfe0291 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/steps/create-options/sample-project.test.js @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | create-options > sample-project', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/utils/blueprints/blueprints-root.test.js b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/utils/blueprints/blueprints-root.test.js new file mode 100644 index 00000000..df5ed4f0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript-with-addons/output/ember-codemod-args-to-signature/tests/utils/blueprints/blueprints-root.test.js @@ -0,0 +1,7 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { blueprintsRoot } from '../../../src/utils/blueprints.js'; + +test('utils | blueprints | blueprints-root', function () { + assert.strictEqual(blueprintsRoot.endsWith('src/blueprints'), true); +}); diff --git a/packages/cli/tests/fixtures/javascript/index.js b/packages/cli/tests/fixtures/javascript/index.js new file mode 100644 index 00000000..2ab40e51 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/index.js @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('javascript/input'); +const outputProject = convertFixtureToJson('javascript/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/javascript/input/.gitkeep b/packages/cli/tests/fixtures/javascript/input/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/javascript/output/.gitkeep b/packages/cli/tests/fixtures/javascript/output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.eslintignore b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.eslintignore new file mode 100644 index 00000000..771057c8 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.eslintignore @@ -0,0 +1,13 @@ +# compiled output +/dist/ +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +!.* +.*/ +/src/blueprints/ +/tests/fixtures/ diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.eslintrc.cjs b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.eslintrc.cjs new file mode 100644 index 00000000..fd7b3a94 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.eslintrc.cjs @@ -0,0 +1,41 @@ +'use strict'; + +module.exports = { + root: true, + parser: '@babel/eslint-parser', + parserOptions: { + ecmaVersion: 'latest', + requireConfigFile: false, + sourceType: 'module', + }, + plugins: ['simple-import-sort'], + extends: [ + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:n/recommended', + 'plugin:prettier/recommended', + ], + rules: { + curly: 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', + }, + overrides: [ + // JavaScript files + { + files: ['**/*.js'], + rules: { + 'import/no-duplicates': 'error', + }, + }, + // Node files + { + files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'], + env: { + browser: false, + node: true, + }, + extends: ['plugin:n/recommended'], + }, + ], +}; diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md new file mode 100644 index 00000000..4296e54f --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md @@ -0,0 +1,27 @@ +--- +name: Ask for better documentation +about: Ask for better documentation +title: '' +labels: 'enhance: documentation' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve documentation. + +Here, documentation can mean a few different things, including README, code comments, and tests. Anything that will help everyone understand how to use `ember-codemod-pod-to-octane`! + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md new file mode 100644 index 00000000..d4d18a4a --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md @@ -0,0 +1,27 @@ +--- +name: Ask for new feature or refactor +about: Ask for new feature or refactor +title: '' +labels: 'enhance: code' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve `ember-codemod-pod-to-octane`. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request already. + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-bug.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-bug.md new file mode 100644 index 00000000..140b92c9 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-bug.md @@ -0,0 +1,38 @@ +--- +name: Report bug +about: Report bug +title: '' +labels: bug +assignees: '' + +--- + +Hello! Thanks for taking time to make a bug report. + +Before you make a new issue, please search for similar issues. It's possible that someone has reported this bug already. + + +## Describe the bug 🐞 + +A clear and concise description of the bug. + + +## Expected behavior 🤔 + +A clear and concise description of what you expected to see. + + +## Minimal reproduction 🔬 + +Describe steps to reproduce the issue. + +1. ... +1. ... +1. ... + +If possible, please share a repo with the minimum files to reproduce the issue. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-outdated-dependency.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-outdated-dependency.md new file mode 100644 index 00000000..3fb22da0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-outdated-dependency.md @@ -0,0 +1,35 @@ +--- +name: Report outdated dependency +about: Report outdated dependency +title: '' +labels: 'enhance: dependency' +assignees: '' + +--- + +Hello! Thanks for taking time to make an outdated dependency report. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request for update already. + + +## List outdated dependencies 🔗 + +When you ran `pnpm outdated`, what did you see? + +```sh +┌────────────────────────┬─────────┬────────┐ +│ Package │ Current │ Latest │ +├────────────────────────┼─────────┼────────┤ +│ @sondr3/minitest (dev) │ 0.1.1 │ 0.1.2 │ +└────────────────────────┴─────────┴────────┘ +``` + + +## Risk analysis ⚠️ + +Are there breaking changes that we should be aware of? Please add links to the `CHANGELOG`s, if they are available. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/workflows/ci.yml b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/workflows/ci.yml new file mode 100644 index 00000000..5a6e74c7 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +env: + NODE_VERSION: 16 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm lint + + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.gitignore b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.gitignore new file mode 100644 index 00000000..cc33aa0e --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.gitignore @@ -0,0 +1,12 @@ +# compiled output +dist/ +dist-for-testing/ +tmp/ + +# dependencies +node_modules/ + +# misc +.DS_Store +.env* +.eslintcache diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.npmignore b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.npmignore new file mode 100644 index 00000000..fc33b3b8 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.npmignore @@ -0,0 +1,25 @@ +# compiled output +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +/.DS_Store +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.cjs +/.git/ +/.github/ +/.gitignore +/.pnpm-debug.log +/.prettierignore +/.prettierrc.cjs +/build.sh +/codemod-test-fixture.sh +/codemod-test-fixtures.sh +/CONTRIBUTING.md +/create-test-fixture.sh +/tests/ diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.prettierrc.cjs b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.prettierrc.cjs new file mode 100644 index 00000000..cc9c6600 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/.prettierrc.cjs @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + overrides: [ + { + files: '*.{cjs,js,mjs}', + options: { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + }, + }, + ], +}; diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/CHANGELOG.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/CHANGELOG.md new file mode 100644 index 00000000..825c32f0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/CONTRIBUTING.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/CONTRIBUTING.md new file mode 100644 index 00000000..4129fd42 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/CONTRIBUTING.md @@ -0,0 +1,86 @@ +# Contributing to ember-codemod-pod-to-octane + +Open source projects like `ember-codemod-pod-to-octane` live on your words of encouragement and contribution. Please give feedback, report issues, or submit pull requests! + +Here are some guidelines to help you and everyone else. + + +## Local development + +
+Install dependencies + +1. Fork and clone this repo. + + ```sh + git clone git@github.com:/ember-codemod-pod-to-octane.git + ``` + +1. Change directory. + + ```sh + cd ember-codemod-pod-to-octane + ``` + +1. Use [`pnpm`](https://pnpm.io/installation) to install dependencies. + + ```sh + pnpm install + ``` + +
+ + +
+Lint files + +1. When you write code, please check that it meets the linting rules. + + ```sh + pnpm lint + ``` + +1. You can run `lint:fix` to automatically fix linting errors. + + ```sh + pnpm lint:fix + ``` + +
+ + +
+Run tests + +1. When you write code, please check that all tests continue to pass. + + ```sh + pnpm test + ``` + +
+ + +
+ +Publish packages (for admins) + +1. Generate a [personal access token](https://github.com/settings/tokens/) in GitHub, with default values for scopes (none selected). + +1. Run the `changelog` script. This generates a text that you can add to `CHANGELOG.md`. + + ```sh + GITHUB_AUTH= pnpm changelog + ``` + +1. The package follows [semantic versioning](https://semver.org/). Update the version in `package.json` accordingly. + +1. Create a tag and provide release notes. The tag name should match the package version. + +1. Publish the package. + + ```sh + pnpm publish + ``` + +
diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/LICENSE.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/LICENSE.md new file mode 100644 index 00000000..94385605 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2023 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/README.md b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/README.md new file mode 100644 index 00000000..0ca059d7 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/README.md @@ -0,0 +1,50 @@ +# ember-codemod-pod-to-octane + +_Codemod to [PROVIDE A SHORT DESCRIPTION.]_ + + +## Usage + +### Arguments + +[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.] + +
+Optional: Specify the project root + +Pass `--root` to run the codemod somewhere else (i.e. not in the current directory). + +```sh +npx ember-codemod-pod-to-octane --root= +``` + +
+ + +### Limitations + +The codemod is designed to cover typical cases. It is not designed to cover one-off cases. + +To better meet your needs, consider cloning the repo and running the codemod locally. + +```sh +cd + +# Run codemod +./bin/ember-codemod-pod-to-octane.js --root= +``` + + +## Compatibility + +- Node.js v16 or above + + +## Contributing + +See the [Contributing](CONTRIBUTING.md) guide for details. + + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/bin/ember-codemod-pod-to-octane.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/bin/ember-codemod-pod-to-octane.js new file mode 100755 index 00000000..bec5f43b --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/bin/ember-codemod-pod-to-octane.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'use strict'; + +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +import { runCodemod } from '../src/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)) + .option('root', { + describe: 'Where to run the codemod', + type: 'string', + }) + .parseSync(); + +const codemodOptions = { + projectRoot: argv['root'] ?? process.cwd(), +}; + +runCodemod(codemodOptions); diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/codemod-test-fixture.sh b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/codemod-test-fixture.sh new file mode 100755 index 00000000..57ceb336 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/codemod-test-fixture.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix the expected output of a test fixture after updating the source code. +# +# B. Usage +# +# For named arguments, do not include `=` between the flag and the value. +# Positional arguments are to appear at the end. +# +# ./codemod-test-fixture.sh [OPTIONAL-FLAGS] +# +#--------- + +# Get named arguments for the binary +while getopts ":N:" flag +do + case $flag in + N) NAMED_ARGUMENTS=$OPTARG;; + esac +done + +# Get fixture name +FIXTURE=${@:$OPTIND:1} + +if [ ! $FIXTURE ] +then + echo "ERROR: Please specify the fixture name.\n" + exit 1 +elif [ ! -d "tests/fixtures/$FIXTURE/input" ] +then + echo "ERROR: Input folder \`tests/fixtures/$FIXTURE/input\` does not exist.\n" + exit 1 +fi + +rm -r "tests/fixtures/$FIXTURE/output" +cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output" + +./dist/bin/ember-codemod-pod-to-octane.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output" + +echo "SUCCESS: Updated the output of $FIXTURE.\n" diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/codemod-test-fixtures.sh b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/codemod-test-fixtures.sh new file mode 100755 index 00000000..6b06b5f0 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/codemod-test-fixtures.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix all test fixtures after updating the source code. +# +# B. Usage +# +# ./codemod-test-fixtures.sh +# +#--------- + +# Compile TypeScript +# pnpm build + +./codemod-test-fixture.sh \ + -N "" \ + sample-project diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/package.json b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/package.json new file mode 100644 index 00000000..f95fc46a --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/package.json @@ -0,0 +1,63 @@ +{ + "name": "ember-codemod-pod-to-octane", + "version": "0.0.0", + "private": true, + "description": "Small description for ember-codemod-pod-to-octane goes here", + "keywords": [ + "codemod", + "ember-codemod", + "emberjs" + ], + "repository": "", + "license": "MIT", + "author": "", + "type": "module", + "main": "src/index.js", + "bin": "bin/ember-codemod-pod-to-octane.js", + "directories": { + "test": "tests" + }, + "files": [ + "bin", + "src" + ], + "scripts": { + "changelog": "lerna-changelog", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "test": "mt --quiet" + }, + "dependencies": { + "@codemod-utils/files": "^0.5.1", + "yargs": "^17.7.2" + }, + "devDependencies": { + "@babel/core": "^7.22.8", + "@babel/eslint-parser": "^7.22.7", + "@codemod-utils/tests": "^0.2.4", + "@sondr3/minitest": "0.1.1", + "concurrently": "^8.2.0", + "eslint": "^8.44.0", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-n": "^16.0.1", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-simple-import-sort": "^10.0.0", + "lerna-changelog": "^2.2.0", + "prettier": "^2.8.8" + }, + "engines": { + "node": "16.* || >= 18" + }, + "changelog": { + "labels": { + "breaking": "Breaking Change", + "bug": "Bug Fix", + "enhance: code": "Enhancement", + "enhance: dependency": "Internal", + "enhance: documentation": "Documentation" + } + } +} diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/index.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/index.js new file mode 100644 index 00000000..86600b69 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/index.js @@ -0,0 +1,8 @@ +import { addEndOfLine, createOptions } from './steps/index.js'; + +export function runCodemod(codemodOptions) { + const options = createOptions(codemodOptions); + + // TODO: Replace with actual steps + addEndOfLine(options); +} diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/add-end-of-line.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/add-end-of-line.js new file mode 100644 index 00000000..c7e4f10e --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/add-end-of-line.js @@ -0,0 +1,24 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { createFiles, findFiles } from '@codemod-utils/files'; + +export function addEndOfLine(options) { + const { projectRoot } = options; + + const filePaths = findFiles('**/*.txt', { + projectRoot, + }); + + const fileMap = new Map( + filePaths.map((filePath) => { + const file = readFileSync(join(projectRoot, filePath), 'utf8'); + + const newFile = file.endsWith('\n') ? file : `${file}\n`; + + return [filePath, newFile]; + }), + ); + + createFiles(fileMap, options); +} diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/create-options.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/create-options.js new file mode 100644 index 00000000..ef6336db --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/create-options.js @@ -0,0 +1,7 @@ +export function createOptions(codemodOptions) { + const { projectRoot } = codemodOptions; + + return { + projectRoot, + }; +} diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/index.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/index.js new file mode 100644 index 00000000..5435fe02 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/src/steps/index.js @@ -0,0 +1,2 @@ +export * from './add-end-of-line.js'; +export * from './create-options.js'; diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/index.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/index.js new file mode 100644 index 00000000..a8a96766 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/index.js @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('sample-project/input'); +const outputProject = convertFixtureToJson('sample-project/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/input/file.txt b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/input/file.txt new file mode 100644 index 00000000..6769dd60 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/input/file.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/output/file.txt b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/output/file.txt new file mode 100644 index 00000000..cd087558 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/output/file.txt @@ -0,0 +1 @@ +Hello world! diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/helpers/shared-test-setups/sample-project.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/helpers/shared-test-setups/sample-project.js new file mode 100644 index 00000000..8b286802 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/helpers/shared-test-setups/sample-project.js @@ -0,0 +1,9 @@ +const codemodOptions = { + projectRoot: 'tmp/sample-project', +}; + +const options = { + projectRoot: 'tmp/sample-project', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/index/sample-project.test.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/index/sample-project.test.js new file mode 100644 index 00000000..7a97215f --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/index/sample-project.test.js @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { runCodemod } from '../../src/index.js'; +import { + inputProject, + outputProject, +} from '../fixtures/sample-project/index.js'; +import { codemodOptions } from '../helpers/shared-test-setups/sample-project.js'; + +test('index > sample-project', function () { + loadFixture(inputProject, codemodOptions); + + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/base-case.test.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/base-case.test.js new file mode 100644 index 00000000..cf5dfe06 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/base-case.test.js @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > base case', function () { + const inputProject = { + 'file.txt': 'Hello world!', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.js new file mode 100644 index 00000000..2340e587 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.js @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file ends with newline)', function () { + const inputProject = { + 'file.txt': 'Hello world!\n', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-is-empty.test.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-is-empty.test.js new file mode 100644 index 00000000..218b3c4e --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-is-empty.test.js @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file is empty)', function () { + const inputProject = { + 'file.txt': '', + }; + + const outputProject = { + 'file.txt': '\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/create-options/sample-project.test.js b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/create-options/sample-project.test.js new file mode 100644 index 00000000..fbfe0291 --- /dev/null +++ b/packages/cli/tests/fixtures/javascript/output/ember-codemod-pod-to-octane/tests/steps/create-options/sample-project.test.js @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | create-options > sample-project', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/index.js b/packages/cli/tests/fixtures/typescript-with-addons/index.js new file mode 100644 index 00000000..f457d8d7 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/index.js @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('typescript-with-addons/input'); +const outputProject = convertFixtureToJson('typescript-with-addons/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/input/.gitkeep b/packages/cli/tests/fixtures/typescript-with-addons/input/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/.gitkeep b/packages/cli/tests/fixtures/typescript-with-addons/output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.eslintignore b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.eslintignore new file mode 100644 index 00000000..771057c8 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.eslintignore @@ -0,0 +1,13 @@ +# compiled output +/dist/ +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +!.* +.*/ +/src/blueprints/ +/tests/fixtures/ diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.eslintrc.cjs b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.eslintrc.cjs new file mode 100644 index 00000000..ecb3f494 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.eslintrc.cjs @@ -0,0 +1,61 @@ +'use strict'; + +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + plugins: ['@typescript-eslint', 'simple-import-sort', 'typescript-sort-keys'], + extends: [ + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'plugin:n/recommended', + 'plugin:prettier/recommended', + 'plugin:typescript-sort-keys/recommended', + ], + rules: { + curly: 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', + }, + settings: { + 'import/resolver': { + node: true, + typescript: true, + }, + }, + overrides: [ + // TypeScript files + { + files: ['**/*.{cts,ts}'], + extends: [ + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + ], + rules: { + '@typescript-eslint/array-type': 'error', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + }, + }, + // TypeScript and JavaScript files + { + files: ['**/*.{cjs,cts,js,ts}'], + rules: { + 'import/no-duplicates': 'error', + }, + }, + // Node files + { + files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'], + env: { + browser: false, + node: true, + }, + extends: ['plugin:n/recommended'], + }, + ], +}; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md new file mode 100644 index 00000000..e3ec7c1d --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md @@ -0,0 +1,27 @@ +--- +name: Ask for better documentation +about: Ask for better documentation +title: '' +labels: 'enhance: documentation' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve documentation. + +Here, documentation can mean a few different things, including README, code comments, and tests. Anything that will help everyone understand how to use `ember-codemod-args-to-signature`! + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md new file mode 100644 index 00000000..b561c5fd --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md @@ -0,0 +1,27 @@ +--- +name: Ask for new feature or refactor +about: Ask for new feature or refactor +title: '' +labels: 'enhance: code' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve `ember-codemod-args-to-signature`. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request already. + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-bug.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-bug.md new file mode 100644 index 00000000..140b92c9 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-bug.md @@ -0,0 +1,38 @@ +--- +name: Report bug +about: Report bug +title: '' +labels: bug +assignees: '' + +--- + +Hello! Thanks for taking time to make a bug report. + +Before you make a new issue, please search for similar issues. It's possible that someone has reported this bug already. + + +## Describe the bug 🐞 + +A clear and concise description of the bug. + + +## Expected behavior 🤔 + +A clear and concise description of what you expected to see. + + +## Minimal reproduction 🔬 + +Describe steps to reproduce the issue. + +1. ... +1. ... +1. ... + +If possible, please share a repo with the minimum files to reproduce the issue. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-outdated-dependency.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-outdated-dependency.md new file mode 100644 index 00000000..3fb22da0 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/ISSUE_TEMPLATE/report-outdated-dependency.md @@ -0,0 +1,35 @@ +--- +name: Report outdated dependency +about: Report outdated dependency +title: '' +labels: 'enhance: dependency' +assignees: '' + +--- + +Hello! Thanks for taking time to make an outdated dependency report. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request for update already. + + +## List outdated dependencies 🔗 + +When you ran `pnpm outdated`, what did you see? + +```sh +┌────────────────────────┬─────────┬────────┐ +│ Package │ Current │ Latest │ +├────────────────────────┼─────────┼────────┤ +│ @sondr3/minitest (dev) │ 0.1.1 │ 0.1.2 │ +└────────────────────────┴─────────┴────────┘ +``` + + +## Risk analysis ⚠️ + +Are there breaking changes that we should be aware of? Please add links to the `CHANGELOG`s, if they are available. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/workflows/ci.yml b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/workflows/ci.yml new file mode 100644 index 00000000..5a6e74c7 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +env: + NODE_VERSION: 16 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm lint + + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.gitignore b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.gitignore new file mode 100644 index 00000000..cc33aa0e --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.gitignore @@ -0,0 +1,12 @@ +# compiled output +dist/ +dist-for-testing/ +tmp/ + +# dependencies +node_modules/ + +# misc +.DS_Store +.env* +.eslintcache diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.npmignore b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.npmignore new file mode 100644 index 00000000..fc33b3b8 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.npmignore @@ -0,0 +1,25 @@ +# compiled output +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +/.DS_Store +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.cjs +/.git/ +/.github/ +/.gitignore +/.pnpm-debug.log +/.prettierignore +/.prettierrc.cjs +/build.sh +/codemod-test-fixture.sh +/codemod-test-fixtures.sh +/CONTRIBUTING.md +/create-test-fixture.sh +/tests/ diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.prettierrc.cjs b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.prettierrc.cjs new file mode 100644 index 00000000..004c04d2 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/.prettierrc.cjs @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + overrides: [ + { + files: '*.{cjs,cts,js,mjs,mts,ts}', + options: { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + }, + }, + ], +}; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/CHANGELOG.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/CHANGELOG.md new file mode 100644 index 00000000..825c32f0 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/CONTRIBUTING.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/CONTRIBUTING.md new file mode 100644 index 00000000..8781a164 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/CONTRIBUTING.md @@ -0,0 +1,86 @@ +# Contributing to ember-codemod-args-to-signature + +Open source projects like `ember-codemod-args-to-signature` live on your words of encouragement and contribution. Please give feedback, report issues, or submit pull requests! + +Here are some guidelines to help you and everyone else. + + +## Local development + +
+Install dependencies + +1. Fork and clone this repo. + + ```sh + git clone git@github.com:/ember-codemod-args-to-signature.git + ``` + +1. Change directory. + + ```sh + cd ember-codemod-args-to-signature + ``` + +1. Use [`pnpm`](https://pnpm.io/installation) to install dependencies. + + ```sh + pnpm install + ``` + +
+ + +
+Lint files + +1. When you write code, please check that it meets the linting rules. + + ```sh + pnpm lint + ``` + +1. You can run `lint:fix` to automatically fix linting errors. + + ```sh + pnpm lint:fix + ``` + +
+ + +
+Run tests + +1. When you write code, please check that all tests continue to pass. + + ```sh + pnpm test + ``` + +
+ + +
+ +Publish packages (for admins) + +1. Generate a [personal access token](https://github.com/settings/tokens/) in GitHub, with default values for scopes (none selected). + +1. Run the `changelog` script. This generates a text that you can add to `CHANGELOG.md`. + + ```sh + GITHUB_AUTH= pnpm changelog + ``` + +1. The package follows [semantic versioning](https://semver.org/). Update the version in `package.json` accordingly. + +1. Create a tag and provide release notes. The tag name should match the package version. + +1. Publish the package. + + ```sh + pnpm publish + ``` + +
diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/LICENSE.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/LICENSE.md new file mode 100644 index 00000000..94385605 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2023 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/README.md b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/README.md new file mode 100644 index 00000000..805f82ed --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/README.md @@ -0,0 +1,53 @@ +# ember-codemod-args-to-signature + +_Codemod to [PROVIDE A SHORT DESCRIPTION.]_ + + +## Usage + +### Arguments + +[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.] + +
+Optional: Specify the project root + +Pass `--root` to run the codemod somewhere else (i.e. not in the current directory). + +```sh +npx ember-codemod-args-to-signature --root= +``` + +
+ + +### Limitations + +The codemod is designed to cover typical cases. It is not designed to cover one-off cases. + +To better meet your needs, consider cloning the repo and running the codemod locally. + +```sh +cd + +# Compile TypeScript +pnpm build + +# Run codemod +./dist/bin/ember-codemod-args-to-signature.js --root= +``` + + +## Compatibility + +- Node.js v16 or above + + +## Contributing + +See the [Contributing](CONTRIBUTING.md) guide for details. + + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/bin/ember-codemod-args-to-signature.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/bin/ember-codemod-args-to-signature.ts new file mode 100755 index 00000000..ccbafe3e --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/bin/ember-codemod-args-to-signature.ts @@ -0,0 +1,26 @@ +#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'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-args-to-signature'; + +// Set codemod options +const argv = yargs(hideBin(process.argv)) + .option('root', { + describe: 'Where to run the codemod', + type: 'string', + }) + .parseSync(); + +const codemodOptions: CodemodOptions = { + projectRoot: argv['root'] ?? process.cwd(), +}; + +runCodemod(codemodOptions); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/build.sh b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/build.sh new file mode 100755 index 00000000..1ad39b7a --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +COMMAND="ember-codemod-args-to-signature" +ENVIRONMENT=$1 + +if [ $ENVIRONMENT = "--production" ] +then + # Clean slate + rm -rf "dist" + + # Compile TypeScript + tsc --project "tsconfig.build.json" + + # Configure files + chmod +x "dist/bin/$COMMAND.js" + + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist/src/blueprints" + fi + + echo "SUCCESS: Built dist.\n" + +elif [ $ENVIRONMENT = "--test" ] +then + # Clean slate + rm -rf "dist-for-testing" + + # Compile TypeScript + tsc --project "tsconfig.json" + + # Configure files + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist-for-testing/src/blueprints" + fi + + echo "SUCCESS: Built dist-for-testing.\n" + +fi diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixture.sh b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixture.sh new file mode 100755 index 00000000..a78a4ae9 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixture.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix the expected output of a test fixture after updating the source code. +# +# B. Usage +# +# For named arguments, do not include `=` between the flag and the value. +# Positional arguments are to appear at the end. +# +# ./codemod-test-fixture.sh [OPTIONAL-FLAGS] +# +#--------- + +# Get named arguments for the binary +while getopts ":N:" flag +do + case $flag in + N) NAMED_ARGUMENTS=$OPTARG;; + esac +done + +# Get fixture name +FIXTURE=${@:$OPTIND:1} + +if [ ! $FIXTURE ] +then + echo "ERROR: Please specify the fixture name.\n" + exit 1 +elif [ ! -d "tests/fixtures/$FIXTURE/input" ] +then + echo "ERROR: Input folder \`tests/fixtures/$FIXTURE/input\` does not exist.\n" + exit 1 +fi + +rm -r "tests/fixtures/$FIXTURE/output" +cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output" + +./dist/bin/ember-codemod-args-to-signature.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output" + +echo "SUCCESS: Updated the output of $FIXTURE.\n" diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixtures.sh b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixtures.sh new file mode 100755 index 00000000..5caf3c3a --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/codemod-test-fixtures.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix all test fixtures after updating the source code. +# +# B. Usage +# +# ./codemod-test-fixtures.sh +# +#--------- + +# Compile TypeScript +pnpm build + +./codemod-test-fixture.sh \ + -N "" \ + sample-project diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/package.json b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/package.json new file mode 100644 index 00000000..bf71cd80 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/package.json @@ -0,0 +1,84 @@ +{ + "name": "ember-codemod-args-to-signature", + "version": "0.0.0", + "private": true, + "description": "Small description for ember-codemod-args-to-signature goes here", + "keywords": [ + "codemod", + "ember-codemod", + "emberjs" + ], + "repository": "", + "license": "MIT", + "author": "", + "type": "module", + "main": "dist/src/index.js", + "bin": "dist/bin/ember-codemod-args-to-signature.js", + "directories": { + "test": "tests" + }, + "files": [ + "dist" + ], + "scripts": { + "build": "./build.sh --production", + "changelog": "lerna-changelog", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "lint:types": "tsc --noEmit", + "prepare": "pnpm build", + "test": "./build.sh --test && mt dist-for-testing --quiet" + }, + "dependencies": { + "@codemod-utils/ast-javascript": "^0.3.0", + "@codemod-utils/ast-template": "^0.3.0", + "@codemod-utils/blueprints": "^0.2.1", + "@codemod-utils/ember-cli-string": "^0.1.0", + "@codemod-utils/files": "^0.5.1", + "@codemod-utils/json": "^0.3.2", + "yargs": "^17.7.2" + }, + "devDependencies": { + "@babel/core": "^7.22.8", + "@codemod-utils/tests": "^0.2.4", + "@sondr3/minitest": "0.1.1", + "@tsconfig/esm": "^1.0.4", + "@tsconfig/node16": "^16.1.0", + "@tsconfig/strictest": "^2.0.1", + "@types/node": "^16.11.7", + "@types/yargs": "^17.0.24", + "@typescript-eslint/eslint-plugin": "^5.61.0", + "@typescript-eslint/parser": "^5.61.0", + "concurrently": "^8.2.0", + "eslint": "^8.44.0", + "eslint-config-prettier": "^8.8.0", + "eslint-import-resolver-typescript": "^3.5.5", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-n": "^16.0.1", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-simple-import-sort": "^10.0.0", + "eslint-plugin-typescript-sort-keys": "^2.3.0", + "lerna-changelog": "^2.2.0", + "prettier": "^2.8.8", + "typescript": "^5.1.6" + }, + "engines": { + "node": "16.* || >= 18" + }, + "changelog": { + "labels": { + "breaking": "Breaking Change", + "bug": "Bug Fix", + "enhance: code": "Enhancement", + "enhance: dependency": "Internal", + "enhance: documentation": "Documentation" + } + }, + "pnpm": { + "overrides": { + "eslint-plugin-import@2.27.5>tsconfig-paths": "^4.2.0" + } + } +} diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/blueprints/.gitkeep b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/blueprints/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/index.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/index.ts new file mode 100644 index 00000000..b2f3be42 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/index.ts @@ -0,0 +1,9 @@ +import { addEndOfLine, createOptions } from './steps/index.js'; +import type { CodemodOptions } from './types/index.js'; + +export function runCodemod(codemodOptions: CodemodOptions): void { + const options = createOptions(codemodOptions); + + // TODO: Replace with actual steps + addEndOfLine(options); +} diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/add-end-of-line.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/add-end-of-line.ts new file mode 100644 index 00000000..de3ae4e1 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/add-end-of-line.ts @@ -0,0 +1,26 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { createFiles, findFiles } from '@codemod-utils/files'; + +import type { Options } from '../types/index.js'; + +export function addEndOfLine(options: Options): void { + const { projectRoot } = options; + + const filePaths = findFiles('**/*.txt', { + projectRoot, + }); + + const fileMap = new Map( + filePaths.map((filePath) => { + const file = readFileSync(join(projectRoot, filePath), 'utf8'); + + const newFile = file.endsWith('\n') ? file : `${file}\n`; + + return [filePath, newFile]; + }), + ); + + createFiles(fileMap, options); +} diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/create-options.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/create-options.ts new file mode 100644 index 00000000..8c156fb8 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/create-options.ts @@ -0,0 +1,9 @@ +import type { CodemodOptions, Options } from '../types/index.js'; + +export function createOptions(codemodOptions: CodemodOptions): Options { + const { projectRoot } = codemodOptions; + + return { + projectRoot, + }; +} diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/index.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/index.ts new file mode 100644 index 00000000..5435fe02 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/steps/index.ts @@ -0,0 +1,2 @@ +export * from './add-end-of-line.js'; +export * from './create-options.js'; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/types/index.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/types/index.ts new file mode 100644 index 00000000..e9bbbebc --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/types/index.ts @@ -0,0 +1,9 @@ +type CodemodOptions = { + projectRoot: string; +}; + +type Options = { + projectRoot: string; +}; + +export type { CodemodOptions, Options }; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints.ts new file mode 100644 index 00000000..1e540879 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints.ts @@ -0,0 +1 @@ +export * from './blueprints/blueprints-root.js'; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints/blueprints-root.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints/blueprints-root.ts new file mode 100644 index 00000000..237d2fb9 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/src/utils/blueprints/blueprints-root.ts @@ -0,0 +1,7 @@ +import { join } from 'node:path'; + +import { getFilePath } from '@codemod-utils/blueprints'; + +const fileURL = import.meta.url; + +export const blueprintsRoot = join(getFilePath(fileURL), '../../blueprints'); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/index.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/index.ts new file mode 100644 index 00000000..a8a96766 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/index.ts @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('sample-project/input'); +const outputProject = convertFixtureToJson('sample-project/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/input/file.txt b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/input/file.txt new file mode 100644 index 00000000..6769dd60 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/input/file.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/output/file.txt b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/output/file.txt new file mode 100644 index 00000000..cd087558 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/fixtures/sample-project/output/file.txt @@ -0,0 +1 @@ +Hello world! diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/helpers/shared-test-setups/sample-project.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/helpers/shared-test-setups/sample-project.ts new file mode 100644 index 00000000..a7d7ecab --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/helpers/shared-test-setups/sample-project.ts @@ -0,0 +1,11 @@ +import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + projectRoot: 'tmp/sample-project', +}; + +const options: Options = { + projectRoot: 'tmp/sample-project', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/index/sample-project.test.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/index/sample-project.test.ts new file mode 100644 index 00000000..7a97215f --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/index/sample-project.test.ts @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { runCodemod } from '../../src/index.js'; +import { + inputProject, + outputProject, +} from '../fixtures/sample-project/index.js'; +import { codemodOptions } from '../helpers/shared-test-setups/sample-project.js'; + +test('index > sample-project', function () { + loadFixture(inputProject, codemodOptions); + + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/base-case.test.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/base-case.test.ts new file mode 100644 index 00000000..cf5dfe06 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/base-case.test.ts @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > base case', function () { + const inputProject = { + 'file.txt': 'Hello world!', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.ts new file mode 100644 index 00000000..2340e587 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.ts @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file ends with newline)', function () { + const inputProject = { + 'file.txt': 'Hello world!\n', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-is-empty.test.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-is-empty.test.ts new file mode 100644 index 00000000..218b3c4e --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/add-end-of-line/edge-case-file-is-empty.test.ts @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file is empty)', function () { + const inputProject = { + 'file.txt': '', + }; + + const outputProject = { + 'file.txt': '\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/create-options/sample-project.test.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/create-options/sample-project.test.ts new file mode 100644 index 00000000..fbfe0291 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/steps/create-options/sample-project.test.ts @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | create-options > sample-project', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/utils/blueprints/blueprints-root.test.ts b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/utils/blueprints/blueprints-root.test.ts new file mode 100644 index 00000000..df5ed4f0 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tests/utils/blueprints/blueprints-root.test.ts @@ -0,0 +1,7 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { blueprintsRoot } from '../../../src/utils/blueprints.js'; + +test('utils | blueprints | blueprints-root', function () { + assert.strictEqual(blueprintsRoot.endsWith('src/blueprints'), true); +}); diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tsconfig.build.json b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tsconfig.build.json new file mode 100644 index 00000000..6ff3bf82 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "@tsconfig/node16/tsconfig", + "@tsconfig/strictest/tsconfig", + "@tsconfig/esm/tsconfig" + ], + "compilerOptions": { + "declaration": false, + "moduleResolution": "NodeNext", + "outDir": "dist" + }, + "include": ["bin", "src"], + "exclude": ["src/blueprints"] +} diff --git a/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tsconfig.json b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tsconfig.json new file mode 100644 index 00000000..dfd1d499 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript-with-addons/output/ember-codemod-args-to-signature/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "@tsconfig/node16/tsconfig", + "@tsconfig/strictest/tsconfig", + "@tsconfig/esm/tsconfig" + ], + "compilerOptions": { + "declaration": false, + "moduleResolution": "NodeNext", + "outDir": "dist-for-testing" + }, + "include": ["bin", "src", "tests"], + "exclude": ["src/blueprints", "tests/fixtures"] +} diff --git a/packages/cli/tests/fixtures/typescript/index.js b/packages/cli/tests/fixtures/typescript/index.js new file mode 100644 index 00000000..28d08681 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/index.js @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('typescript/input'); +const outputProject = convertFixtureToJson('typescript/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/typescript/input/.gitkeep b/packages/cli/tests/fixtures/typescript/input/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/typescript/output/.gitkeep b/packages/cli/tests/fixtures/typescript/output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.eslintignore b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.eslintignore new file mode 100644 index 00000000..771057c8 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.eslintignore @@ -0,0 +1,13 @@ +# compiled output +/dist/ +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +!.* +.*/ +/src/blueprints/ +/tests/fixtures/ diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.eslintrc.cjs b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.eslintrc.cjs new file mode 100644 index 00000000..ecb3f494 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.eslintrc.cjs @@ -0,0 +1,61 @@ +'use strict'; + +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + plugins: ['@typescript-eslint', 'simple-import-sort', 'typescript-sort-keys'], + extends: [ + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'plugin:n/recommended', + 'plugin:prettier/recommended', + 'plugin:typescript-sort-keys/recommended', + ], + rules: { + curly: 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', + }, + settings: { + 'import/resolver': { + node: true, + typescript: true, + }, + }, + overrides: [ + // TypeScript files + { + files: ['**/*.{cts,ts}'], + extends: [ + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + ], + rules: { + '@typescript-eslint/array-type': 'error', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + }, + }, + // TypeScript and JavaScript files + { + files: ['**/*.{cjs,cts,js,ts}'], + rules: { + 'import/no-duplicates': 'error', + }, + }, + // Node files + { + files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'], + env: { + browser: false, + node: true, + }, + extends: ['plugin:n/recommended'], + }, + ], +}; diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md new file mode 100644 index 00000000..4296e54f --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-better-documentation.md @@ -0,0 +1,27 @@ +--- +name: Ask for better documentation +about: Ask for better documentation +title: '' +labels: 'enhance: documentation' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve documentation. + +Here, documentation can mean a few different things, including README, code comments, and tests. Anything that will help everyone understand how to use `ember-codemod-pod-to-octane`! + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md new file mode 100644 index 00000000..d4d18a4a --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/ask-for-new-feature-or-refactor.md @@ -0,0 +1,27 @@ +--- +name: Ask for new feature or refactor +about: Ask for new feature or refactor +title: '' +labels: 'enhance: code' +assignees: '' + +--- + +Hello! Thanks for taking time to suggest how we can improve `ember-codemod-pod-to-octane`. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request already. + + +## I would like to see... 🙋‍♀️🙋‍♂️ + +A clear, concise description of what you want to happen. + + +## Why and how 💬 + +A clear, concise description of why you want something to happen and how we might be able to solve the problem. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here. diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-bug.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-bug.md new file mode 100644 index 00000000..140b92c9 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-bug.md @@ -0,0 +1,38 @@ +--- +name: Report bug +about: Report bug +title: '' +labels: bug +assignees: '' + +--- + +Hello! Thanks for taking time to make a bug report. + +Before you make a new issue, please search for similar issues. It's possible that someone has reported this bug already. + + +## Describe the bug 🐞 + +A clear and concise description of the bug. + + +## Expected behavior 🤔 + +A clear and concise description of what you expected to see. + + +## Minimal reproduction 🔬 + +Describe steps to reproduce the issue. + +1. ... +1. ... +1. ... + +If possible, please share a repo with the minimum files to reproduce the issue. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-outdated-dependency.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-outdated-dependency.md new file mode 100644 index 00000000..3fb22da0 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/ISSUE_TEMPLATE/report-outdated-dependency.md @@ -0,0 +1,35 @@ +--- +name: Report outdated dependency +about: Report outdated dependency +title: '' +labels: 'enhance: dependency' +assignees: '' + +--- + +Hello! Thanks for taking time to make an outdated dependency report. + +Before you make a new issue, please search for similar issues. It's possible that someone has made a request for update already. + + +## List outdated dependencies 🔗 + +When you ran `pnpm outdated`, what did you see? + +```sh +┌────────────────────────┬─────────┬────────┐ +│ Package │ Current │ Latest │ +├────────────────────────┼─────────┼────────┤ +│ @sondr3/minitest (dev) │ 0.1.1 │ 0.1.2 │ +└────────────────────────┴─────────┴────────┘ +``` + + +## Risk analysis ⚠️ + +Are there breaking changes that we should be aware of? Please add links to the `CHANGELOG`s, if they are available. + + +## Additional context ➕ + +If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here. diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/workflows/ci.yml b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/workflows/ci.yml new file mode 100644 index 00000000..5a6e74c7 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +env: + NODE_VERSION: 16 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm lint + + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out a copy of the repo + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + cache: 'pnpm' + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.gitignore b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.gitignore new file mode 100644 index 00000000..cc33aa0e --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.gitignore @@ -0,0 +1,12 @@ +# compiled output +dist/ +dist-for-testing/ +tmp/ + +# dependencies +node_modules/ + +# misc +.DS_Store +.env* +.eslintcache diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.npmignore b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.npmignore new file mode 100644 index 00000000..fc33b3b8 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.npmignore @@ -0,0 +1,25 @@ +# compiled output +/dist-for-testing/ +/tmp/ + +# dependencies +/node_modules/ + +# misc +/.DS_Store +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.cjs +/.git/ +/.github/ +/.gitignore +/.pnpm-debug.log +/.prettierignore +/.prettierrc.cjs +/build.sh +/codemod-test-fixture.sh +/codemod-test-fixtures.sh +/CONTRIBUTING.md +/create-test-fixture.sh +/tests/ diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.prettierrc.cjs b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.prettierrc.cjs new file mode 100644 index 00000000..004c04d2 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/.prettierrc.cjs @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + overrides: [ + { + files: '*.{cjs,cts,js,mjs,mts,ts}', + options: { + printWidth: 80, + singleQuote: true, + trailingComma: 'all', + }, + }, + ], +}; diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/CHANGELOG.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/CHANGELOG.md new file mode 100644 index 00000000..825c32f0 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/CONTRIBUTING.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/CONTRIBUTING.md new file mode 100644 index 00000000..4129fd42 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/CONTRIBUTING.md @@ -0,0 +1,86 @@ +# Contributing to ember-codemod-pod-to-octane + +Open source projects like `ember-codemod-pod-to-octane` live on your words of encouragement and contribution. Please give feedback, report issues, or submit pull requests! + +Here are some guidelines to help you and everyone else. + + +## Local development + +
+Install dependencies + +1. Fork and clone this repo. + + ```sh + git clone git@github.com:/ember-codemod-pod-to-octane.git + ``` + +1. Change directory. + + ```sh + cd ember-codemod-pod-to-octane + ``` + +1. Use [`pnpm`](https://pnpm.io/installation) to install dependencies. + + ```sh + pnpm install + ``` + +
+ + +
+Lint files + +1. When you write code, please check that it meets the linting rules. + + ```sh + pnpm lint + ``` + +1. You can run `lint:fix` to automatically fix linting errors. + + ```sh + pnpm lint:fix + ``` + +
+ + +
+Run tests + +1. When you write code, please check that all tests continue to pass. + + ```sh + pnpm test + ``` + +
+ + +
+ +Publish packages (for admins) + +1. Generate a [personal access token](https://github.com/settings/tokens/) in GitHub, with default values for scopes (none selected). + +1. Run the `changelog` script. This generates a text that you can add to `CHANGELOG.md`. + + ```sh + GITHUB_AUTH= pnpm changelog + ``` + +1. The package follows [semantic versioning](https://semver.org/). Update the version in `package.json` accordingly. + +1. Create a tag and provide release notes. The tag name should match the package version. + +1. Publish the package. + + ```sh + pnpm publish + ``` + +
diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/LICENSE.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/LICENSE.md new file mode 100644 index 00000000..94385605 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2023 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/README.md b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/README.md new file mode 100644 index 00000000..e490fee2 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/README.md @@ -0,0 +1,53 @@ +# ember-codemod-pod-to-octane + +_Codemod to [PROVIDE A SHORT DESCRIPTION.]_ + + +## Usage + +### Arguments + +[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.] + +
+Optional: Specify the project root + +Pass `--root` to run the codemod somewhere else (i.e. not in the current directory). + +```sh +npx ember-codemod-pod-to-octane --root= +``` + +
+ + +### Limitations + +The codemod is designed to cover typical cases. It is not designed to cover one-off cases. + +To better meet your needs, consider cloning the repo and running the codemod locally. + +```sh +cd + +# Compile TypeScript +pnpm build + +# Run codemod +./dist/bin/ember-codemod-pod-to-octane.js --root= +``` + + +## Compatibility + +- Node.js v16 or above + + +## Contributing + +See the [Contributing](CONTRIBUTING.md) guide for details. + + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/bin/ember-codemod-pod-to-octane.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/bin/ember-codemod-pod-to-octane.ts new file mode 100755 index 00000000..9e41f810 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/bin/ember-codemod-pod-to-octane.ts @@ -0,0 +1,26 @@ +#!/usr/bin/env node +// eslint-disable-next-line n/shebang +'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)) + .option('root', { + describe: 'Where to run the codemod', + type: 'string', + }) + .parseSync(); + +const codemodOptions: CodemodOptions = { + projectRoot: argv['root'] ?? process.cwd(), +}; + +runCodemod(codemodOptions); diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/build.sh b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/build.sh new file mode 100755 index 00000000..79c3a66d --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +COMMAND="ember-codemod-pod-to-octane" +ENVIRONMENT=$1 + +if [ $ENVIRONMENT = "--production" ] +then + # Clean slate + rm -rf "dist" + + # Compile TypeScript + tsc --project "tsconfig.build.json" + + # Configure files + chmod +x "dist/bin/$COMMAND.js" + + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist/src/blueprints" + fi + + echo "SUCCESS: Built dist.\n" + +elif [ $ENVIRONMENT = "--test" ] +then + # Clean slate + rm -rf "dist-for-testing" + + # Compile TypeScript + tsc --project "tsconfig.json" + + # Configure files + if [ -d "src/blueprints" ] + then + cp -r "src/blueprints" "dist-for-testing/src/blueprints" + fi + + echo "SUCCESS: Built dist-for-testing.\n" + +fi diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/codemod-test-fixture.sh b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/codemod-test-fixture.sh new file mode 100755 index 00000000..57ceb336 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/codemod-test-fixture.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix the expected output of a test fixture after updating the source code. +# +# B. Usage +# +# For named arguments, do not include `=` between the flag and the value. +# Positional arguments are to appear at the end. +# +# ./codemod-test-fixture.sh [OPTIONAL-FLAGS] +# +#--------- + +# Get named arguments for the binary +while getopts ":N:" flag +do + case $flag in + N) NAMED_ARGUMENTS=$OPTARG;; + esac +done + +# Get fixture name +FIXTURE=${@:$OPTIND:1} + +if [ ! $FIXTURE ] +then + echo "ERROR: Please specify the fixture name.\n" + exit 1 +elif [ ! -d "tests/fixtures/$FIXTURE/input" ] +then + echo "ERROR: Input folder \`tests/fixtures/$FIXTURE/input\` does not exist.\n" + exit 1 +fi + +rm -r "tests/fixtures/$FIXTURE/output" +cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output" + +./dist/bin/ember-codemod-pod-to-octane.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output" + +echo "SUCCESS: Updated the output of $FIXTURE.\n" diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/codemod-test-fixtures.sh b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/codemod-test-fixtures.sh new file mode 100755 index 00000000..5caf3c3a --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/codemod-test-fixtures.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +#---------- +# +# A. Purpose +# +# Fix all test fixtures after updating the source code. +# +# B. Usage +# +# ./codemod-test-fixtures.sh +# +#--------- + +# Compile TypeScript +pnpm build + +./codemod-test-fixture.sh \ + -N "" \ + sample-project diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/package.json b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/package.json new file mode 100644 index 00000000..9a35315b --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/package.json @@ -0,0 +1,79 @@ +{ + "name": "ember-codemod-pod-to-octane", + "version": "0.0.0", + "private": true, + "description": "Small description for ember-codemod-pod-to-octane goes here", + "keywords": [ + "codemod", + "ember-codemod", + "emberjs" + ], + "repository": "", + "license": "MIT", + "author": "", + "type": "module", + "main": "dist/src/index.js", + "bin": "dist/bin/ember-codemod-pod-to-octane.js", + "directories": { + "test": "tests" + }, + "files": [ + "dist" + ], + "scripts": { + "build": "./build.sh --production", + "changelog": "lerna-changelog", + "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", + "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "lint:types": "tsc --noEmit", + "prepare": "pnpm build", + "test": "./build.sh --test && mt dist-for-testing --quiet" + }, + "dependencies": { + "@codemod-utils/files": "^0.5.1", + "yargs": "^17.7.2" + }, + "devDependencies": { + "@babel/core": "^7.22.8", + "@codemod-utils/tests": "^0.2.4", + "@sondr3/minitest": "0.1.1", + "@tsconfig/esm": "^1.0.4", + "@tsconfig/node16": "^16.1.0", + "@tsconfig/strictest": "^2.0.1", + "@types/node": "^16.11.7", + "@types/yargs": "^17.0.24", + "@typescript-eslint/eslint-plugin": "^5.61.0", + "@typescript-eslint/parser": "^5.61.0", + "concurrently": "^8.2.0", + "eslint": "^8.44.0", + "eslint-config-prettier": "^8.8.0", + "eslint-import-resolver-typescript": "^3.5.5", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-n": "^16.0.1", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-simple-import-sort": "^10.0.0", + "eslint-plugin-typescript-sort-keys": "^2.3.0", + "lerna-changelog": "^2.2.0", + "prettier": "^2.8.8", + "typescript": "^5.1.6" + }, + "engines": { + "node": "16.* || >= 18" + }, + "changelog": { + "labels": { + "breaking": "Breaking Change", + "bug": "Bug Fix", + "enhance: code": "Enhancement", + "enhance: dependency": "Internal", + "enhance: documentation": "Documentation" + } + }, + "pnpm": { + "overrides": { + "eslint-plugin-import@2.27.5>tsconfig-paths": "^4.2.0" + } + } +} diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/index.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/index.ts new file mode 100644 index 00000000..b2f3be42 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/index.ts @@ -0,0 +1,9 @@ +import { addEndOfLine, createOptions } from './steps/index.js'; +import type { CodemodOptions } from './types/index.js'; + +export function runCodemod(codemodOptions: CodemodOptions): void { + const options = createOptions(codemodOptions); + + // TODO: Replace with actual steps + addEndOfLine(options); +} diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/add-end-of-line.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/add-end-of-line.ts new file mode 100644 index 00000000..de3ae4e1 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/add-end-of-line.ts @@ -0,0 +1,26 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { createFiles, findFiles } from '@codemod-utils/files'; + +import type { Options } from '../types/index.js'; + +export function addEndOfLine(options: Options): void { + const { projectRoot } = options; + + const filePaths = findFiles('**/*.txt', { + projectRoot, + }); + + const fileMap = new Map( + filePaths.map((filePath) => { + const file = readFileSync(join(projectRoot, filePath), 'utf8'); + + const newFile = file.endsWith('\n') ? file : `${file}\n`; + + return [filePath, newFile]; + }), + ); + + createFiles(fileMap, options); +} diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/create-options.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/create-options.ts new file mode 100644 index 00000000..8c156fb8 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/create-options.ts @@ -0,0 +1,9 @@ +import type { CodemodOptions, Options } from '../types/index.js'; + +export function createOptions(codemodOptions: CodemodOptions): Options { + const { projectRoot } = codemodOptions; + + return { + projectRoot, + }; +} diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/index.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/index.ts new file mode 100644 index 00000000..5435fe02 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/steps/index.ts @@ -0,0 +1,2 @@ +export * from './add-end-of-line.js'; +export * from './create-options.js'; diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/types/index.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/types/index.ts new file mode 100644 index 00000000..e9bbbebc --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/src/types/index.ts @@ -0,0 +1,9 @@ +type CodemodOptions = { + projectRoot: string; +}; + +type Options = { + projectRoot: string; +}; + +export type { CodemodOptions, Options }; diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/index.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/index.ts new file mode 100644 index 00000000..a8a96766 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/index.ts @@ -0,0 +1,6 @@ +import { convertFixtureToJson } from '@codemod-utils/tests'; + +const inputProject = convertFixtureToJson('sample-project/input'); +const outputProject = convertFixtureToJson('sample-project/output'); + +export { inputProject, outputProject }; diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/input/file.txt b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/input/file.txt new file mode 100644 index 00000000..6769dd60 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/input/file.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/output/file.txt b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/output/file.txt new file mode 100644 index 00000000..cd087558 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/fixtures/sample-project/output/file.txt @@ -0,0 +1 @@ +Hello world! diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/helpers/shared-test-setups/sample-project.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/helpers/shared-test-setups/sample-project.ts new file mode 100644 index 00000000..a7d7ecab --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/helpers/shared-test-setups/sample-project.ts @@ -0,0 +1,11 @@ +import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + projectRoot: 'tmp/sample-project', +}; + +const options: Options = { + projectRoot: 'tmp/sample-project', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/index/sample-project.test.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/index/sample-project.test.ts new file mode 100644 index 00000000..7a97215f --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/index/sample-project.test.ts @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { runCodemod } from '../../src/index.js'; +import { + inputProject, + outputProject, +} from '../fixtures/sample-project/index.js'; +import { codemodOptions } from '../helpers/shared-test-setups/sample-project.js'; + +test('index > sample-project', function () { + loadFixture(inputProject, codemodOptions); + + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + runCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/base-case.test.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/base-case.test.ts new file mode 100644 index 00000000..cf5dfe06 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/base-case.test.ts @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > base case', function () { + const inputProject = { + 'file.txt': 'Hello world!', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.ts new file mode 100644 index 00000000..2340e587 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-ends-with-newline.test.ts @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file ends with newline)', function () { + const inputProject = { + 'file.txt': 'Hello world!\n', + }; + + const outputProject = { + 'file.txt': 'Hello world!\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-is-empty.test.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-is-empty.test.ts new file mode 100644 index 00000000..218b3c4e --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/add-end-of-line/edge-case-file-is-empty.test.ts @@ -0,0 +1,23 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { addEndOfLine } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | add-end-of-line > edge case (file is empty)', function () { + const inputProject = { + 'file.txt': '', + }; + + const outputProject = { + 'file.txt': '\n', + }; + + loadFixture(inputProject, codemodOptions); + + addEndOfLine(options); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/create-options/sample-project.test.ts b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/create-options/sample-project.test.ts new file mode 100644 index 00000000..fbfe0291 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tests/steps/create-options/sample-project.test.ts @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../src/steps/index.js'; +import { + codemodOptions, + options, +} from '../../helpers/shared-test-setups/sample-project.js'; + +test('steps | create-options > sample-project', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tsconfig.build.json b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tsconfig.build.json new file mode 100644 index 00000000..6ff3bf82 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "@tsconfig/node16/tsconfig", + "@tsconfig/strictest/tsconfig", + "@tsconfig/esm/tsconfig" + ], + "compilerOptions": { + "declaration": false, + "moduleResolution": "NodeNext", + "outDir": "dist" + }, + "include": ["bin", "src"], + "exclude": ["src/blueprints"] +} diff --git a/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tsconfig.json b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tsconfig.json new file mode 100644 index 00000000..dfd1d499 --- /dev/null +++ b/packages/cli/tests/fixtures/typescript/output/ember-codemod-pod-to-octane/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "@tsconfig/node16/tsconfig", + "@tsconfig/strictest/tsconfig", + "@tsconfig/esm/tsconfig" + ], + "compilerOptions": { + "declaration": false, + "moduleResolution": "NodeNext", + "outDir": "dist-for-testing" + }, + "include": ["bin", "src", "tests"], + "exclude": ["src/blueprints", "tests/fixtures"] +} diff --git a/packages/cli/tests/helpers/shared-test-setups/javascript-with-addons.ts b/packages/cli/tests/helpers/shared-test-setups/javascript-with-addons.ts new file mode 100644 index 00000000..bf7db1d0 --- /dev/null +++ b/packages/cli/tests/helpers/shared-test-setups/javascript-with-addons.ts @@ -0,0 +1,31 @@ +import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + addons: new Set([ + 'ast-javascript', + 'ast-template', + 'blueprints', + 'ember-cli-string', + 'json', + ]), + hasTypeScript: false, + name: 'ember-codemod-args-to-signature', + projectRoot: 'tmp/javascript-with-addons', +}; + +const options: Options = { + codemod: { + addons: new Set([ + 'ast-javascript', + 'ast-template', + 'blueprints', + 'ember-cli-string', + 'json', + ]), + hasTypeScript: false, + name: 'ember-codemod-args-to-signature', + }, + projectRoot: 'tmp/javascript-with-addons', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/helpers/shared-test-setups/javascript.ts b/packages/cli/tests/helpers/shared-test-setups/javascript.ts new file mode 100644 index 00000000..3ab01685 --- /dev/null +++ b/packages/cli/tests/helpers/shared-test-setups/javascript.ts @@ -0,0 +1,19 @@ +import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + addons: new Set(), + hasTypeScript: false, + name: 'ember-codemod-pod-to-octane', + projectRoot: 'tmp/javascript', +}; + +const options: Options = { + codemod: { + addons: new Set(), + hasTypeScript: false, + name: 'ember-codemod-pod-to-octane', + }, + projectRoot: 'tmp/javascript', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/helpers/shared-test-setups/typescript-with-addons.ts b/packages/cli/tests/helpers/shared-test-setups/typescript-with-addons.ts new file mode 100644 index 00000000..34df13fd --- /dev/null +++ b/packages/cli/tests/helpers/shared-test-setups/typescript-with-addons.ts @@ -0,0 +1,31 @@ +import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + addons: new Set([ + 'ast-javascript', + 'ast-template', + 'blueprints', + 'ember-cli-string', + 'json', + ]), + hasTypeScript: true, + name: 'ember-codemod-args-to-signature', + projectRoot: 'tmp/typescript-with-addons', +}; + +const options: Options = { + codemod: { + addons: new Set([ + 'ast-javascript', + 'ast-template', + 'blueprints', + 'ember-cli-string', + 'json', + ]), + hasTypeScript: true, + name: 'ember-codemod-args-to-signature', + }, + projectRoot: 'tmp/typescript-with-addons', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/helpers/shared-test-setups/typescript.ts b/packages/cli/tests/helpers/shared-test-setups/typescript.ts new file mode 100644 index 00000000..8ee119f5 --- /dev/null +++ b/packages/cli/tests/helpers/shared-test-setups/typescript.ts @@ -0,0 +1,19 @@ +import type { CodemodOptions, Options } from '../../../src/types/index.js'; + +const codemodOptions: CodemodOptions = { + addons: new Set(), + hasTypeScript: true, + name: 'ember-codemod-pod-to-octane', + projectRoot: 'tmp/typescript', +}; + +const options: Options = { + codemod: { + addons: new Set(), + hasTypeScript: true, + name: 'ember-codemod-pod-to-octane', + }, + projectRoot: 'tmp/typescript', +}; + +export { codemodOptions, options }; diff --git a/packages/cli/tests/migration/index/javascript-with-addons.test.ts b/packages/cli/tests/migration/index/javascript-with-addons.test.ts new file mode 100644 index 00000000..cda26a33 --- /dev/null +++ b/packages/cli/tests/migration/index/javascript-with-addons.test.ts @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { createCodemod } from '../../../src/migration/index.js'; +import { + inputProject, + outputProject, +} from '../../fixtures/javascript-with-addons/index.js'; +import { codemodOptions } from '../../helpers/shared-test-setups/javascript-with-addons.js'; + +test('migration | index > javascript with addons', function () { + loadFixture(inputProject, codemodOptions); + + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/migration/index/javascript.test.ts b/packages/cli/tests/migration/index/javascript.test.ts new file mode 100644 index 00000000..c0af59b5 --- /dev/null +++ b/packages/cli/tests/migration/index/javascript.test.ts @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { createCodemod } from '../../../src/migration/index.js'; +import { + inputProject, + outputProject, +} from '../../fixtures/javascript/index.js'; +import { codemodOptions } from '../../helpers/shared-test-setups/javascript.js'; + +test('migration | index > javascript', function () { + loadFixture(inputProject, codemodOptions); + + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/migration/index/typescript-with-addons.test.ts b/packages/cli/tests/migration/index/typescript-with-addons.test.ts new file mode 100644 index 00000000..f5d6bc78 --- /dev/null +++ b/packages/cli/tests/migration/index/typescript-with-addons.test.ts @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { createCodemod } from '../../../src/migration/index.js'; +import { + inputProject, + outputProject, +} from '../../fixtures/typescript-with-addons/index.js'; +import { codemodOptions } from '../../helpers/shared-test-setups/typescript-with-addons.js'; + +test('migration | index > typescript with addons', function () { + loadFixture(inputProject, codemodOptions); + + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/migration/index/typescript.test.ts b/packages/cli/tests/migration/index/typescript.test.ts new file mode 100644 index 00000000..813eee3c --- /dev/null +++ b/packages/cli/tests/migration/index/typescript.test.ts @@ -0,0 +1,21 @@ +import { assertFixture, loadFixture, test } from '@codemod-utils/tests'; + +import { createCodemod } from '../../../src/migration/index.js'; +import { + inputProject, + outputProject, +} from '../../fixtures/typescript/index.js'; +import { codemodOptions } from '../../helpers/shared-test-setups/typescript.js'; + +test('migration | index > typescript', function () { + loadFixture(inputProject, codemodOptions); + + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); + + // Check idempotence + createCodemod(codemodOptions); + + assertFixture(outputProject, codemodOptions); +}); diff --git a/packages/cli/tests/migration/steps/create-options/javascript-with-addons.test.ts b/packages/cli/tests/migration/steps/create-options/javascript-with-addons.test.ts new file mode 100644 index 00000000..c90ec9e7 --- /dev/null +++ b/packages/cli/tests/migration/steps/create-options/javascript-with-addons.test.ts @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../../src/migration/steps/index.js'; +import { + codemodOptions, + options, +} from '../../../helpers/shared-test-setups/javascript-with-addons.js'; + +test('migration | steps | create-options > javascript-with-addons', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/migration/steps/create-options/javascript.test.ts b/packages/cli/tests/migration/steps/create-options/javascript.test.ts new file mode 100644 index 00000000..c735f453 --- /dev/null +++ b/packages/cli/tests/migration/steps/create-options/javascript.test.ts @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../../src/migration/steps/index.js'; +import { + codemodOptions, + options, +} from '../../../helpers/shared-test-setups/javascript.js'; + +test('migration | steps | create-options > javascript', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/migration/steps/create-options/typescript-with-addons.test.ts b/packages/cli/tests/migration/steps/create-options/typescript-with-addons.test.ts new file mode 100644 index 00000000..0bc0c185 --- /dev/null +++ b/packages/cli/tests/migration/steps/create-options/typescript-with-addons.test.ts @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../../src/migration/steps/index.js'; +import { + codemodOptions, + options, +} from '../../../helpers/shared-test-setups/typescript-with-addons.js'; + +test('migration | steps | create-options > typescript-with-addons', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/migration/steps/create-options/typescript.test.ts b/packages/cli/tests/migration/steps/create-options/typescript.test.ts new file mode 100644 index 00000000..60469c29 --- /dev/null +++ b/packages/cli/tests/migration/steps/create-options/typescript.test.ts @@ -0,0 +1,11 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { createOptions } from '../../../../src/migration/steps/index.js'; +import { + codemodOptions, + options, +} from '../../../helpers/shared-test-setups/typescript.js'; + +test('migration | steps | create-options > typescript', function () { + assert.deepStrictEqual(createOptions(codemodOptions), options); +}); diff --git a/packages/cli/tests/utils/blueprints/blueprints-root.test.ts b/packages/cli/tests/utils/blueprints/blueprints-root.test.ts new file mode 100644 index 00000000..df5ed4f0 --- /dev/null +++ b/packages/cli/tests/utils/blueprints/blueprints-root.test.ts @@ -0,0 +1,7 @@ +import { assert, test } from '@codemod-utils/tests'; + +import { blueprintsRoot } from '../../../src/utils/blueprints.js'; + +test('utils | blueprints | blueprints-root', function () { + assert.strictEqual(blueprintsRoot.endsWith('src/blueprints'), true); +}); diff --git a/packages/cli/tsconfig.build.json b/packages/cli/tsconfig.build.json new file mode 100644 index 00000000..4bc44e20 --- /dev/null +++ b/packages/cli/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "@shared-configs/typescript/node16", + "compilerOptions": { + "declaration": false, + "outDir": "dist" + }, + "include": ["bin", "src"], + "exclude": ["src/blueprints"] +} diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json new file mode 100644 index 00000000..5b481c97 --- /dev/null +++ b/packages/cli/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@shared-configs/typescript/node16", + "compilerOptions": { + "declaration": false, + "outDir": "dist-for-testing" + }, + "include": ["bin", "src", "tests"], + "exclude": ["src/blueprints", "tests/fixtures"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08de0c24..52217220 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -208,6 +208,55 @@ importers: specifier: ^5.1.6 version: 5.1.6 + packages/cli: + dependencies: + '@codemod-utils/blueprints': + specifier: workspace:* + version: link:../blueprints + '@codemod-utils/files': + specifier: workspace:* + version: link:../files + '@codemod-utils/json': + specifier: workspace:* + version: link:../json + yargs: + specifier: ^17.7.2 + version: 17.7.2 + devDependencies: + '@codemod-utils/tests': + specifier: workspace:* + version: link:../tests + '@shared-configs/eslint-config-node': + specifier: workspace:* + version: link:../../configs/eslint/node + '@shared-configs/prettier': + specifier: workspace:* + version: link:../../configs/prettier + '@shared-configs/typescript': + specifier: workspace:* + version: link:../../configs/typescript + '@sondr3/minitest': + specifier: ^0.1.1 + version: 0.1.1 + '@types/node': + specifier: ^16.11.7 + version: 16.11.7 + '@types/yargs': + specifier: ^17.0.24 + version: 17.0.24 + concurrently: + specifier: ^8.2.0 + version: 8.2.0 + eslint: + specifier: ^8.44.0 + version: 8.44.0 + prettier: + specifier: ^2.8.8 + version: 2.8.8 + typescript: + specifier: ^5.1.6 + version: 5.1.6 + packages/ember-cli-string: devDependencies: '@codemod-utils/tests': @@ -1090,6 +1139,16 @@ packages: /@types/semver@7.5.0: resolution: {integrity: sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==} + /@types/yargs-parser@21.0.0: + resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} + dev: true + + /@types/yargs@17.0.24: + resolution: {integrity: sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==} + dependencies: + '@types/yargs-parser': 21.0.0 + dev: true + /@typescript-eslint/eslint-plugin@5.61.0(@typescript-eslint/parser@5.61.0)(eslint@8.44.0)(typescript@5.1.6): resolution: {integrity: sha512-A5l/eUAug103qtkwccSCxn8ZRwT+7RXWkFECdA4Cvl1dOlDUgTpAOfSEElZn2uSUxhdDpnCdetrf0jvU4qrL+g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1603,7 +1662,6 @@ packages: string-width: 4.2.3 strip-ansi: 6.0.1 wrap-ansi: 7.0.0 - dev: true /clone@1.0.4: resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==} @@ -2431,7 +2489,6 @@ packages: /get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} - dev: true /get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==} @@ -3521,7 +3578,6 @@ packages: /require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} - dev: true /require-main-filename@2.0.0: resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} @@ -4174,7 +4230,6 @@ packages: /y18n@5.0.8: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} - dev: true /yallist@2.1.2: resolution: {integrity: sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==} @@ -4198,7 +4253,6 @@ packages: /yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} - dev: true /yargs@15.4.1: resolution: {integrity: sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==} @@ -4228,7 +4282,6 @@ packages: string-width: 4.2.3 y18n: 5.0.8 yargs-parser: 21.1.1 - dev: true /yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 250ea541..dcc6921a 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -3,6 +3,7 @@ packages: - packages/ast/javascript - packages/ast/template - packages/blueprints + - packages/cli - packages/ember-cli-string - packages/files - packages/json