Skip to content

Commit

Permalink
(Codemods) Use correct bin, paths for Windows (redwoodjs#3458)
Browse files Browse the repository at this point in the history
* get things working on windows

* get tests working
  • Loading branch information
jtoar authored Sep 30, 2021
1 parent a367e14 commit 8596821
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path'
import fg from 'fast-glob'
import task from 'tasuku'

import getRWPaths from '../../../lib/getRWPaths'
import runTransform from '../../../lib/runTransform'

export const command = 'update-graphql-function'
Expand All @@ -12,11 +11,9 @@ export const description =

export const handler = () => {
task('Updating the GraphQL Function', async () => {
const rwPaths = getRWPaths()

runTransform({
transformPath: path.join(__dirname, 'updateGraphQLFunction.js'),
targetPaths: fg.sync(path.join(rwPaths.api.functions, 'graphql.{js,ts}')),
targetPaths: fg.sync('api/src/functions/graphql.{js,ts}'),
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path'
import fg from 'fast-glob'
import task from 'tasuku'

import getRWPaths from '../../../lib/getRWPaths'
import runTransform from '../../../lib/runTransform'

export const command = 'update-scenarios'
Expand All @@ -25,11 +24,9 @@ export const description =
*/
export const handler = () => {
task('Updating Scenarios', async () => {
const rwPaths = getRWPaths()

runTransform({
transformPath: path.join(__dirname, 'updateScenarios.js'),
targetPaths: fg.sync(`${rwPaths.api.services}/**/*.scenarios.{js,ts}`),
targetPaths: fg.sync('api/src/services/**/*.scenarios.{js,ts}'),
})
})
}
74 changes: 52 additions & 22 deletions packages/codemods/src/lib/runTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,60 @@ export const runTransform = ({
*/
const flags = Object.entries(options).map((key, val) => `--${key}=${val}`)

const { command, cmdArgs } = getExecaArgs()
if (process.env.NODE_ENV === 'test') {
const { command, cmdArgs } = getExecaArgs()

try {
execa.sync(
command,
[
...cmdArgs,
`--parser=${parser}`,
process.env.NODE_ENV === 'test' ? '--babel' : '--no-babel',
'--ignore-pattern=**/node_modules/**',
// Putting flags here lets them override all the defaults.
...flags,
'-t',
transformPath,
...targetPaths,
],
{
stdio: 'inherit',
}
)
} catch (e: any) {
console.error('Transform Error', e.message)
try {
execa.sync(
command,
[
...cmdArgs,
`--parser=${parser}`,
process.env.NODE_ENV === 'test' ? '--babel' : '--no-babel',
'--ignore-pattern=**/node_modules/**',
// Putting flags here lets them override all the defaults.
...flags,
'-t',
transformPath,
...targetPaths,
],
{
stdio: 'inherit',
}
)
} catch (e: any) {
console.error('Transform Error', e.message)

throw new Error('Failed to invoke transform')
}
} else {
try {
const jscodeshiftExecutable = path.resolve(
__dirname,
'../../node_modules/.bin/jscodeshift'
)

execa.sync(
jscodeshiftExecutable,
[
`--parser=${parser}`,
process.env.NODE_ENV === 'test' ? '--babel' : '--no-babel',
'--ignore-pattern=**/node_modules/**',
// Putting flags here lets them override all the defaults.
...flags,
'-t',
transformPath,
...targetPaths,
],
{
stdio: 'inherit',
}
)
} catch (e: any) {
console.error('Transform Error', e.message)

throw new Error('Failed to invoke transform')
throw new Error('Failed to invoke transform')
}
}
}

Expand Down

0 comments on commit 8596821

Please sign in to comment.