Skip to content

Commit 1f01a52

Browse files
committed
[forgive] Add build scripts
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 8f3df2d commit 1f01a52

File tree

5 files changed

+149
-9
lines changed

5 files changed

+149
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/node_modules
2+
client
3+
server
4+
scripts

compiler/packages/react-forgive/package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@
3535
]
3636
},
3737
"scripts": {
38-
"compile": "yarn run esbuild-base -- --sourcemap",
38+
"build": "yarn run compile",
39+
"compile": "rimraf dist && concurrently -n server,client \"scripts/build.mjs -t server\" \"scripts/build.mjs -t client\"",
3940
"dev": "yarn run package && yarn run install-ext",
40-
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node",
41-
"install-ext": "code --install-extension vscode-react-compiler-0.0.1.vsix",
42-
"lint": "eslint src --ext ts",
43-
"package": "vsce package",
41+
"install-ext": "code --install-extension react-forgive-0.0.0.vsix",
42+
"lint": "echo 'no tests'",
43+
"package": "rm -f react-forgive-0.0.0.vsix && vsce package --yarn",
4444
"postinstall": "cd client && yarn install && cd ../server && yarn install && cd ..",
4545
"pretest": "yarn run compile && yarn run lint",
4646
"test": "echo 'no tests'",
47-
"test-compile": "tsc -p ./",
48-
"vscode:prepublish": "yarn run esbuild-base -- --minify",
49-
"watch": "yarn run esbuild-base -- --sourcemap --watch"
47+
"vscode:prepublish": "yarn run compile",
48+
"watch": "scripts/build.mjs --watch"
5049
},
5150
"devDependencies": {
5251
"@eslint/js": "^9.13.0",
5352
"@types/node": "^20",
5453
"eslint": "^9.13.0",
55-
"typescript-eslint": "^8.16.0"
54+
"typescript-eslint": "^8.16.0",
55+
"yargs": "^17.7.2"
5656
}
5757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright (c) Meta Platforms, Inc. and affiliates.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
import * as esbuild from 'esbuild';
11+
import yargs from 'yargs';
12+
import * as Server from './server.mjs';
13+
import * as Client from './client.mjs';
14+
import path from 'path';
15+
import {fileURLToPath} from 'url';
16+
17+
const IS_DEV = process.env.NODE_ENV === 'development';
18+
const __filename = fileURLToPath(import.meta.url);
19+
const __dirname = path.dirname(__filename);
20+
21+
const argv = yargs(process.argv.slice(2))
22+
.choices('t', ['client', 'server'])
23+
.options('w', {
24+
alias: 'watch',
25+
default: false,
26+
type: 'boolean',
27+
})
28+
.parse();
29+
30+
async function main() {
31+
if (argv.w) {
32+
const serverCtx = await esbuild.context(Server.config);
33+
const clientCtx = await esbuild.context(Client.config);
34+
await Promise.all([serverCtx.watch(), clientCtx.watch()]);
35+
console.log('watching for changes...');
36+
} else {
37+
switch (argv.t) {
38+
case 'server': {
39+
await esbuild.build({
40+
sourcemap: IS_DEV,
41+
minify: IS_DEV === false,
42+
...Server.config,
43+
});
44+
break;
45+
}
46+
case 'client': {
47+
await esbuild.build({
48+
sourcemap: IS_DEV,
49+
minify: IS_DEV === false,
50+
...Client.config,
51+
});
52+
break;
53+
}
54+
}
55+
}
56+
}
57+
58+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import path from 'path';
9+
import {fileURLToPath} from 'url';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
14+
export const entryPoint = path.join(__dirname, '../client/src/extension.ts');
15+
export const outfile = path.join(__dirname, '../dist/extension.js');
16+
export const config = {
17+
entryPoints: [entryPoint],
18+
outfile,
19+
bundle: true,
20+
external: ['vscode'],
21+
format: 'cjs',
22+
platform: 'node',
23+
banner: {
24+
js: `/**
25+
* Copyright (c) Meta Platforms, Inc. and affiliates.
26+
*
27+
* This source code is licensed under the MIT license found in the
28+
* LICENSE file in the root directory of this source tree.
29+
*
30+
* @lightSyntaxTransform
31+
* @noflow
32+
* @nolint
33+
* @preventMunge
34+
* @preserve-invariant-messages
35+
*/
36+
37+
`,
38+
},
39+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import path from 'path';
9+
import {fileURLToPath} from 'url';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
14+
export const entryPoint = path.join(__dirname, '../server/src/index.ts');
15+
export const outfile = path.join(__dirname, '../dist/extension.js');
16+
export const config = {
17+
entryPoints: [entryPoint],
18+
outfile,
19+
bundle: true,
20+
external: ['vscode'],
21+
format: 'cjs',
22+
platform: 'node',
23+
banner: {
24+
js: `/**
25+
* Copyright (c) Meta Platforms, Inc. and affiliates.
26+
*
27+
* This source code is licensed under the MIT license found in the
28+
* LICENSE file in the root directory of this source tree.
29+
*
30+
* @lightSyntaxTransform
31+
* @noflow
32+
* @nolint
33+
* @preventMunge
34+
* @preserve-invariant-messages
35+
*/
36+
37+
`,
38+
},
39+
};

0 commit comments

Comments
 (0)