Skip to content

Commit 8b10f2b

Browse files
committed
Adds worker sync script
1 parent 2a116ba commit 8b10f2b

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

.github/workflows/release-all-codemods.yml

+2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ jobs:
2424
- run: yarn test
2525
- run: yarn community:validate
2626
- run: yarn community:release-all
27+
- run: yarn worker:sync
2728
env:
2829
CI: true
2930
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3031
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32+
WORKER_PRESHARED_KEY: ${{ secrets.WORKER_PRESHARED_KEY }}

.github/workflows/release-codemods.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ jobs:
2626
- run: yarn test
2727
- run: yarn community:validate
2828
- run: yarn community:release
29+
- run: yarn worker:sync
2930
env:
3031
CI: true
3132
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3233
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
WORKER_PRESHARED_KEY: ${{ secrets.WORKER_PRESHARED_KEY }}

community/@emotion__monorepo/codeshift.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
module.exports = {
22
maintainers: ['danieldelcore'],
3+
targets: [
4+
'@emotion/babel-plugin',
5+
'@emotion/core',
6+
'@emotion/css',
7+
'@emotion/css/create-instance',
8+
'@emotion/eslint-plugin',
9+
'@emotion/jest',
10+
'@emotion/react',
11+
'@emotion/server',
12+
'@emotion/server/create-instance',
13+
'babel-plugin-emotion',
14+
'create-emotion-server',
15+
'create-emotion',
16+
'emotion-server',
17+
'emotion-theming',
18+
'emotion',
19+
'eslint-plugin-emotion',
20+
'jest-emotion',
21+
],
322
transforms: {
423
'11.0.0': require.resolve('./11.0.0/transform'),
524
},

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"community:release": "ts-node scripts/publish.ts ./community .tmp",
3232
"community:release-all": "ts-node scripts/publish-all.ts ./community .tmp",
3333
"community:release-all-dry": "ts-node scripts/publish-all-dry.ts ./community .tmp",
34+
"worker:sync": "ts-node scripts/sync.ts",
3435
"prerelease": "yarn validate && yarn test",
3536
"release": "yarn changeset publish"
3637
},
@@ -48,6 +49,7 @@
4849
"@types/tar": "^4.0.4",
4950
"@typescript-eslint/eslint-plugin": "^5.0.0",
5051
"@typescript-eslint/parser": "^5.0.0",
52+
"axios": "^0.27.2",
5153
"babel-loader": "^8.0.6",
5254
"eslint": "^7.0.0",
5355
"eslint-config-prettier": "^8.0.0",

scripts/sync.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import fs from 'fs-extra';
2+
import junk from 'junk';
3+
import path from 'path';
4+
import axios from 'axios';
5+
6+
import { fetchConfig } from '@codeshift/fetcher';
7+
8+
const COMMUNITY_PATH = path.join(__dirname, '..', 'community');
9+
const CODESHIFT_WORKER_URL = 'http://codeshift.delcore.workers.dev/packages';
10+
11+
interface DocsData {
12+
pkgName: string;
13+
targets: string;
14+
}
15+
16+
async function main() {
17+
console.log('🚚 Syncing community packages with the codeshift worker');
18+
19+
const communityCodemods = fs.readdirSync(COMMUNITY_PATH);
20+
const data: DocsData[] = [];
21+
const directories = communityCodemods.filter(dir => junk.not(dir));
22+
23+
for (const dir of directories) {
24+
const config = await fetchConfig(path.join(COMMUNITY_PATH, dir));
25+
26+
if (!config) {
27+
throw new Error(`Unable to locate config for path: ${dir}`);
28+
}
29+
30+
const pkgName = `@codeshift/mod-${dir.replace('@', '').replace('/', '__')}`;
31+
const rawPkgName = dir.replace('__', '/');
32+
data.push({
33+
pkgName,
34+
targets: rawPkgName + (config.targets ? `, ${config.targets}` : ''),
35+
});
36+
}
37+
38+
const response = await axios.post(
39+
CODESHIFT_WORKER_URL,
40+
JSON.stringify(data),
41+
{
42+
headers: {
43+
'Content-Type': 'application/json',
44+
'X-Custom-PSK': process.env.WORKER_PRESHARED_KEY || '',
45+
},
46+
},
47+
);
48+
49+
console.log(response.data);
50+
}
51+
52+
main().catch(error => {
53+
console.error('Syncing error:', error.message);
54+
process.exit(1);
55+
});

yarn.lock

+22
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,14 @@ aws4@^1.8.0:
22562256
resolved "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
22572257
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
22582258

2259+
axios@^0.27.2:
2260+
version "0.27.2"
2261+
resolved "https://packages.atlassian.com/api/npm/npm-remote/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
2262+
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
2263+
dependencies:
2264+
follow-redirects "^1.14.9"
2265+
form-data "^4.0.0"
2266+
22592267
babel-core@^7.0.0-bridge.0:
22602268
version "7.0.0-bridge.0"
22612269
resolved "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
@@ -3659,6 +3667,11 @@ flow-parser@0.*:
36593667
resolved "https://registry.npmjs.org/flow-parser/-/flow-parser-0.158.0.tgz#d845f167c722babe880110fc3681c44f21823399"
36603668
integrity sha512-0hMsPkBTRrkII/0YiG9ehOxFXy4gOWdk8RSRze5WbfeKAQpL5kC2K4BmumyTfU9o5gr7/llgElF3UpSSrjzQAA==
36613669

3670+
follow-redirects@^1.14.9:
3671+
version "1.15.1"
3672+
resolved "https://packages.atlassian.com/api/npm/npm-remote/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
3673+
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==
3674+
36623675
for-in@^1.0.2:
36633676
version "1.0.2"
36643677
resolved "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -3678,6 +3691,15 @@ form-data@^3.0.0:
36783691
combined-stream "^1.0.8"
36793692
mime-types "^2.1.12"
36803693

3694+
form-data@^4.0.0:
3695+
version "4.0.0"
3696+
resolved "https://packages.atlassian.com/api/npm/npm-remote/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
3697+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
3698+
dependencies:
3699+
asynckit "^0.4.0"
3700+
combined-stream "^1.0.8"
3701+
mime-types "^2.1.12"
3702+
36813703
form-data@~2.3.2:
36823704
version "2.3.3"
36833705
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"

0 commit comments

Comments
 (0)