Skip to content

Commit

Permalink
chore(build): copy plugin to commonjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Feb 19, 2025
1 parent bbd898e commit 94d4d69
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 57 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module.exports = {
'./tsconfig.json',
'./example/tsconfig.json',
'./scripts/tsconfig.json',
'./plugin/tsconfig.eslint.json',
'./plugin/src/__tests__/tsconfig.eslint.json',
],
},
Expand Down
15 changes: 15 additions & 0 deletions bob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
source: 'src',
output: 'lib',
targets: [
'commonjs',
'module',
'typescript',
[
'custom',
{
script: 'build:copy-plugin',
},
],
],
};
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"build:examples.json": "cd example; jest __tests__/dumpExamplesJson.ts",
"lint:plugin": "yarn eslint plugin/src/*",
"build": "yarn bob build",
"prepare": "yarn bob build"
"prepare": "yarn bob build",
"build:copy-plugin": "yarn ts-node plugin/copy-plugin.ts"
},
"peerDependencies": {
"expo": ">=47.0.0",
Expand Down Expand Up @@ -121,9 +122,9 @@
"react-docgen": "rnmapbox/react-docgen#rnmapbox-dist-react-docgen-v6",
"to-fast-properties": "3.0.1",
"react-native": "0.76.7",
"react-native-builder-bob": "^0.36.0",
"react-native-builder-bob": "^0.37.0",
"react-test-renderer": "18.3.1",
"ts-node": "10.9.1",
"ts-node": "10.9.2",
"typescript": "5.1.3",
"@mdx-js/mdx": "^3.0.0",
"@types/react": "^18.3.1",
Expand All @@ -140,15 +141,6 @@
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --fix"
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
"commonjs",
"module",
"typescript"
]
},
"eslintIgnore": [
"node_modules/",
"lib/"
Expand Down
56 changes: 56 additions & 0 deletions plugin/copy-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as fs from 'fs';
import * as path from 'path';

const rootDir = path.resolve(__dirname, '..');
const destDir = path.resolve(rootDir, 'lib/commonjs');
const pluginDir = path.resolve(rootDir, 'plugin');
const appPluginFile = path.resolve(rootDir, 'app.plugin.js');

function copyFileSync(source: string, target: string) {
let targetFile = target;

// If target is a directory, a new file with the same name will be created
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source));
}
}

fs.writeFileSync(targetFile, fs.readFileSync(source));
}

function copyFolderRecursiveSync(source: string, target: string) {
let files = [];

// Check if folder needs to be created or integrated
const targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder);
}

// Copy
if (fs.lstatSync(source).isDirectory()) {
files = fs.readdirSync(source);
files.forEach((file) => {
const curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder);
} else {
copyFileSync(curSource, targetFolder);
}
});
}
}

// Ensure destination directory exists
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}

// Copy app.plugin.js
copyFileSync(appPluginFile, destDir);

// Copy plugin folder
copyFolderRecursiveSync(pluginDir, destDir);

console.log('Files copied successfully.');
5 changes: 5 additions & 0 deletions plugin/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
},
"include": ["./copy-plugin.ts"],
}
2 changes: 1 addition & 1 deletion plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"outDir": "build",
"rootDir": "src"
},
"include": ["./src"],
"include": ["./src", "./copy-plugin.ts"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
}
Loading

0 comments on commit 94d4d69

Please # to comment.