diff --git a/autopublish-test/.gitignore b/autopublish-test/.gitignore new file mode 100644 index 0000000..78174f4 --- /dev/null +++ b/autopublish-test/.gitignore @@ -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 \ No newline at end of file diff --git a/autopublish-test/README.md b/autopublish-test/README.md new file mode 100644 index 0000000..09d5ad9 --- /dev/null +++ b/autopublish-test/README.md @@ -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 \ No newline at end of file diff --git a/autopublish-test/codemod.yaml b/autopublish-test/codemod.yaml new file mode 100644 index 0000000..6f8f35c --- /dev/null +++ b/autopublish-test/codemod.yaml @@ -0,0 +1,18 @@ +schema_version: "1.0" + +name: "autopublish-test" +version: "0.1.0" +description: "Transform legacy code patterns" +author: "Author " +license: "MIT" +workflow: "workflow.yaml" +category: "migration" + +targets: + languages: ["typescript"] + +keywords: ["transformation", "migration"] + +registry: + access: "public" + visibility: "public" diff --git a/autopublish-test/package.json b/autopublish-test/package.json new file mode 100644 index 0000000..287af10 --- /dev/null +++ b/autopublish-test/package.json @@ -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" + } +} diff --git a/autopublish-test/scripts/codemod.ts b/autopublish-test/scripts/codemod.ts new file mode 100644 index 0000000..85c69c3 --- /dev/null +++ b/autopublish-test/scripts/codemod.ts @@ -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): Promise { + 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; diff --git a/autopublish-test/tests/fixtures/expected.js b/autopublish-test/tests/fixtures/expected.js new file mode 100644 index 0000000..0eb1048 --- /dev/null +++ b/autopublish-test/tests/fixtures/expected.js @@ -0,0 +1,3 @@ +const oldVariable = "should be const" +const anotherVar = 42 +console.log("debug statement"); \ No newline at end of file diff --git a/autopublish-test/tsconfig.json b/autopublish-test/tsconfig.json new file mode 100644 index 0000000..469fc5a --- /dev/null +++ b/autopublish-test/tsconfig.json @@ -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"] +} diff --git a/autopublish-test/workflow.yaml b/autopublish-test/workflow.yaml new file mode 100644 index 0000000..50a4933 --- /dev/null +++ b/autopublish-test/workflow.yaml @@ -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"