-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1511f4
commit f69ec38
Showing
23 changed files
with
4,077 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/codemods/styledictionary/4/add-async-await-to-methods/.codemodrc.json
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 @@ | ||
{ | ||
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", | ||
"name": "add-async-await-to-methods", | ||
"version": "1.0.0", | ||
"engine": "jscodeshift", | ||
"private": false, | ||
"arguments": [], | ||
"meta": { | ||
"tags": ["style-dictionary", "4"], | ||
"git": "https://github.com/codemod-com/codemod.git" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/codemods/styledictionary/4/add-async-await-to-methods/.gitignore
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 @@ | ||
node_modules | ||
dist |
9 changes: 9 additions & 0 deletions
9
packages/codemods/styledictionary/4/add-async-await-to-methods/LICENSE
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,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 mohab-sameh | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
157 changes: 157 additions & 0 deletions
157
packages/codemods/styledictionary/4/add-async-await-to-methods/README.md
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,157 @@ | ||
|
||
|
||
|
||
## Example | ||
This codemod turns X into Y. It also does Z. | ||
Note: this is a contrived example. Please modify it. | ||
|
||
### Before | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allTokens); | ||
|
||
sd.cleanAllPlatforms(); | ||
sd.buildAllPlatforms(); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allTokens); | ||
|
||
await sd.cleanAllPlatforms(); | ||
await sd.buildAllPlatforms(); | ||
``` | ||
,This codemod turns X into Y. It also does Z. | ||
Note: this is a contrived example. Please modify it. | ||
|
||
### Before | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.tokens); | ||
|
||
sd.exportPlatform('web'); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.tokens); | ||
|
||
await sd.exportPlatform('web'); | ||
``` | ||
,This codemod turns X into Y. It also does Z. | ||
Note: this is a contrived example. Please modify it. | ||
|
||
### Before | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.properties); | ||
|
||
sd.buildPlatform('ios'); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.properties); | ||
|
||
await sd.buildPlatform('ios'); | ||
``` | ||
,This codemod turns X into Y. It also does Z. | ||
Note: this is a contrived example. Please modify it. | ||
|
||
### Before | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allProperties); | ||
|
||
sd.cleanPlatform('android'); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allProperties); | ||
|
||
await sd.cleanPlatform('android'); | ||
``` | ||
,This codemod turns X into Y. It also does Z. | ||
Note: this is a contrived example. Please modify it. | ||
|
||
### Before | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allTokens); | ||
|
||
sd.registerTransformGroup('custom', []); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allTokens); | ||
|
||
sd.registerTransformGroup('custom', []); | ||
``` | ||
,This codemod turns X into Y. It also does Z. | ||
Note: this is a contrived example. Please modify it. | ||
|
||
### Before | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allProperties); | ||
|
||
sd.registerFormat('customFormat', {}); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allProperties); | ||
|
||
sd.registerFormat('customFormat', {}); | ||
``` | ||
|
7 changes: 7 additions & 0 deletions
7
.../codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture1.input.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,7 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allTokens); | ||
|
||
sd.cleanAllPlatforms(); | ||
sd.buildAllPlatforms(); |
8 changes: 8 additions & 0 deletions
8
...codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture1.output.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,8 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allTokens); | ||
|
||
await sd.cleanAllPlatforms(); | ||
await sd.buildAllPlatforms(); |
6 changes: 6 additions & 0 deletions
6
.../codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture2.input.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,6 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.tokens); | ||
|
||
sd.exportPlatform('web'); |
7 changes: 7 additions & 0 deletions
7
...codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture2.output.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,7 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.tokens); | ||
|
||
await sd.exportPlatform('web'); |
6 changes: 6 additions & 0 deletions
6
.../codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture3.input.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,6 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.properties); | ||
|
||
sd.buildPlatform('ios'); |
7 changes: 7 additions & 0 deletions
7
...codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture3.output.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,7 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.properties); | ||
|
||
await sd.buildPlatform('ios'); |
6 changes: 6 additions & 0 deletions
6
.../codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture4.input.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,6 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allProperties); | ||
|
||
sd.cleanPlatform('android'); |
7 changes: 7 additions & 0 deletions
7
...codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture4.output.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,7 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allProperties); | ||
|
||
await sd.cleanPlatform('android'); |
6 changes: 6 additions & 0 deletions
6
.../codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture5.input.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,6 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allTokens); | ||
|
||
sd.registerTransformGroup('custom', []); |
7 changes: 7 additions & 0 deletions
7
...codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture5.output.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,7 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allTokens); | ||
|
||
sd.registerTransformGroup('custom', []); |
6 changes: 6 additions & 0 deletions
6
.../codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture6.input.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,6 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
console.log(sd.allProperties); | ||
|
||
sd.registerFormat('customFormat', {}); |
7 changes: 7 additions & 0 deletions
7
...codemods/styledictionary/4/add-async-await-to-methods/__testfixtures__/fixture6.output.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,7 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
|
||
const sd = new StyleDictionary({ source: ['tokens.json'], platforms: {} }); | ||
await sd.hasInitialized; | ||
console.log(sd.allProperties); | ||
|
||
sd.registerFormat('customFormat', {}); |
56 changes: 56 additions & 0 deletions
56
packages/codemods/styledictionary/4/add-async-await-to-methods/cdmd_dist/index.cjs
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,56 @@ | ||
/*! @license | ||
The MIT License (MIT) | ||
Copyright (c) 2024 mohab-sameh | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "default", { | ||
enumerable: true, | ||
get: () => transformer, | ||
}); | ||
function transformer(fileInfo, api) { | ||
const j = api.jscodeshift; | ||
const asyncMethods = [ | ||
"cleanAllPlatforms", | ||
"buildAllPlatforms", | ||
"extend", | ||
"exportPlatform", | ||
"getPlatform", | ||
"buildPlatform", | ||
"cleanPlatform", | ||
]; | ||
const root = j(fileInfo.source); | ||
root.find(j.FunctionDeclaration).forEach((path) => addAsyncIfNeeded(path, j)); | ||
root.find(j.FunctionExpression).forEach((path) => addAsyncIfNeeded(path, j)); | ||
root | ||
.find(j.ArrowFunctionExpression) | ||
.forEach((path) => addAsyncIfNeeded(path, j)); | ||
asyncMethods.forEach((method) => { | ||
root | ||
.find(j.CallExpression, { callee: { property: { name: method } } }) | ||
.forEach((path) => { | ||
if (!j.AwaitExpression.check(path.parent.node)) { | ||
j(path).replaceWith(j.awaitExpression(path.node)); | ||
} | ||
}); | ||
}); | ||
return root.toSource(); | ||
function addAsyncIfNeeded(path, j) { | ||
const containsAsyncMethod = j(path) | ||
.find(j.CallExpression) | ||
.some((callPath) => | ||
asyncMethods.includes(callPath.node.callee.property?.name), | ||
); | ||
if (containsAsyncMethod && !path.node.async) { | ||
path.node.async = true; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/codemods/styledictionary/4/add-async-await-to-methods/package.json
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,19 @@ | ||
{ | ||
"name": "add-async-await-to-methods", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "20.9.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^1.0.1", | ||
"@codemod.com/codemod-utils": "*", | ||
"jscodeshift": "^0.15.1", | ||
"@types/jscodeshift": "^0.11.10" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"test:watch": "vitest watch" | ||
}, | ||
"files": ["README.md", ".codemodrc.json", "/dist/index.cjs"], | ||
"type": "module", | ||
"author": "mohab-sameh" | ||
} |
Oops, something went wrong.