@mapples/cli 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75711,6 +75711,47 @@ const getExistingMetaFiles = (config) => {
|
|
|
75711
75711
|
}
|
|
75712
75712
|
return existingFiles;
|
|
75713
75713
|
};
|
|
75714
|
+
const generateAssetMap = (config) => {
|
|
75715
|
+
const metaAssetsDir = path.join(process.cwd(), config.sourceDir, config.dirs.assets, '_meta_assets');
|
|
75716
|
+
if (!fs.existsSync(metaAssetsDir)) {
|
|
75717
|
+
return;
|
|
75718
|
+
}
|
|
75719
|
+
const assetMap = {};
|
|
75720
|
+
const items = fs.readdirSync(metaAssetsDir);
|
|
75721
|
+
for (const item of items) {
|
|
75722
|
+
if (item.startsWith('_meta_') && item.endsWith('.json')) {
|
|
75723
|
+
const metaFilePath = path.join(metaAssetsDir, item);
|
|
75724
|
+
try {
|
|
75725
|
+
const metaContent = fs.readFileSync(metaFilePath, 'utf-8');
|
|
75726
|
+
const metaData = JSON.parse(metaContent);
|
|
75727
|
+
// Create the ref string in format: "ref(assetType:uuid:name.ext)"
|
|
75728
|
+
const refString = `ref(${metaData.type}:${metaData.uuid}:${metaData.file_name})`;
|
|
75729
|
+
// Create the require path relative to the assets directory
|
|
75730
|
+
const assetPath = `./${metaData.type}/${metaData.file_name}`;
|
|
75731
|
+
assetMap[refString] = `require("${assetPath}")`;
|
|
75732
|
+
}
|
|
75733
|
+
catch (error) {
|
|
75734
|
+
console.error(`Error reading meta file ${item}:`, error);
|
|
75735
|
+
}
|
|
75736
|
+
}
|
|
75737
|
+
}
|
|
75738
|
+
// Generate the asset map file content
|
|
75739
|
+
const assetMapContent = `// Auto-generated asset map
|
|
75740
|
+
// Do not edit this file manually
|
|
75741
|
+
|
|
75742
|
+
const assetMap = {
|
|
75743
|
+
${Object.entries(assetMap)
|
|
75744
|
+
.map(([ref, requirePath]) => ` "${ref}": ${requirePath}`)
|
|
75745
|
+
.join(',\n')}
|
|
75746
|
+
};
|
|
75747
|
+
|
|
75748
|
+
export default assetMap;
|
|
75749
|
+
`;
|
|
75750
|
+
// Write the asset map to the assets directory
|
|
75751
|
+
const assetMapPath = path.join(process.cwd(), config.sourceDir, config.dirs.assets, 'assetMap.ts');
|
|
75752
|
+
fs.writeFileSync(assetMapPath, assetMapContent);
|
|
75753
|
+
console.log(chalk.green(`✓ Generated asset map: ${path.relative(process.cwd(), assetMapPath)}`));
|
|
75754
|
+
};
|
|
75714
75755
|
const syncAssets = async (configPath) => {
|
|
75715
75756
|
try {
|
|
75716
75757
|
const config = readConfig(configPath);
|
|
@@ -75789,6 +75830,9 @@ const syncAssets = async (configPath) => {
|
|
|
75789
75830
|
}
|
|
75790
75831
|
}
|
|
75791
75832
|
}
|
|
75833
|
+
// Generate asset map after all assets are processed
|
|
75834
|
+
console.log('\nGenerating asset map...');
|
|
75835
|
+
generateAssetMap(config);
|
|
75792
75836
|
console.log(chalk.green('\nAssets synchronized successfully.'));
|
|
75793
75837
|
}
|
|
75794
75838
|
catch (error) {
|