Skip to content

Commit cad8342

Browse files
authored
chore(build): copy plugin to commonjs (rnmapbox#3782)
1 parent bbd898e commit cad8342

File tree

6 files changed

+168
-56
lines changed

6 files changed

+168
-56
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module.exports = {
9191
'./tsconfig.json',
9292
'./example/tsconfig.json',
9393
'./scripts/tsconfig.json',
94+
'./plugin/tsconfig.eslint.json',
9495
'./plugin/src/__tests__/tsconfig.eslint.json',
9596
],
9697
},

bob.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
source: 'src',
3+
output: 'lib',
4+
targets: [
5+
'commonjs',
6+
'module',
7+
'typescript',
8+
[
9+
'custom',
10+
{
11+
script: 'build:copy-plugin',
12+
},
13+
],
14+
],
15+
};

package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"build:examples.json": "cd example; jest __tests__/dumpExamplesJson.ts",
5454
"lint:plugin": "yarn eslint plugin/src/*",
5555
"build": "yarn bob build",
56-
"prepare": "yarn bob build"
56+
"prepare": "yarn bob build",
57+
"build:copy-plugin": "yarn ts-node plugin/copy-plugin.ts"
5758
},
5859
"peerDependencies": {
5960
"expo": ">=47.0.0",
@@ -121,9 +122,9 @@
121122
"react-docgen": "rnmapbox/react-docgen#rnmapbox-dist-react-docgen-v6",
122123
"to-fast-properties": "3.0.1",
123124
"react-native": "0.76.7",
124-
"react-native-builder-bob": "^0.36.0",
125+
"react-native-builder-bob": "^0.37.0",
125126
"react-test-renderer": "18.3.1",
126-
"ts-node": "10.9.1",
127+
"ts-node": "10.9.2",
127128
"typescript": "5.1.3",
128129
"@mdx-js/mdx": "^3.0.0",
129130
"@types/react": "^18.3.1",
@@ -140,15 +141,6 @@
140141
"lint-staged": {
141142
"*.{js,jsx,ts,tsx}": "eslint --fix"
142143
},
143-
"react-native-builder-bob": {
144-
"source": "src",
145-
"output": "lib",
146-
"targets": [
147-
"commonjs",
148-
"module",
149-
"typescript"
150-
]
151-
},
152144
"eslintIgnore": [
153145
"node_modules/",
154146
"lib/"

plugin/copy-plugin.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
const rootDir = path.resolve(__dirname, '..');
5+
const destDir = path.resolve(rootDir, 'lib/commonjs');
6+
const pluginDir = path.resolve(rootDir, 'plugin');
7+
const appPluginFile = path.resolve(rootDir, 'app.plugin.js');
8+
9+
function copyFileSync(source: string, target: string) {
10+
let targetFile = target;
11+
12+
// If target is a directory, a new file with the same name will be created
13+
if (fs.existsSync(target)) {
14+
if (fs.lstatSync(target).isDirectory()) {
15+
targetFile = path.join(target, path.basename(source));
16+
}
17+
}
18+
19+
fs.writeFileSync(targetFile, fs.readFileSync(source));
20+
}
21+
22+
function copyFolderRecursiveSync(source: string, target: string) {
23+
let files = [];
24+
25+
// Check if folder needs to be created or integrated
26+
const targetFolder = path.join(target, path.basename(source));
27+
if (!fs.existsSync(targetFolder)) {
28+
fs.mkdirSync(targetFolder);
29+
}
30+
31+
// Copy
32+
if (fs.lstatSync(source).isDirectory()) {
33+
files = fs.readdirSync(source);
34+
files.forEach((file) => {
35+
const curSource = path.join(source, file);
36+
if (fs.lstatSync(curSource).isDirectory()) {
37+
copyFolderRecursiveSync(curSource, targetFolder);
38+
} else {
39+
copyFileSync(curSource, targetFolder);
40+
}
41+
});
42+
}
43+
}
44+
45+
// Ensure destination directory exists
46+
if (!fs.existsSync(destDir)) {
47+
fs.mkdirSync(destDir, { recursive: true });
48+
}
49+
50+
// Copy app.plugin.js
51+
copyFileSync(appPluginFile, destDir);
52+
53+
// Copy plugin folder
54+
copyFolderRecursiveSync(pluginDir, destDir);
55+
56+
console.log('Files copied successfully.');

plugin/tsconfig.eslint.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
},
4+
"include": ["./copy-plugin.ts"],
5+
}

0 commit comments

Comments
 (0)