Automated Codebase Maintainer.
npm install codeup

Automated codebase updater.
> [!IMPORTANT]
> This project a proof of concept in the current state.
Manually applying a change across multiple repositotires can become tiresome.
Codeup exposes conventional utils and a CLI to make it easier to migrate code and apply changes automatically and programmatically.
You can define shared actions using codeup. See ./actions dir for some examples.
``ts
import { defineAction } from "codeup";
export default defineAction({
meta: {
name: "",
description: "",
date: "",
},
async filter({ utils, logger }) {},
async apply({ utils, logger }) {},
});
`
Example:
`ts [eslint-flat.ts]
import { defineAction } from "codeup";
export default defineAction({
meta: {
name: "eslint-flat",
description: "Upgrade to eslint flat config with unjs preset",
date: "2024-05-03",
},
async filter({ utils }) {
// Only apply if legacy eslint config is found
return (
(await utils.existsWithAnyExt(".eslintrc")) &&
!(await utils.existsWithAnyExt("eslint.config"))
);
},
async apply({ utils }) {
// Migrate to new eslint config
const eslintRC = await utils.readJSON(".eslintrc");
const eslintignore = (await utils.readLines(".eslintignore")) || [];
await utils.write(
"eslint.config.mjs",
getConfigTemplate({
rules: eslintRC?.rules || {},
ignores: eslintignore.filter((i) => !["", "node_modules", "dist", "coverage"].includes(i)),
}),
);
// Remove legacy eslint config files
await utils.remove(".eslintrc");
await utils.remove(".eslintignore");
// Update package.json scripts
await utils.updatePackageJSON((pkg) => {
if (!pkg.scripts) {
return;
}
for (const name in pkg.scripts) {
if (pkg.scripts[name].includes("eslint")) {
pkg.scripts[name] = pkg.scripts[name].replace(/--ext\s+\S+\s/, "");
}
}
});
// Ensure latest eslint and preset versions are installed
await utils.addDevDependency(["eslint@^9.0.0", "eslint-config-unjs@^0.3.0"]);
// Run lint:fix script once
await utils.runScript("lint:fix");
},
});
function getConfigTemplate(opts: { rules: Record
return / js /
import unjs from "eslint-config-unjs";
// https://github.com/unjs/eslint-config
export default unjs({
ignores: ${JSON.stringify(opts.ignores || [], undefined, 2)},
rules: ${JSON.stringify(opts.rules || {}, undefined, 2)},
});.trim();`
}
You can use codeup apply CLI to apply actions from a local directory or remote source (powered by unjs/giget).
By default actions order will be sorted by date and name.
`shRun all actions from local dir
npx codeup apply --actions path/to/actions/dir
Utils
You can directly use codeup utils as a library use use them within actions context.
`js
import { readJSON, runScript } from "codeup/utils";
`File System
$3
Append text to a file (with a newline by default)
$3
Checks if a file or directory exists in path
$3
Checks if a file or directory exists in path with any extension (input path should not contain extension)
$3
Try to find a file in the current working directory or any parent directories
$3
Try to read a text file and returns its contents
$3
Read a text file and return its contents as an array of lines
$3
Try to remove a file or directory
$3
Resolves a path relative to the current working directory.
$3
Read a file and update its contents
Returns the updated contents or the old one
$3
Write text contents to a file
Json
$3
Try to read a JSON file
$3
Try to update a JSON file using an updater function and return updated JSON
$3
Write a JSON file
Package Json
$3
Add a dependency to the project using detected package manager
$3
Add a dev dependency to the project using detected package manager
$3
Detect current package manager
$3
Try to read the closest package.json file
$3
Remove a dependency from the project using detected package manager
$3
Run a command with the detected package manager
$3
Run a
package.json script using detected package manager$3
Try to update the closest package.json file
Programmatic API
You can integrate codeup in your workflows using programmatic API instead of CLI.
`js
import { applyActionsFrom } from "codeup";
`$3
Apply an action within context and working directory.
$3
Load and apply action from file.
$3
Apply multiple actions within context and working directory.
If
opts.sort is true, actions will be sorted by date or name otherwise in the order they are provided.$3
Load and apply actions from a remote or local source.
$3
Load and apply actions from directory.
$3
Create an action context from a working directory.
$3
$3
Get action name from action object.
$3
Load action from file.
$3
Load actions from a directory.
$3
Run a function within a context.
$3
Sort actions by date or name.
$3
Get the current action context or create a new one from the working directory.
Development
local development
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable
- Install dependencies using pnpm install
- Enable stub mode using pnpm build --stub`Published under the MIT license.
Made by @pi0 and community 💛
---
_🤖 auto updated with automd_