Skip to content

Commit

Permalink
try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed May 15, 2024
1 parent 300523e commit b7ab5e0
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"copy:icons": "cp -r ./node_modules/@fuel-ui/icons/dist/icons/sprite.svg ./public/icons",
"deps:update": "updates -gu",
"dev": "./scripts/dev.sh",
"docs:clean": "sh ./scripts/clean-build-files.sh",
"docs:clean": "node ./scripts/clean-build-files.mjs",
"docs:sync": "sh ./scripts/sync-repos.sh",
"docs:update": "node scripts/update-nightly/index.mjs",
"docs:update:nightly": "node scripts/update-nightly/index.mjs --nightly",
Expand Down
113 changes: 113 additions & 0 deletions scripts/clean-build-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import fs from 'fs';
import path from 'path';

// List of directories to delete unused files from
const targetDirs = [
'./docs/sway',
'./docs/nightly/sway',
'./docs/builds/sway',
'./docs/nightly/builds/sway',
'./docs/fuels-rs',
'./docs/nightly/fuels-rs',
'./docs/fuels-ts',
'./docs/nightly/fuels-ts',
'./docs/fuels-wallet',
'./docs/nightly/fuels-wallet',
'./docs/fuel-graphql-docs',
'./docs/nightly/fuel-graphql-docs',
// './docs/fuel-core',
];

// Exclusions for each type of directory
const exclusions = {
sway: [
'sway/Cargo.toml',
'sway/forc-pkg',
'sway/sway-lib-std',
'sway/docs/book/src',
'sway/examples',
'sway/master/book',
'sway/test/src/sdk-harness/test_projects/run_external_proxy',
'sway/test/src/sdk-harness/test_projects/run_external_target',
],
fuels_rs: [
'fuels-rs/Cargo.toml',
'fuels-rs/docs',
'fuels-rs/examples',
'fuels-rs/packages',
],
fuels_ts: [
'fuels-ts/apps',
'fuels-ts/packages',
'fuels-ts/package.json',
'fuels-ts/demo-wallet-sdk-react',
],
fuels_wallet: ['fuels-wallet/package.json', 'fuels-wallet/packages'],
// fuel_core: ['fuel-core/deployment/scripts/chainspec', 'fuel-core/Cargo.toml'],
fuel_graphql_docs: [
'fuel-graphql-docs/docs',
'fuel-graphql-docs/examples',
'fuel-graphql-docs/src',
],
};

function main() {
for (const targetDir of targetDirs) {
if (!fs.existsSync(targetDir)) {
// console.log(`Directory ${targetDir} does not exist!`);
const basePath = process.cwd();
// console.log(`Current directory: ${basePath}`);
return;
}
// Change to the target directory
process.chdir(targetDir);
const dirBasename = path.basename(targetDir).replace(/-/g, '_');
const currentExclusions = exclusions[dirBasename];
cleanupFiles(currentExclusions, '.');
// console.log(`Cleanup done for ${targetDir}!`);
// Return to the original directory
let x = '../..';
if (process.cwd().includes('nightly')) {
x = `${x}/..`;
}
if (process.cwd().includes('builds')) {
x = `${x}/..`;
}
process.chdir(path.resolve(process.cwd(), x));
}
}

function cleanupFiles(currentExclusions, dirPath) {
// Read all items in directory
fs.readdirSync(dirPath).forEach((item) => {
let shouldDelete = true;
const basePath = process.cwd().split('/docs/')[1];
const thisFilePath = path
.join(basePath, dirPath, item)
.replace('builds/', '')
.replace('nightly/', '');
const subFilePath = `./${thisFilePath.split('/').slice(1).join('/')}`;

if (currentExclusions?.includes(thisFilePath)) {
shouldDelete = false;
// console.log('Excluding: ', thisFilePath);
} else if (
fs.existsSync(subFilePath) &&
fs.lstatSync(subFilePath).isDirectory()
) {
shouldDelete = false;
cleanupFiles(currentExclusions, subFilePath);
}

deleteFolder(shouldDelete, subFilePath);
});
}

function deleteFolder(shouldDelete, subFilePath) {
if (shouldDelete) {
// console.log('DELETING: ', subFilePath);
fs.rmSync(subFilePath, { recursive: true, force: true });
}
}

main();
57 changes: 0 additions & 57 deletions scripts/clean-build-files.sh

This file was deleted.

0 comments on commit b7ab5e0

Please sign in to comment.