-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(almin): Almin 0.15.x → 0.18.x (#5)
Add migration scripts for `executor` to `execute` ## Blocker Wait to release almin 0.18 - almin/almin#358
- Loading branch information
Showing
14 changed files
with
2,871 additions
and
1,354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
scripts/babel-codemod/__testfixtures__/executor-to-execute/does-not-change-executor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const expression = useCase => useCase.execute("A"); | ||
context.useCase(new MyUseCaseA()).executor(expression); |
4 changes: 4 additions & 0 deletions
4
scripts/babel-codemod/__testfixtures__/executor-to-execute/evincive-return-execute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const value: string = "asasea"; | ||
context.useCase(createMyUseCaseA()).executor(useCase => { | ||
return useCase.execute(value) | ||
}); |
1 change: 1 addition & 0 deletions
1
scripts/babel-codemod/__testfixtures__/executor-to-execute/no-arguments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute()); |
3 changes: 3 additions & 0 deletions
3
scripts/babel-codemod/__testfixtures__/executor-to-execute/return-function-expression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
context.useCase(createMyUseCaseA()).executor(function (useCase) { | ||
return useCase.execute(1, 2, { key: "3" }) | ||
}); |
13 changes: 13 additions & 0 deletions
13
scripts/babel-codemod/__testfixtures__/executor-to-execute/simple.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { UseCase, Context } from "almin"; | ||
|
||
class MyUseCaseA extends UseCase { | ||
execute(_a) { | ||
console.log(_a) | ||
} | ||
} | ||
|
||
const context = new Context({ | ||
store: createStore({ name: "test" }) | ||
}); | ||
|
||
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute("A")); |
12 changes: 12 additions & 0 deletions
12
scripts/babel-codemod/__testfixtures__/executor-to-execute/simple.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { UseCase, Context } from "almin"; | ||
|
||
class MyUseCaseA extends UseCase { | ||
execute(_a: string) { | ||
} | ||
} | ||
|
||
const context = new Context({ | ||
store: createStore({ name: "test" }) | ||
}); | ||
|
||
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute("A")); |
103 changes: 103 additions & 0 deletions
103
scripts/babel-codemod/__tests__/__snapshots__/executor-to-execute.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`executor-to-execute does-not-change-executor.ts 1`] = ` | ||
"const expression = useCase => useCase.execute(\\"A\\"); | ||
context.useCase(new MyUseCaseA()).executor(expression); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
const expression = useCase => useCase.execute(\\"A\\"); | ||
context.useCase(new MyUseCaseA()).executor(expression); | ||
" | ||
`; | ||
|
||
exports[`executor-to-execute evincive-return-execute.ts 1`] = ` | ||
"const value: string = \\"asasea\\"; | ||
context.useCase(createMyUseCaseA()).executor(useCase => { | ||
return useCase.execute(value) | ||
}); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
const value: string = \\"asasea\\"; | ||
context.useCase(createMyUseCaseA()).execute(value); | ||
" | ||
`; | ||
|
||
exports[`executor-to-execute no-arguments.ts 1`] = ` | ||
"context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute()); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
context.useCase(new MyUseCaseA()).execute(); | ||
" | ||
`; | ||
|
||
exports[`executor-to-execute return-function-expression.ts 1`] = ` | ||
"context.useCase(createMyUseCaseA()).executor(function (useCase) { | ||
return useCase.execute(1, 2, { key: \\"3\\" }) | ||
}); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
context.useCase(createMyUseCaseA()).execute(1, 2, { key: \\"3\\" }); | ||
" | ||
`; | ||
|
||
exports[`executor-to-execute simple.js 1`] = ` | ||
"import { UseCase, Context } from \\"almin\\"; | ||
class MyUseCaseA extends UseCase { | ||
execute(_a) { | ||
console.log(_a) | ||
} | ||
} | ||
const context = new Context({ | ||
store: createStore({ name: \\"test\\" }) | ||
}); | ||
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute(\\"A\\")); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
import { UseCase, Context } from \\"almin\\"; | ||
class MyUseCaseA extends UseCase { | ||
execute(_a) { | ||
console.log(_a) | ||
} | ||
} | ||
const context = new Context({ | ||
store: createStore({ name: \\"test\\" }) | ||
}); | ||
context.useCase(new MyUseCaseA()).execute(\\"A\\"); | ||
" | ||
`; | ||
|
||
exports[`executor-to-execute simple.ts 1`] = ` | ||
"import { UseCase, Context } from \\"almin\\"; | ||
class MyUseCaseA extends UseCase { | ||
execute(_a: string) { | ||
} | ||
} | ||
const context = new Context({ | ||
store: createStore({ name: \\"test\\" }) | ||
}); | ||
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute(\\"A\\")); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
import { UseCase, Context } from \\"almin\\"; | ||
class MyUseCaseA extends UseCase { | ||
execute(_a: string) { | ||
} | ||
} | ||
const context = new Context({ | ||
store: createStore({ name: \\"test\\" }) | ||
}); | ||
context.useCase(new MyUseCaseA()).execute(\\"A\\"); | ||
" | ||
`; |
47 changes: 47 additions & 0 deletions
47
scripts/babel-codemod/__tests__/executor-to-execute.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
const childProcess = require('child_process'); | ||
const { promisify } = require('util'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const exec = promisify(childProcess.exec) | ||
const codemod = require.resolve(".bin/codemod"); | ||
|
||
const run = (pluginFilePath, filePath) => { | ||
if (!fs.existsSync(pluginFilePath)) { | ||
return Promise.reject(new Error(`Not exist ${pluginFilePath}`)); | ||
} | ||
if (!fs.existsSync(filePath)) { | ||
return Promise.reject(new Error(`Not exist ${filePath}`)); | ||
} | ||
// TODO: https://github.com/square/babel-codemod/issues/13 | ||
return exec(`cat "${filePath}" | ${codemod} --plugin "${pluginFilePath}" --stdio`).then(result => { | ||
// TODO: IT IS DEBUG HACK | ||
if (result.stderr) { | ||
console.log(result.stderr); | ||
} | ||
return result.stdout; | ||
}) | ||
}; | ||
|
||
const testFile = (testName) => { | ||
it(testName, async () => { | ||
const filePath = path.join(__dirname, `../__testfixtures__/executor-to-execute/${testName}`); | ||
const inputContent = fs.readFileSync(filePath, "utf-8"); | ||
const stdout = await run( | ||
path.join(__dirname, "../executor-to-execute.js"), | ||
filePath, | ||
); | ||
expect(`${inputContent} | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
${stdout}`).toMatchSnapshot(); | ||
}); | ||
}; | ||
jest.setTimeout(20000); | ||
describe("executor-to-execute", () => { | ||
testFile("simple.js"); | ||
testFile("simple.ts"); | ||
testFile("evincive-return-execute.ts"); | ||
testFile("return-function-expression.ts"); | ||
testFile("no-arguments.ts"); | ||
testFile("does-not-change-executor.ts"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
module.exports = function(babel) { | ||
const { types: t } = babel; | ||
return { | ||
visitor: { | ||
CallExpression(path) { | ||
const isExecuteCallExpression = (path) => { | ||
return path.node.callee && | ||
path.node.callee.property && | ||
path.node.callee.property.name === "execute" && | ||
path.node["arguments"] !== undefined | ||
}; | ||
const findParentExecutorCalleePath = (path) => { | ||
return path.findParent((path) => { | ||
return path.node.type === "CallExpression" && | ||
path.node.callee && | ||
path.node.callee.type === "MemberExpression" && | ||
path.node.callee.property && | ||
path.node.callee.property.type === "Identifier" && | ||
path.node.callee.property.name === "executor" | ||
}); | ||
}; | ||
if (!isExecuteCallExpression(path)) { | ||
return; | ||
} | ||
const executorPath = findParentExecutorCalleePath(path); | ||
if (!executorPath) { | ||
return; | ||
} | ||
// [object].executor(useCase => useCase.execute(args)); | ||
// => | ||
// [object].execute(args) | ||
const executeArgs = path.node["arguments"]; | ||
executorPath.node.callee.property.name = "execute"; | ||
executorPath.node["arguments"] = executeArgs | ||
} | ||
} | ||
}; | ||
}; |
Oops, something went wrong.