@mapples/cli 0.0.6 → 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.
@@ -1,2 +1,2 @@
1
- export declare const syncPages: (configPath?: string) => Promise<void>;
1
+ export declare const syncPages: (configPath?: string, force?: boolean) => Promise<void>;
2
2
  export declare const showPagesInfo: (configPath?: string) => Promise<void>;
package/dist/index.js CHANGED
@@ -75346,9 +75346,10 @@ const processTemplateFile = (templatePath, destPath, data) => {
75346
75346
  fs.copyFileSync(templatePath, destPath);
75347
75347
  }
75348
75348
  };
75349
- const createPageFromTemplates = (pageName, pageData, config) => {
75349
+ const createPageFromTemplates = (pageName, pageData, config, force = false) => {
75350
75350
  const templateDir = path.resolve(__dirname, '../templates/PageTemplate');
75351
75351
  const destDir = path.join(process.cwd(), config.sourceDir, config.dirs.pages, pageName);
75352
+ const pageExists = fs.existsSync(destDir);
75352
75353
  ensureDirectoryExists$2(destDir);
75353
75354
  // Files that should not be overwritten if they already exist
75354
75355
  const protectedExtensions = ['.tsx'];
@@ -75365,11 +75366,20 @@ const createPageFromTemplates = (pageName, pageData, config) => {
75365
75366
  }
75366
75367
  destFileName = destFileName.replace(/{{PageName}}/g, pageName).replace(/\.tmpl$/, '');
75367
75368
  const destPath = path.join(destDir, destFileName);
75368
- // Check if this file has a protected extension and already exists
75369
75369
  const fileExtension = path.extname(destFileName);
75370
75370
  if (protectedExtensions.includes(fileExtension) && fs.existsSync(destPath)) {
75371
- console.log(`Skipping protected file: ${destFileName}`);
75372
- return;
75371
+ if (force) {
75372
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
75373
+ const baseName = path.basename(destFileName, fileExtension);
75374
+ const deprecatedFileName = `_depr_${timestamp}_${baseName}${fileExtension}.old`;
75375
+ const deprecatedPath = path.join(destDir, deprecatedFileName);
75376
+ fs.renameSync(destPath, deprecatedPath);
75377
+ console.log(`Renamed existing file: ${destFileName} → ${deprecatedFileName}`);
75378
+ }
75379
+ else {
75380
+ console.log(`Skipping protected file: ${destFileName}`);
75381
+ return;
75382
+ }
75373
75383
  }
75374
75384
  if (file === `_meta_{{PageName}}.json.tmpl`) {
75375
75385
  const metaData = lodashExports.cloneDeep(pageData);
@@ -75383,20 +75393,38 @@ const createPageFromTemplates = (pageName, pageData, config) => {
75383
75393
  processTemplateFile(templatePath, destPath, { PageName: pageName });
75384
75394
  }
75385
75395
  });
75386
- console.log(`Created page: ${pageName}`);
75396
+ console.log(`${pageExists ? 'Updated' : 'Created'} page: ${pageName}`);
75387
75397
  };
75388
- const syncPages = async (configPath) => {
75398
+ const syncPages = async (configPath, force = false) => {
75389
75399
  try {
75390
75400
  const config = readConfig(configPath);
75391
75401
  if (!config) {
75392
75402
  console.error('Configuration not found. Run "mapples init" first.');
75393
75403
  process.exit(1);
75394
75404
  }
75405
+ if (force) {
75406
+ console.log(chalk.yellow('⚠️ WARNING: Force mode enabled'));
75407
+ console.log(chalk.yellow('This will overwrite all .tsx Mapplet components.'));
75408
+ console.log(chalk.yellow('Existing components will be renamed with a timestamp.'));
75409
+ console.log('');
75410
+ const { confirm } = await inquirer.prompt([
75411
+ {
75412
+ type: 'confirm',
75413
+ name: 'confirm',
75414
+ message: 'Are you sure you want to continue?',
75415
+ default: false,
75416
+ },
75417
+ ]);
75418
+ if (!confirm) {
75419
+ console.log('Operation cancelled.');
75420
+ return;
75421
+ }
75422
+ }
75395
75423
  console.log('Fetching pages...');
75396
75424
  const pages = await fetchPages();
75397
75425
  console.log(`Found ${pages.length} pages.`);
75398
75426
  for (const page of pages) {
75399
- createPageFromTemplates(page.name, page, config);
75427
+ createPageFromTemplates(page.name, page, config, force);
75400
75428
  }
75401
75429
  console.log('Pages synchronized successfully.');
75402
75430
  }
@@ -75683,6 +75711,47 @@ const getExistingMetaFiles = (config) => {
75683
75711
  }
75684
75712
  return existingFiles;
75685
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
+ };
75686
75755
  const syncAssets = async (configPath) => {
75687
75756
  try {
75688
75757
  const config = readConfig(configPath);
@@ -75761,6 +75830,9 @@ const syncAssets = async (configPath) => {
75761
75830
  }
75762
75831
  }
75763
75832
  }
75833
+ // Generate asset map after all assets are processed
75834
+ console.log('\nGenerating asset map...');
75835
+ generateAssetMap(config);
75764
75836
  console.log(chalk.green('\nAssets synchronized successfully.'));
75765
75837
  }
75766
75838
  catch (error) {
@@ -76116,18 +76188,20 @@ program
76116
76188
  .command('pages')
76117
76189
  .description('Manage Mapples pages')
76118
76190
  .option('--sync', 'Synchronize pages from the API')
76191
+ .option('--force', 'Force sync and overwrite protected files (use with --sync)')
76119
76192
  .option('--info', 'Show information about pages')
76120
76193
  .option('--config <path>', 'Path to the configuration file')
76121
76194
  .action(async (options) => {
76122
76195
  try {
76123
76196
  if (options.sync) {
76124
- await syncPages(options.config);
76197
+ await syncPages(options.config, options.force);
76125
76198
  }
76126
76199
  else if (options.info) {
76127
76200
  await showPagesInfo(options.config);
76128
76201
  }
76129
76202
  else {
76130
76203
  console.log('Please specify an option: --sync, --info');
76204
+ console.log('Use --sync --force to overwrite protected .tsx files');
76131
76205
  }
76132
76206
  }
76133
76207
  catch (error) {