Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions autopublish-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build artifacts
target/
dist/
build/

# Temporary files
*.tmp
*.temp
.cache/

# Environment files
.env
.env.local

# IDE files
.vscode/
.idea/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Package bundles
*.tar.gz
*.tgz
39 changes: 39 additions & 0 deletions autopublish-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# autopublish-test

Transform legacy code patterns

## Installation

```bash
# Install from registry
codemod run autopublish-test

# Or run locally
codemod run -w workflow.yaml
```

## Usage

This codemod transforms typescript code by:

- Converting `var` declarations to `const`/`let`
- Removing debug statements
- Modernizing syntax patterns

## Development

```bash
# Test the transformation
npm test

# Validate the workflow
codemod validate -w workflow.yaml

# Publish to registry
codemod login
codemod publish
```

## License

MIT
18 changes: 18 additions & 0 deletions autopublish-test/codemod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
schema_version: "1.0"

name: "autopublish-test"
version: "0.1.0"
description: "Transform legacy code patterns"
author: "Author <[email protected]>"
license: "MIT"
workflow: "workflow.yaml"
category: "migration"

targets:
languages: ["typescript"]

keywords: ["transformation", "migration"]

registry:
access: "public"
visibility: "public"
14 changes: 14 additions & 0 deletions autopublish-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "autopublish-test",
"version": "0.1.0",
"description": "Transform legacy code patterns",
"type": "module",
"devDependencies": {
"@codemod.com/jssg-types": "^1.0.3",
"typescript": "^5.8.3"
},
"scripts": {
"test": "npx codemod@latest jssg test -l typescript ./scripts/codemod.ts",
"check-types": "npx tsc --noEmit"
}
}
23 changes: 23 additions & 0 deletions autopublish-test/scripts/codemod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { SgRoot } from "codemod:ast-grep";
import type TS from "codemod:ast-grep/langs/typescript";

async function transform(root: SgRoot<TS>): Promise<string> {
const rootNode = root.root();

const nodes = rootNode.findAll({
rule: {
pattern: "var $VAR = $VALUE",
},
});

const edits = nodes.map((node) => {
const varName = node.getMatch("VAR")?.text();
const value = node.getMatch("VALUE")?.text();
return node.replace(`const ${varName} = ${value}`);
});

const newSource = rootNode.commitEdits(edits);
return newSource;
}

export default transform;
3 changes: 3 additions & 0 deletions autopublish-test/tests/fixtures/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const oldVariable = "should be const"
const anotherVar = 42
console.log("debug statement");
17 changes: 17 additions & 0 deletions autopublish-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"types": ["@codemod.com/jssg-types"],
"allowImportingTsExtensions": true,
"noEmit": true,
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true,
"strict": true,
"strictNullChecks": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true
},
"exclude": ["tests"]
}
11 changes: 11 additions & 0 deletions autopublish-test/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "1"

nodes:
- id: apply-transforms
name: Apply AST Transformations
type: automatic
steps:
- name: "Scan typescript files and apply fixes"
js-ast-grep:
js_file: scripts/codemod.ts
language: "typescript"