simple-icons/scripts/build/clean.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-03-24 20:38:18 +03:00
#!/usr/bin/env node
2024-03-19 15:35:59 +03:00
/**
2024-06-06 15:40:35 +03:00
* @file
2024-03-19 15:35:59 +03:00
* Clean files built by the build process.
*/
2024-03-24 20:38:18 +03:00
import fs from 'node:fs/promises';
2024-03-19 15:35:59 +03:00
import path from 'node:path';
2024-03-24 20:38:18 +03:00
import process from 'node:process';
import {getDirnameFromImportMeta} from '../../sdk.mjs';
2024-03-19 15:35:59 +03:00
const __dirname = getDirnameFromImportMeta(import.meta.url);
const rootDirectory = path.resolve(__dirname, '..', '..');
const files = ['index.js', 'index.mjs', 'index.d.ts', 'sdk.js'];
/**
* Check if a file exists.
* @param {string} fpath File path to check.
* @returns {Promise<boolean>} True if the file exists, false otherwise.
*/
2024-09-17 04:46:48 +03:00
const fileExists = async (fpath) => {
try {
await fs.access(fpath);
return true;
} catch {
return false;
}
};
2024-03-19 15:35:59 +03:00
2024-03-24 20:38:18 +03:00
try {
Promise.all(
files.map(async (file) => {
const filepath = path.join(rootDirectory, file);
if (!(await fileExists(filepath))) {
console.error(`File ${file} does not exist, skipping...`);
return;
}
return fs.unlink(filepath);
}),
);
} catch (error) {
console.error('Error cleaning files:', error);
2024-03-19 15:35:59 +03:00
process.exit(1);
2024-03-24 20:38:18 +03:00
}