@mapples/cli 0.0.4 → 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.
- package/README.md +2 -2
- package/dist/commands/pages.d.ts +1 -1
- package/dist/index.js +44 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/PageTemplate/.donotedit +8 -1
- package/templates/PageTemplate/index.ts.tmpl +1 -1
- package/templates/PageTemplate/{{PageName}}Mapplet.tsx.tmpl +23 -0
- package/templates/PageTemplate/{{PageName}}Component.tsx.tmpl +0 -8
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ This command will:
|
|
|
47
47
|
- Create page directories with the following structure:
|
|
48
48
|
```
|
|
49
49
|
src/pages/{PageName}/
|
|
50
|
-
├── {PageName}
|
|
50
|
+
├── {PageName}Mapplet.tsx
|
|
51
51
|
├── {PageName}.json
|
|
52
52
|
├── _meta_{PageName}.json
|
|
53
53
|
├── index.ts
|
|
@@ -101,7 +101,7 @@ The CLI uses a `.mapplesrc.json` file for configuration. Here are the available
|
|
|
101
101
|
|
|
102
102
|
When synchronizing pages, the CLI generates the following files for each page:
|
|
103
103
|
|
|
104
|
-
### Component File (`{PageName}
|
|
104
|
+
### Component File (`{PageName}Mapplet.tsx`)
|
|
105
105
|
|
|
106
106
|
A React component that uses the `@mapples/render` package to render page content.
|
|
107
107
|
|
package/dist/commands/pages.d.ts
CHANGED
|
@@ -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,10 +75346,13 @@ 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);
|
|
75354
|
+
// Files that should not be overwritten if they already exist
|
|
75355
|
+
const protectedExtensions = ['.tsx'];
|
|
75353
75356
|
const templateFiles = fs.readdirSync(templateDir);
|
|
75354
75357
|
templateFiles.forEach((file) => {
|
|
75355
75358
|
const templatePath = path.join(templateDir, file);
|
|
@@ -75363,6 +75366,21 @@ const createPageFromTemplates = (pageName, pageData, config) => {
|
|
|
75363
75366
|
}
|
|
75364
75367
|
destFileName = destFileName.replace(/{{PageName}}/g, pageName).replace(/\.tmpl$/, '');
|
|
75365
75368
|
const destPath = path.join(destDir, destFileName);
|
|
75369
|
+
const fileExtension = path.extname(destFileName);
|
|
75370
|
+
if (protectedExtensions.includes(fileExtension) && fs.existsSync(destPath)) {
|
|
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
|
+
}
|
|
75383
|
+
}
|
|
75366
75384
|
if (file === `_meta_{{PageName}}.json.tmpl`) {
|
|
75367
75385
|
const metaData = lodashExports.cloneDeep(pageData);
|
|
75368
75386
|
lodashExports.unset(metaData, 'data');
|
|
@@ -75371,24 +75389,42 @@ const createPageFromTemplates = (pageName, pageData, config) => {
|
|
|
75371
75389
|
else if (file === `{{PageName}}.json.tmpl`) {
|
|
75372
75390
|
writeJsonToFile(destPath, pageData.data || {});
|
|
75373
75391
|
}
|
|
75374
|
-
else if (file === `{{PageName}}
|
|
75392
|
+
else if (file === `{{PageName}}Mapplet.tsx.tmpl` || file === `index.ts.tmpl`) {
|
|
75375
75393
|
processTemplateFile(templatePath, destPath, { PageName: pageName });
|
|
75376
75394
|
}
|
|
75377
75395
|
});
|
|
75378
|
-
console.log(
|
|
75396
|
+
console.log(`${pageExists ? 'Updated' : 'Created'} page: ${pageName}`);
|
|
75379
75397
|
};
|
|
75380
|
-
const syncPages = async (configPath) => {
|
|
75398
|
+
const syncPages = async (configPath, force = false) => {
|
|
75381
75399
|
try {
|
|
75382
75400
|
const config = readConfig(configPath);
|
|
75383
75401
|
if (!config) {
|
|
75384
75402
|
console.error('Configuration not found. Run "mapples init" first.');
|
|
75385
75403
|
process.exit(1);
|
|
75386
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
|
+
}
|
|
75387
75423
|
console.log('Fetching pages...');
|
|
75388
75424
|
const pages = await fetchPages();
|
|
75389
75425
|
console.log(`Found ${pages.length} pages.`);
|
|
75390
75426
|
for (const page of pages) {
|
|
75391
|
-
createPageFromTemplates(page.name, page, config);
|
|
75427
|
+
createPageFromTemplates(page.name, page, config, force);
|
|
75392
75428
|
}
|
|
75393
75429
|
console.log('Pages synchronized successfully.');
|
|
75394
75430
|
}
|
|
@@ -76108,18 +76144,20 @@ program
|
|
|
76108
76144
|
.command('pages')
|
|
76109
76145
|
.description('Manage Mapples pages')
|
|
76110
76146
|
.option('--sync', 'Synchronize pages from the API')
|
|
76147
|
+
.option('--force', 'Force sync and overwrite protected files (use with --sync)')
|
|
76111
76148
|
.option('--info', 'Show information about pages')
|
|
76112
76149
|
.option('--config <path>', 'Path to the configuration file')
|
|
76113
76150
|
.action(async (options) => {
|
|
76114
76151
|
try {
|
|
76115
76152
|
if (options.sync) {
|
|
76116
|
-
await syncPages(options.config);
|
|
76153
|
+
await syncPages(options.config, options.force);
|
|
76117
76154
|
}
|
|
76118
76155
|
else if (options.info) {
|
|
76119
76156
|
await showPagesInfo(options.config);
|
|
76120
76157
|
}
|
|
76121
76158
|
else {
|
|
76122
76159
|
console.log('Please specify an option: --sync, --info');
|
|
76160
|
+
console.log('Use --sync --force to overwrite protected .tsx files');
|
|
76123
76161
|
}
|
|
76124
76162
|
}
|
|
76125
76163
|
catch (error) {
|