|
@@ -1,35 +1,39 @@
|
|
|
/**
|
|
/**
|
|
|
* Precompile the abilities config from Yaml to TS
|
|
* Precompile the abilities config from Yaml to TS
|
|
|
*/
|
|
*/
|
|
|
-import * as fs from 'fs';
|
|
|
|
|
-import * as path from 'path';
|
|
|
|
|
-import * as yaml from 'js-yaml';
|
|
|
|
|
|
|
+import * as fs from 'fs'
|
|
|
|
|
+import * as path from 'path'
|
|
|
|
|
+import * as yaml from 'js-yaml'
|
|
|
function loadYamlFile(filePath) {
|
|
function loadYamlFile(filePath) {
|
|
|
- try {
|
|
|
|
|
- const fileContents = fs.readFileSync(filePath, 'utf8');
|
|
|
|
|
- return yaml.load(fileContents);
|
|
|
|
|
- }
|
|
|
|
|
- catch (error) {
|
|
|
|
|
- console.error(`Error loading YAML file ${filePath}:`, error);
|
|
|
|
|
- return {};
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const fileContents = fs.readFileSync(filePath, 'utf8')
|
|
|
|
|
+ return yaml.load(fileContents)
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error(`Error loading YAML file ${filePath}:`, error)
|
|
|
|
|
+ return {}
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
function compileAbilitiesConfig() {
|
|
function compileAbilitiesConfig() {
|
|
|
- const configDir = path.join(process.cwd(), 'config/abilities/pages');
|
|
|
|
|
- const outputPath = path.join(process.cwd(), 'config/abilities-config-precompiled.ts');
|
|
|
|
|
- console.log('Starting abilities config compilation...');
|
|
|
|
|
- // Read all YAML files from the pages directory
|
|
|
|
|
- const yamlFiles = fs.readdirSync(configDir).filter(file => file.endsWith('.yaml'));
|
|
|
|
|
- const compiledAbilities = {};
|
|
|
|
|
- yamlFiles.forEach(file => {
|
|
|
|
|
- const filePath = path.join(configDir, file);
|
|
|
|
|
- console.log(`Processing ${file}...`);
|
|
|
|
|
- const config = loadYamlFile(filePath);
|
|
|
|
|
- // Merge all abilities from this file into the compiled config
|
|
|
|
|
- Object.assign(compiledAbilities, config);
|
|
|
|
|
- });
|
|
|
|
|
- // Generate TypeScript content
|
|
|
|
|
- const header = `/**
|
|
|
|
|
|
|
+ const configDir = path.join(process.cwd(), 'config/abilities/pages')
|
|
|
|
|
+ const outputPath = path.join(
|
|
|
|
|
+ process.cwd(),
|
|
|
|
|
+ 'config/abilities-config-precompiled.ts',
|
|
|
|
|
+ )
|
|
|
|
|
+ console.log('Starting abilities config compilation...')
|
|
|
|
|
+ // Read all YAML files from the pages directory
|
|
|
|
|
+ const yamlFiles = fs
|
|
|
|
|
+ .readdirSync(configDir)
|
|
|
|
|
+ .filter((file) => file.endsWith('.yaml'))
|
|
|
|
|
+ const compiledAbilities = {}
|
|
|
|
|
+ yamlFiles.forEach((file) => {
|
|
|
|
|
+ const filePath = path.join(configDir, file)
|
|
|
|
|
+ console.log(`Processing ${file}...`)
|
|
|
|
|
+ const config = loadYamlFile(filePath)
|
|
|
|
|
+ // Merge all abilities from this file into the compiled config
|
|
|
|
|
+ Object.assign(compiledAbilities, config)
|
|
|
|
|
+ })
|
|
|
|
|
+ // Generate TypeScript content
|
|
|
|
|
+ const header = `/**
|
|
|
* AUTO-GENERATED FILE - DO NOT MODIFY MANUALLY
|
|
* AUTO-GENERATED FILE - DO NOT MODIFY MANUALLY
|
|
|
*
|
|
*
|
|
|
* This file is automatically generated from YAML configuration files
|
|
* This file is automatically generated from YAML configuration files
|
|
@@ -41,14 +45,16 @@ function compileAbilitiesConfig() {
|
|
|
* Generated on: ${new Date().toISOString()}
|
|
* Generated on: ${new Date().toISOString()}
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-`;
|
|
|
|
|
- const tsContent = `${header}export default ${JSON.stringify(compiledAbilities, null, 2)} as const
|
|
|
|
|
-`;
|
|
|
|
|
- // Write the compiled TypeScript file
|
|
|
|
|
- fs.writeFileSync(outputPath, tsContent, 'utf8');
|
|
|
|
|
- console.log(`✓ Abilities config compiled successfully to ${outputPath}`);
|
|
|
|
|
- console.log(`✓ Processed ${yamlFiles.length} YAML files`);
|
|
|
|
|
- console.log(`✓ Generated ${Object.keys(compiledAbilities).length} ability definitions`);
|
|
|
|
|
|
|
+`
|
|
|
|
|
+ const tsContent = `${header}export default ${JSON.stringify(compiledAbilities, null, 2)} as const
|
|
|
|
|
+`
|
|
|
|
|
+ // Write the compiled TypeScript file
|
|
|
|
|
+ fs.writeFileSync(outputPath, tsContent, 'utf8')
|
|
|
|
|
+ console.log(`✓ Abilities config compiled successfully to ${outputPath}`)
|
|
|
|
|
+ console.log(`✓ Processed ${yamlFiles.length} YAML files`)
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `✓ Generated ${Object.keys(compiledAbilities).length} ability definitions`,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
// Run the compilation
|
|
// Run the compilation
|
|
|
-compileAbilitiesConfig();
|
|
|
|
|
|
|
+compileAbilitiesConfig()
|