{"id":15118132,"url":"https://github.com/unjs/codeup","last_synced_at":"2025-06-10T22:41:58.824Z","repository":{"id":237927094,"uuid":"795505754","full_name":"unjs/codeup","owner":"unjs","description":"Automated codebase updater [POC]","archived":false,"fork":false,"pushed_at":"2025-03-19T13:44:45.000Z","size":219,"stargazers_count":46,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-14T13:58:53.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-03T12:34:19.000Z","updated_at":"2025-04-04T04:46:10.000Z","dependencies_parsed_at":"2024-05-29T22:27:08.748Z","dependency_job_id":null,"html_url":"https://github.com/unjs/codeup","commit_stats":null,"previous_names":["unjs/codeup"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fcodeup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fcodeup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fcodeup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fcodeup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/codeup/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fcodeup/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259165995,"owners_count":22815544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-26T01:46:08.737Z","updated_at":"2025-06-10T22:41:58.797Z","avatar_url":"https://github.com/unjs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","others"],"sub_categories":[],"readme":"# codeup\n\n\u003c!-- automd:badges color=yellow --\u003e\n\n[![npm version](https://img.shields.io/npm/v/codeup?color=yellow)](https://npmjs.com/package/codeup)\n[![npm downloads](https://img.shields.io/npm/dm/codeup?color=yellow)](https://npm.chart.dev/codeup)\n\n\u003c!-- /automd --\u003e\n\nAutomated codebase updater.\n\n\u003e [!IMPORTANT]\n\u003e This project a proof of concept in the current state.\n\n## Why?\n\nManually applying a change across multiple repositotires can become tiresome.\n\nCodeup exposes conventional utils and a CLI to make it easier to migrate code and apply changes automatically and programmatically.\n\n## Defining actions\n\nYou can define shared actions using codeup. See [./actions](./actions/) dir for some examples.\n\n```ts\nimport { defineAction } from \"codeup\";\n\nexport default defineAction({\n  meta: {\n    name: \"\",\n    description: \"\",\n    date: \"\",\n  },\n  async filter({ utils, logger }) {},\n  async apply({ utils, logger }) {},\n});\n```\n\n**Example:**\n\n\u003c!-- \u003cdetails\u003e\n\u003csummary\u003eExample:\u003c/summary\u003e --\u003e\n\n\u003c!-- automd:file code src=\"./actions/unjs/eslint-flat.ts\" --\u003e\n\n```ts [eslint-flat.ts]\nimport { defineAction } from \"codeup\";\n\nexport default defineAction({\n  meta: {\n    name: \"eslint-flat\",\n    description: \"Upgrade to eslint flat config with unjs preset\",\n    date: \"2024-05-03\",\n  },\n  async filter({ utils }) {\n    // Only apply if legacy eslint config is found\n    return (\n      (await utils.existsWithAnyExt(\".eslintrc\")) \u0026\u0026\n      !(await utils.existsWithAnyExt(\"eslint.config\"))\n    );\n  },\n  async apply({ utils }) {\n    // Migrate to new eslint config\n    const eslintRC = await utils.readJSON(\".eslintrc\");\n    const eslintignore = (await utils.readLines(\".eslintignore\")) || [];\n    await utils.write(\n      \"eslint.config.mjs\",\n      getConfigTemplate({\n        rules: eslintRC?.rules || {},\n        ignores: eslintignore.filter(\n          (i) =\u003e ![\"\", \"node_modules\", \"dist\", \"coverage\"].includes(i),\n        ),\n      }),\n    );\n\n    // Remove legacy eslint config files\n    await utils.remove(\".eslintrc\");\n    await utils.remove(\".eslintignore\");\n\n    // Update package.json scripts\n    await utils.updatePackageJSON((pkg) =\u003e {\n      if (!pkg.scripts) {\n        return;\n      }\n      for (const name in pkg.scripts) {\n        if (pkg.scripts[name].includes(\"eslint\")) {\n          pkg.scripts[name] = pkg.scripts[name].replace(/--ext\\s+\\S+\\s/, \"\");\n        }\n      }\n    });\n\n    // Ensure latest eslint and preset versions are installed\n    await utils.addDevDependency([\n      \"eslint@^9.0.0\",\n      \"eslint-config-unjs@^0.3.0\",\n    ]);\n\n    // Run lint:fix script once\n    await utils.runScript(\"lint:fix\");\n  },\n});\n\nfunction getConfigTemplate(opts: {\n  rules: Record\u003cstring, unknown\u003e;\n  ignores: string[];\n}) {\n  return /* js */ `\nimport unjs from \"eslint-config-unjs\";\n\n// https://github.com/unjs/eslint-config\nexport default unjs({\n  ignores: ${JSON.stringify(opts.ignores || [], undefined, 2)},\n  rules: ${JSON.stringify(opts.rules || {}, undefined, 2)},\n});\n`.trim();\n}\n```\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- \u003c/details\u003e --\u003e\n\n## Apply Actions\n\nYou can use `codeup apply` CLI to apply actions from a local directory or remote source (powered by [unjs/giget](https://giget.unjs.io)).\n\nBy default actions order will be sorted by date and name.\n\n```sh\n# Run all actions from local dir\nnpx codeup apply --actions path/to/actions/dir\n\n# Run actions from a github source\nnpx codeup apply --actions gh:unjs/codeup/actions/unjs\n```\n\n## Utils\n\nYou can directly use codeup utils as a library use use them within actions context.\n\n```js\nimport { readJSON, runScript } from \"codeup/utils\";\n```\n\n\u003c!-- automd:jsdocs src=\"./src/utils/fs.ts\" --\u003e\n\n## File System\n\n### `append(path, contents, opts?: { newLine? })`\n\nAppend text to a file (with a newline by default)\n\n### `exists(path, opts?: { withAnyExt? })`\n\nChecks if a file or directory exists in path\n\n### `existsWithAnyExt(path)`\n\nChecks if a file or directory exists in path with any extension (input path should not contain extension)\n\n### `findUp(name)`\n\nTry to find a file in the current working directory or any parent directories\n\n### `read(path)`\n\nTry to read a text file and returns its contents\n\n### `readLines(path)`\n\nRead a text file and return its contents as an array of lines\n\n### `remove(path, opts?: { log? })`\n\nTry to remove a file or directory\n\n### `resolve(path)`\n\nResolves a path relative to the current working directory.\n\n### `update(path, fn, opts?: { log? })`\n\nRead a file and update its contents\n\nReturns the updated contents or the old one\n\n### `write(path, contents, opts?: { skipIfExists?, log? })`\n\nWrite text contents to a file\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:jsdocs src=\"./src/utils/json.ts\" --\u003e\n\n## Json\n\n### `readJSON(path)`\n\nTry to read a JSON file\n\n### `updateJSON(path, updater)`\n\nTry to update a JSON file using an updater function and return updated JSON\n\n### `writeJSON(path, json, opts?)`\n\nWrite a JSON file\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:jsdocs src=\"./src/utils/pkg.ts\" --\u003e\n\n## Package Json\n\n### `addDependency(name, opts?)`\n\nAdd a dependency to the project using detected package manager\n\n### `addDevDependency(name, opts?)`\n\nAdd a dev dependency to the project using detected package manager\n\n### `detectPackageManager()`\n\nDetect current package manager\n\n### `readPackageJSON()`\n\nTry to read the closest package.json file\n\n### `removeDependency(name, opts?)`\n\nRemove a dependency from the project using detected package manager\n\n### `runPackageManagerCommand(command, opts?: { ignoreErrors? })`\n\nRun a command with the detected package manager\n\n### `runScript(script)`\n\nRun a `package.json` script using detected package manager\n\n### `updatePackageJSON()`\n\nTry to update the closest package.json file\n\n\u003c!-- /automd --\u003e\n\n## Programmatic API\n\nYou can integrate codeup in your workflows using programmatic API instead of CLI.\n\n```js\nimport { applyActionsFrom } from \"codeup\";\n```\n\n\u003c!-- automd:jsdocs src=\"./src/index.ts\" --\u003e\n\n### `applyAction(action, cwd)`\n\nApply an action within context and working directory.\n\n### `applyActionFromFile(path, workingDir)`\n\nLoad and apply action from file.\n\n### `applyActions(actions, cwd, opts?: { sort })`\n\nApply multiple actions within context and working directory.\n\nIf `opts.sort` is true, actions will be sorted by date or name otherwise in the order they are provided.\n\n### `applyActionsFrom(source, cwd)`\n\nLoad and apply actions from a remote or local source.\n\n### `applyActionsFromDir(actionsDir, cwd)`\n\nLoad and apply actions from directory.\n\n### `createContext(cwd, name?)`\n\nCreate an action context from a working directory.\n\n### `defineAction(action)`\n\n### `getActionName(action)`\n\nGet action name from action object.\n\n### `loadActionFromFile(path)`\n\nLoad action from file.\n\n### `loadActionsFromDir(actionsDir)`\n\nLoad actions from a directory.\n\n### `runWithContext(context, fn)`\n\nRun a function within a context.\n\n### `sortActions(actions)`\n\nSort actions by date or name.\n\n### `useContext()`\n\nGet the current action context or create a new one from the working directory.\n\n\u003c!-- /automd --\u003e\n\n## Development\n\n\u003cdetails\u003e\n\n\u003csummary\u003elocal development\u003c/summary\u003e\n\n- Clone this repository\n- Install latest LTS version of [Node.js](https://nodejs.org/en/)\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`\n- Install dependencies using `pnpm install`\n- Enable stub mode using `pnpm build --stub`\n\n\u003c/details\u003e\n\n## License\n\n\u003c!-- automd:contributors author=\"pi0\" license=MIT --\u003e\n\nPublished under the [MIT](https://github.com/unjs/codeup/blob/main/LICENSE) license.\nMade by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/codeup/graphs/contributors) 💛\n\u003cbr\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/unjs/codeup/graphs/contributors\"\u003e\n\u003cimg src=\"https://contrib.rocks/image?repo=unjs/codeup\" /\u003e\n\u003c/a\u003e\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:with-automd --\u003e\n\n---\n\n_🤖 auto updated with [automd](https://automd.unjs.io)_\n\n\u003c!-- /automd --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fcodeup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Fcodeup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fcodeup/lists"}