Files
spacedrive/packages/assets/scripts/generate.mjs
ameer2468 a7fed83556 [ENG-1413] Full disk access perms (#1791)
* fda wip

* clippy

* add tauri invoke fns for FDA

* fda wip

* clippy

* add tauri invoke fns for FDA

* wip

* fda wip

* clippy

* add tauri invoke fns for FDA

* wip

* wip

* wip fda

* remove imports

* hopefully improve FDA

* execute only on macos

* ts

* ts

* Update Platform.tsx

* Update AddLocationButton.tsx

* remove console log

* fix: fda and add unit tests

* temp commit for Jake

* add fda state and keybind handling (so the frontend is kept up to date)

* update FDA

* update imports

* testing purposes

* Jakes work

* fix fda checks

* work in progress (but not working)

* remove dead files

* attempt #2

* !!!temporarily enable devtools in prod

* remove alert

* show FDA screen but don't require it

* add an FDA button to general client settings

* Update AddLocationButton.tsx

* remove dead code

* unused dep

* old errors

* remove import

* dead code

* dead code + typesafety

* eslint

* remove fda dialog references

* remove mp4 vid

* hopefully fix onboarding for non-macos OSes

* shorter nav

---------

Co-authored-by: jake <77554505+brxken128@users.noreply.github.com>
2023-11-23 20:54:45 +00:00

78 lines
2.4 KiB
JavaScript

/*
* This script generates an index file for each asset folder specified in `assetFolders`.
* The index file will export all assets in the folder as an object.
*
* Usage:
* 1. Add the names of your asset folders to the `assetFolders` array.
* 2. Run `pnpm assets gen` to generate the index files.
*
* The generated index files will have the name `index.ts` and will be located in the root of each asset folder.
*/
import fs from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import prettier from 'prettier';
const assetFolders = ['icons', 'images', 'svgs/brands', 'svgs/ext/Extras', 'svgs/ext/Code', 'videos'];
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
prettier.resolveConfig(join(__dirname, '..', '..', '..', '.prettierrc.js')).then((options) =>
Promise.all(
assetFolders.map(async (folder) => {
const indexFilePath = join(__dirname, '..', folder, 'index.ts');
const assetsFolderPath = join(__dirname, '..', folder);
if (
await fs.access(indexFilePath).then(
() => true,
() => false
)
) {
// Delete the index file if it already exists.
await fs.unlink(indexFilePath);
}
const fileNames = await fs.readdir(assetsFolderPath);
// Generate the import statements for each asset.
const assetImports = fileNames
.filter((fileName) => fileName !== 'index.ts' && !/(^|\/)\.[^\/\.]/g.test(fileName))
.map((fileName) => {
const variableName = fileName.split('.')[0].replace(/-/g, '');
if (folder.startsWith('svgs')) {
return `import { ReactComponent as ${variableName} } from './${fileName}';`;
}
return `import ${variableName} from './${fileName}';`;
})
.join('\n');
// Generate the export statements for each asset.
const assetExports = fileNames
.filter((fileName) => fileName !== 'index.ts' && !/(^|\/)\.[^\/\.]/g.test(fileName))
.map((fileName) => `${fileName.split('.')[0].replace(/-/g, '')}`)
.join(',\n');
// Generate the index file content.
const indexFileContent = await prettier.format(
`
/*
* This file was automatically generated by a script.
* To regenerate this file, run: pnpm assets gen
*/
${assetImports}
export {
${assetExports}
};`,
{ ...options, parser: 'typescript' }
);
// Write the index file.
await fs.writeFile(indexFilePath, indexFileContent);
})
)
);