Skip to content

Commit 81c934c

Browse files
authored
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
1 parent dbd1895 commit 81c934c

File tree

14 files changed

+2871
-1354
lines changed

14 files changed

+2871
-1354
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,54 @@ Ensure you have a backup of your source code or commit the latest changes before
3535

3636
## Migrations
3737

38+
### 0.17.x → 0.18.x
39+
40+
#### How to migrate?
41+
42+
Run following command and select `0.17.x → 0.18.x`
43+
44+
```
45+
$ almin-migration-tools
46+
```
47+
48+
49+
#### What is changed?
50+
51+
`executor()` is deprecated.
52+
You should use `UseCaseExecutor#execute` instead of `UseCaseExecutor#executor`.
53+
54+
- [Deprecate `executor()` · Issue #356 · almin/almin](https://github.com/almin/almin/issues/356)
55+
56+
Before: `executor()`
57+
58+
```ts
59+
import { UseCase, Context } from "almin";
60+
class MyUseCaseA extends UseCase {
61+
execute(_a: string) {}
62+
}
63+
const context = new Context({
64+
store: createStore({ name: "test" })
65+
});
66+
67+
// executor
68+
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute("A"));
69+
```
70+
71+
After: `execute()`
72+
73+
```ts
74+
import { UseCase, Context } from "almin";
75+
class MyUseCaseA extends UseCase {
76+
execute(_a: string) {}
77+
}
78+
const context = new Context({
79+
store: createStore({ name: "test" })
80+
});
81+
82+
//execute
83+
context.useCase(new MyUseCaseA()).execute("A");
84+
```
85+
3886
### 0.13.x → 0.15.x
3987

4088
#### How to migrate?

almin-migration-tools.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ updateNotifier({ pkg: cli.pkg }).notify();
4949
const migrator = new CodeMigrator({
5050
moduleName: "almin",
5151
migrationList: migrationVersions,
52-
binCreator: () => {
52+
binCreator: ({ script, filePathList }) => {
53+
if (script.type === "babel-codemod") {
54+
const binArgs = cli.flags.dryRun ? ["--dry"] : [];
55+
return {
56+
binPath: require.resolve(".bin/codemod"),
57+
binArgs: binArgs.concat(["-p", script.filePath]).concat(filePathList)
58+
};
59+
}
5360
const binArgs = cli.flags.dryRun ? ["--dry"] : [];
5461
return {
5562
binPath: require.resolve(".bin/jscodeshift"),
56-
binArgs
63+
binArgs: binArgs.concat(["-t", script.filePath]).concat(filePathList)
5764
};
5865
}
5966
});

migrations.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ module.exports = {
1414
{
1515
name: "store-get-state-return-object-to-flat",
1616
filePath: require.resolve("./scripts/store-get-state-return-object-to-flat"),
17-
}, {
17+
},
18+
{
1819
name: "store-group-arguments",
1920
filePath: require.resolve("./scripts/store-group-arguments"),
21+
},
22+
{
23+
name: "executor-to-execute",
24+
filePath: require.resolve("./scripts/babel-codemod/executor-to-execute.js"),
25+
type: "babel-codemod"
2026
}
2127
],
2228
"versions": [
@@ -35,6 +41,20 @@ module.exports = {
3541
"scripts": [
3642
"remove-ChangedPayload"
3743
]
44+
},
45+
{
46+
"version": "0.16.0",
47+
"scripts": []
48+
},
49+
{
50+
"version": "0.17.0",
51+
"scripts": []
52+
},
53+
{
54+
"version": "0.18.0",
55+
"scripts": [
56+
"executor-to-execute"
57+
]
3858
}
3959
]
4060
};

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@
4545
},
4646
"homepage": "https://github.com/almin/migration-tools",
4747
"dependencies": {
48-
"code-migrator": "^1.3.2",
49-
"jscodeshift": "^0.4.0",
50-
"meow": "^4.0.0",
48+
"babel-codemod": "^2.0.6",
49+
"code-migrator": "^2.0.0",
50+
"jscodeshift": "^0.5.1",
51+
"meow": "^5.0.0",
5152
"npm-run-path": "^2.0.2",
52-
"update-notifier": "^2.3.0"
53+
"update-notifier": "^2.5.0"
5354
},
5455
"devDependencies": {
5556
"husky": "^0.14.3",
56-
"jest": "^22.1.4",
57-
"lint-staged": "^6.0.1",
58-
"prettier": "^1.10.2"
57+
"jest": "^23.5.0",
58+
"lint-staged": "^7.2.2",
59+
"prettier": "^1.14.2"
5960
}
6061
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const expression = useCase => useCase.execute("A");
2+
context.useCase(new MyUseCaseA()).executor(expression);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const value: string = "asasea";
2+
context.useCase(createMyUseCaseA()).executor(useCase => {
3+
return useCase.execute(value)
4+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
context.useCase(createMyUseCaseA()).executor(function (useCase) {
2+
return useCase.execute(1, 2, { key: "3" })
3+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { UseCase, Context } from "almin";
2+
3+
class MyUseCaseA extends UseCase {
4+
execute(_a) {
5+
console.log(_a)
6+
}
7+
}
8+
9+
const context = new Context({
10+
store: createStore({ name: "test" })
11+
});
12+
13+
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute("A"));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { UseCase, Context } from "almin";
2+
3+
class MyUseCaseA extends UseCase {
4+
execute(_a: string) {
5+
}
6+
}
7+
8+
const context = new Context({
9+
store: createStore({ name: "test" })
10+
});
11+
12+
context.useCase(new MyUseCaseA()).executor(useCase => useCase.execute("A"));

0 commit comments

Comments
 (0)