@mapples/cli 0.0.6 → 0.0.7

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
  }
@@ -76116,18 +76144,20 @@ program
76116
76144
  .command('pages')
76117
76145
  .description('Manage Mapples pages')
76118
76146
  .option('--sync', 'Synchronize pages from the API')
76147
+ .option('--force', 'Force sync and overwrite protected files (use with --sync)')
76119
76148
  .option('--info', 'Show information about pages')
76120
76149
  .option('--config <path>', 'Path to the configuration file')
76121
76150
  .action(async (options) => {
76122
76151
  try {
76123
76152
  if (options.sync) {
76124
- await syncPages(options.config);
76153
+ await syncPages(options.config, options.force);
76125
76154
  }
76126
76155
  else if (options.info) {
76127
76156
  await showPagesInfo(options.config);
76128
76157
  }
76129
76158
  else {
76130
76159
  console.log('Please specify an option: --sync, --info');
76160
+ console.log('Use --sync --force to overwrite protected .tsx files');
76131
76161
  }
76132
76162
  }
76133
76163
  catch (error) {