@planningcenter/tapestry-migration-cli 2.1.0 → 2.1.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@planningcenter/tapestry-migration-cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.1-rc.0",
4
4
  "description": "CLI tool for Tapestry migrations",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
8
- "tapestry-migration-cli": "./dist/index.js"
8
+ "tapestry-migration-cli": "./src/index.ts"
9
9
  },
10
10
  "scripts": {
11
11
  "build": "tsc",
@@ -25,14 +25,17 @@
25
25
  "node": ">=18.0.0"
26
26
  },
27
27
  "dependencies": {
28
- "commander": "^11.0.0"
28
+ "commander": "^11.0.0",
29
+ "jscodeshift": "^17.3.0",
30
+ "tsx": "^4.20.5"
29
31
  },
30
32
  "devDependencies": {
33
+ "@types/jscodeshift": "^17.3.0",
31
34
  "@types/node": "^20.0.0",
32
35
  "typescript": "^5.8.3"
33
36
  },
34
37
  "files": [
35
- "dist/**/*"
38
+ "src/**/*"
36
39
  ],
37
40
  "repository": {
38
41
  "type": "git",
@@ -42,5 +45,5 @@
42
45
  "publishConfig": {
43
46
  "access": "public"
44
47
  },
45
- "gitHead": "19f1539b917c5e588c0eb1b5ae0e570b2025411f"
48
+ "gitHead": "78216706f5cd2e95da447640c68d07be6001699f"
46
49
  }
@@ -0,0 +1,24 @@
1
+ import { Transform } from "jscodeshift"
2
+
3
+ const transform: Transform = (fileInfo, api, options) => {
4
+ let currentSource = fileInfo.source
5
+ let hasAnyChanges = false
6
+
7
+ const transforms: Transform[] = []
8
+
9
+ for (const individualTransform of transforms) {
10
+ const result = individualTransform(
11
+ { ...fileInfo, source: currentSource },
12
+ api,
13
+ options
14
+ )
15
+ if (result && result !== currentSource) {
16
+ currentSource = result as string
17
+ hasAnyChanges = true
18
+ }
19
+ }
20
+
21
+ return hasAnyChanges ? currentSource : null
22
+ }
23
+
24
+ export default transform
package/src/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env tsx
2
+
3
+ import { Command } from "commander"
4
+
5
+ import { runTransforms } from "./jscodeshiftRunner"
6
+
7
+ const program = new Command()
8
+
9
+ program
10
+ .name("tapestry-migration-cli")
11
+ .description("CLI tool for Tapestry migrations")
12
+
13
+ const COMPONENTS = ["button"]
14
+
15
+ program
16
+ .command("run")
17
+ .description("Run a migration of a component from Tapestry React to Tapestry")
18
+ .argument("<component-name>", "The name of the component to migrate")
19
+ .option("-f, --fix", "Write the changes")
20
+ .option("-p, --path <path>", "The path to the folder/file to migrate")
21
+ .option("-v, --verbose", "Verbose output")
22
+ .action((componentName, options) => {
23
+ console.log("Hello from Tapestry Migration CLI! 🎨")
24
+ console.log(`Component: ${componentName}`)
25
+ const key = componentName.toLowerCase()
26
+
27
+ if (COMPONENTS.includes(key)) {
28
+ runTransforms(key, options)
29
+ } else {
30
+ console.log(
31
+ `Invalid component name: ${componentName}. Valid components are: ${COMPONENTS.join(", ")}`
32
+ )
33
+ }
34
+ })
35
+
36
+ program
37
+ .command("help")
38
+ .description("Show help information")
39
+ .action(() => {
40
+ program.help()
41
+ })
42
+
43
+ program.parse()
44
+
45
+ if (!process.argv.slice(2).length) {
46
+ program.outputHelp()
47
+ }
@@ -0,0 +1,49 @@
1
+ import { execSync } from "child_process"
2
+ import { existsSync } from "fs"
3
+ import { dirname, resolve } from "path"
4
+ import { fileURLToPath } from "url"
5
+
6
+ import { Options } from "./shared/types"
7
+
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = dirname(__filename)
10
+
11
+ export function runTransforms(key: string, options: Options): void {
12
+ const transformPath = resolve(__dirname, "components", key, "index.ts")
13
+ const targetPath = options.path
14
+
15
+ if (!existsSync(targetPath)) {
16
+ console.error(`❌ Path not found: ${targetPath}`)
17
+ return
18
+ }
19
+
20
+ console.log("🎯 Running transforms...")
21
+ console.log(`📁 Target: ${targetPath}`)
22
+ console.log(`🔧 Transform: ${transformPath}`)
23
+
24
+ try {
25
+ const command = [
26
+ "npx",
27
+ "--prefer-offline",
28
+ "jscodeshift",
29
+ "-t",
30
+ transformPath,
31
+ targetPath,
32
+ options.fix ? "" : "--dry",
33
+ options.verbose ? "--verbose=2" : "",
34
+ "--parser=tsx",
35
+ ]
36
+ .filter(Boolean)
37
+ .join(" ")
38
+
39
+ console.log(`🚀 Running: ${command}`)
40
+
41
+ execSync(command, {
42
+ cwd: process.cwd(),
43
+ env: process.env,
44
+ stdio: "inherit",
45
+ })
46
+ } catch (error) {
47
+ console.error("❌ Transform failed:", error)
48
+ }
49
+ }
@@ -0,0 +1,6 @@
1
+ export interface Options {
2
+ fix?: boolean
3
+ jsTheme?: string
4
+ path: string
5
+ verbose?: boolean
6
+ }
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/index.js DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from "commander";
3
- const program = new Command();
4
- program
5
- .name("tapestry-migration-cli")
6
- .description("CLI tool for Tapestry migrations");
7
- program
8
- .command("run")
9
- .description("Run a migration of a component from Tapestry React to Tapestry")
10
- .argument("<component-name>", "The name of the component to migrate")
11
- .option("-f, --fix", "Write the changes")
12
- .option("-p, --path", "The path to the folder/file to migrate")
13
- .option("-v, --verbose", "Verbose output")
14
- .action(() => {
15
- console.log("Hello from Tapestry Migration CLI! 🎨");
16
- console.log("This CLI is currently in development.");
17
- console.log("More features coming soon!");
18
- });
19
- program
20
- .command("help")
21
- .description("Show help information")
22
- .action(() => {
23
- program.help();
24
- });
25
- program.parse();
26
- if (!process.argv.slice(2).length) {
27
- program.outputHelp();
28
- }