Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds React Export Option #335

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ export default [
'no-await-in-loop': 'off',
'require-atomic-updates': 'off',
}
}
},
{ ignores: ['dist', 'src/templates/react/**'] }
];
151 changes: 118 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@playcanvas/eslint-config": "^2.0.8",
"@playcanvas/pcui": "^4.6.0",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
Expand All @@ -45,8 +46,9 @@
"globals": "^15.13.0",
"i18next": "^24.1.0",
"i18next-browser-languagedetector": "^8.0.2",
"jest": "^29.7.0",
"ignore": "^6.0.2",
"jszip": "^3.10.1",
"jest": "^29.7.0",
marklundin marked this conversation as resolved.
Show resolved Hide resolved
"playcanvas": "^2.3.3",
"postcss": "^8.4.49",
"rollup": "^4.28.1",
Expand Down
File renamed without changes.
86 changes: 86 additions & 0 deletions plugins/zip.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import JSZip from 'jszip';
import { promises as fs } from 'fs';
import path from 'path';
import ignore from 'ignore';

export default function zipPlugin(options = {}) {
const {
input = [], // array of files/directories to zip
output = 'output.zip', // output zip file name
compression = 'DEFLATE'
} = options;

return {
name: 'rollup-plugin-zip',
async writeBundle() {
const zip = new JSZip();

// Load .gitignore rules if the file exists
const ig = ignore().add([
'package-lock.json',
'*.ply'
]);

// Add .gitignore rules if the file exists
try {
const gitignore = await fs.readFile('.gitignore', 'utf8');
ig.add(gitignore);
} catch (err) {
console.log('No .gitignore found, using default ignores only');
}

// Helper to recursively add files from a directory
async function addDirectory(dirPath, zipRoot) {
const files = await fs.readdir(dirPath);
for (const file of files) {
const filePath = path.join(dirPath, file);
const stat = await fs.stat(filePath);

// Get relative path for gitignore checking
const relativePath = path.relative(process.cwd(), filePath);

// Skip if file is ignored by gitignore
if (ig.ignores(relativePath)) {
continue;
}

if (stat.isDirectory()) {
await addDirectory(filePath, zipRoot.folder(file));
} else {
const content = await fs.readFile(filePath);
zipRoot.file(file, content);
}
}
}

// Add all input files/directories
for (const inputPath of input) {
const stat = await fs.stat(inputPath);
if (stat.isDirectory()) {
await addDirectory(inputPath, zip);
} else {
const relativePath = path.relative(process.cwd(), inputPath);
if (!ig.ignores(relativePath)) {
const content = await fs.readFile(inputPath);
zip.file(path.basename(inputPath), content);
}
}
}

// Create output directory if it doesn't exist
const outputDir = path.dirname(output);
await fs.mkdir(outputDir, { recursive: true });

// Generate and write the zip file
const content = await zip.generateAsync({
type: 'nodebuffer',
compression,
compressionOptions: {
level: 9
}
});

await fs.writeFile(output, content);
}
};
}
Loading
Loading