@mapples/cli 0.0.1 → 0.0.2

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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Synchronizes style from the API
3
+ */
4
+ export declare const syncStyle: () => Promise<void>;
5
+ /**
6
+ * Shows information about style in a table format
7
+ */
8
+ export declare const showStyleInfo: () => Promise<void>;
package/dist/index.js CHANGED
@@ -71636,7 +71636,7 @@ const projectService = (axiosInstance) => {
71636
71636
 
71637
71637
  const styleService = (axiosInstance) => {
71638
71638
  const get = async () => {
71639
- const { data } = await axiosInstance.get('/public/style');
71639
+ const { data } = await axiosInstance.get('/public/styles');
71640
71640
  return data;
71641
71641
  };
71642
71642
  return {
@@ -71685,7 +71685,7 @@ const fetchPages = async () => {
71685
71685
  * Creates a directory if it doesn't exist
71686
71686
  * @param dirPath The directory path
71687
71687
  */
71688
- const ensureDirectoryExists = (dirPath) => {
71688
+ const ensureDirectoryExists$1 = (dirPath) => {
71689
71689
  if (!fs.existsSync(dirPath)) {
71690
71690
  fs.mkdirSync(dirPath, { recursive: true });
71691
71691
  }
@@ -71722,7 +71722,7 @@ const createPageFromTemplates = (pageName, pageData, config) => {
71722
71722
  const templateDir = path.resolve(__dirname, '../templates/PageTemplate');
71723
71723
  const destDir = path.join(process.cwd(), config.sourceDir, config.pagesDir, pageName);
71724
71724
  // Ensure the destination directory exists
71725
- ensureDirectoryExists(destDir);
71725
+ ensureDirectoryExists$1(destDir);
71726
71726
  // Get all files in the template directory
71727
71727
  const templateFiles = fs.readdirSync(templateDir);
71728
71728
  // Process each template file
@@ -71924,6 +71924,227 @@ const showPagesInfo = async () => {
71924
71924
  }
71925
71925
  };
71926
71926
 
71927
+ /**
71928
+ * Fetches style from the API
71929
+ * @returns Style data
71930
+ */
71931
+ const fetchStyle = async () => {
71932
+ try {
71933
+ return await services.style.get();
71934
+ }
71935
+ catch (error) {
71936
+ console.error('Error fetching style:', error);
71937
+ throw error;
71938
+ }
71939
+ };
71940
+ /**
71941
+ * Creates a directory if it doesn't exist
71942
+ * @param dirPath The directory path
71943
+ */
71944
+ const ensureDirectoryExists = (dirPath) => {
71945
+ if (!fs.existsSync(dirPath)) {
71946
+ fs.mkdirSync(dirPath, { recursive: true });
71947
+ }
71948
+ };
71949
+ /**
71950
+ * Creates a .donotedit file in the style directory
71951
+ * @param styleDir The style directory path
71952
+ */
71953
+ const createDonotEditFile = (styleDir) => {
71954
+ const donotEditPath = path.join(styleDir, '.donotedit');
71955
+ if (!fs.existsSync(donotEditPath)) {
71956
+ fs.writeFileSync(donotEditPath, '');
71957
+ }
71958
+ };
71959
+ /**
71960
+ * Synchronizes style from the API
71961
+ */
71962
+ const syncStyle = async () => {
71963
+ try {
71964
+ // Read the configuration
71965
+ const config = readConfig();
71966
+ if (!config) {
71967
+ console.error('Configuration not found. Run "mapples init" first.');
71968
+ process.exit(1);
71969
+ }
71970
+ console.log('Fetching style...');
71971
+ // Fetch style from the API
71972
+ const style = await fetchStyle();
71973
+ // Create style directory
71974
+ const styleDir = path.join(process.cwd(), config.sourceDir, 'style');
71975
+ ensureDirectoryExists(styleDir);
71976
+ // Create .donotedit file
71977
+ createDonotEditFile(styleDir);
71978
+ // Save style.json with the transformed structure
71979
+ const styleJsonPath = path.join(styleDir, 'style.json');
71980
+ const styleConfig = {
71981
+ themeConfig: style.theme?.data || {},
71982
+ typographyConfig: style.typography?.data || {},
71983
+ sizingConfig: style.sizing?.data || {},
71984
+ };
71985
+ writeJsonToFile(styleJsonPath, styleConfig);
71986
+ // Save _meta_style.json with response data excluding the data keys
71987
+ const metaStylePath = path.join(styleDir, '_meta_style.json');
71988
+ const metaData = lodashExports.cloneDeep(style);
71989
+ // Remove data from theme, sizing, and typography
71990
+ if (metaData.theme && metaData.theme.data) {
71991
+ lodashExports.unset(metaData.theme, 'data');
71992
+ }
71993
+ if (metaData.sizing && metaData.sizing.data) {
71994
+ lodashExports.unset(metaData.sizing, 'data');
71995
+ }
71996
+ if (metaData.typography && metaData.typography.data) {
71997
+ lodashExports.unset(metaData.typography, 'data');
71998
+ }
71999
+ writeJsonToFile(metaStylePath, metaData);
72000
+ console.log('Style synchronized successfully.');
72001
+ }
72002
+ catch (error) {
72003
+ console.error('Error synchronizing style:', error);
72004
+ process.exit(1);
72005
+ }
72006
+ };
72007
+ /**
72008
+ * Shows information about style in a table format
72009
+ */
72010
+ const showStyleInfo = async () => {
72011
+ try {
72012
+ console.log('Fetching style...');
72013
+ // Read the configuration
72014
+ const config = readConfig();
72015
+ if (!config) {
72016
+ console.error('Configuration not found. Run "mapples init" first.');
72017
+ process.exit(1);
72018
+ }
72019
+ // Fetch style from the API
72020
+ const style = await fetchStyle();
72021
+ // Check style directory and files
72022
+ const styleDir = path.join(process.cwd(), config.sourceDir, 'style');
72023
+ const styleJsonPath = path.join(styleDir, 'style.json');
72024
+ const metaStylePath = path.join(styleDir, '_meta_style.json');
72025
+ // Define style components
72026
+ const styleComponents = [
72027
+ { name: 'theme', data: style.theme },
72028
+ { name: 'typography', data: style.typography },
72029
+ { name: 'sizing', data: style.sizing },
72030
+ ];
72031
+ // Determine status for each component
72032
+ const componentStatuses = styleComponents.map((component) => {
72033
+ if (!fs.existsSync(styleDir)) {
72034
+ return { status: 'New', color: 'white', icon: '🆕' };
72035
+ }
72036
+ else if (!fs.existsSync(styleJsonPath) || !fs.existsSync(metaStylePath)) {
72037
+ return { status: 'New', color: 'white', icon: '🆕' };
72038
+ }
72039
+ else {
72040
+ try {
72041
+ // Read and parse meta file
72042
+ const metaContent = fs.readFileSync(metaStylePath, 'utf-8');
72043
+ const metaData = JSON.parse(metaContent);
72044
+ // Compare updatedAt timestamps
72045
+ const metaComponent = metaData[component.name];
72046
+ const apiComponent = component.data;
72047
+ if (!metaComponent || !apiComponent) {
72048
+ return { status: 'New', color: 'white', icon: '🆕' };
72049
+ }
72050
+ if (metaComponent.updated_at === apiComponent.updated_at) {
72051
+ return { status: 'Synced', color: 'green', icon: '✅ ' };
72052
+ }
72053
+ else {
72054
+ return { status: 'Update', color: 'yellow', icon: '⚠️' };
72055
+ }
72056
+ }
72057
+ catch (error) {
72058
+ console.error(`Error reading meta file for ${component.name}:`, error);
72059
+ return { status: 'Error', color: 'red', icon: '❌' };
72060
+ }
72061
+ }
72062
+ });
72063
+ // Calculate column widths for better formatting
72064
+ const nameWidth = Math.max(4, ...styleComponents.map((c) => c.name.length));
72065
+ const uuidWidth = Math.max(4, ...styleComponents.map((c) => c.data?.uuid?.length || 0));
72066
+ const createdAtWidth = Math.max(9, ...styleComponents.map((c) => c.data?.created_at?.length || 0));
72067
+ const updatedAtWidth = Math.max(9, ...styleComponents.map((c) => c.data?.updated_at?.length || 0));
72068
+ const statusWidth = Math.max(6, ...componentStatuses.map((s) => (s.icon + s.status).length)) + 3;
72069
+ // Print table header
72070
+ console.log('┌' +
72071
+ '─'.repeat(nameWidth + 2) +
72072
+ '┬' +
72073
+ '─'.repeat(statusWidth + 2) +
72074
+ '┬' +
72075
+ '─'.repeat(createdAtWidth + 2) +
72076
+ '┬' +
72077
+ '─'.repeat(updatedAtWidth + 2) +
72078
+ '┬' +
72079
+ '─'.repeat(uuidWidth + 2) +
72080
+ '┐');
72081
+ console.log('│ ' +
72082
+ 'name'.padEnd(nameWidth) +
72083
+ ' │ ' +
72084
+ 'status'.padEnd(statusWidth) +
72085
+ ' │ ' +
72086
+ 'createdAt'.padEnd(createdAtWidth) +
72087
+ ' │ ' +
72088
+ 'updatedAt'.padEnd(updatedAtWidth) +
72089
+ ' │ ' +
72090
+ 'uuid'.padEnd(uuidWidth) +
72091
+ ' │');
72092
+ console.log('├' +
72093
+ '─'.repeat(nameWidth + 2) +
72094
+ '┼' +
72095
+ '─'.repeat(statusWidth + 2) +
72096
+ '┼' +
72097
+ '─'.repeat(createdAtWidth + 2) +
72098
+ '┼' +
72099
+ '─'.repeat(updatedAtWidth + 2) +
72100
+ '┼' +
72101
+ '─'.repeat(uuidWidth + 2) +
72102
+ '┤');
72103
+ // Helper function to truncate text if it's too long
72104
+ const truncate = (text, maxLength) => {
72105
+ if (text.length <= maxLength)
72106
+ return text;
72107
+ return text.substring(0, maxLength - 3) + '...';
72108
+ };
72109
+ // Print table rows for each component
72110
+ styleComponents.forEach((component, index) => {
72111
+ const status = componentStatuses[index];
72112
+ const statusText = status.icon + status.status;
72113
+ const visibleStatusLength = statusText.length;
72114
+ const coloredStatus = chalk[status.color](statusText);
72115
+ const statusPadding = ' '.repeat(Math.max(0, statusWidth - visibleStatusLength));
72116
+ console.log('│ ' +
72117
+ component.name.padEnd(nameWidth) +
72118
+ ' │ ' +
72119
+ coloredStatus +
72120
+ statusPadding +
72121
+ ' │ ' +
72122
+ truncate(component.data?.created_at || '', createdAtWidth).padEnd(createdAtWidth) +
72123
+ ' │ ' +
72124
+ truncate(component.data?.updated_at || '', updatedAtWidth).padEnd(updatedAtWidth) +
72125
+ ' │ ' +
72126
+ truncate(component.data?.uuid || '', uuidWidth).padEnd(uuidWidth) +
72127
+ ' │');
72128
+ });
72129
+ // Print table footer
72130
+ console.log('└' +
72131
+ '─'.repeat(nameWidth + 2) +
72132
+ '┴' +
72133
+ '─'.repeat(statusWidth + 2) +
72134
+ '┴' +
72135
+ '─'.repeat(createdAtWidth + 2) +
72136
+ '┴' +
72137
+ '─'.repeat(updatedAtWidth + 2) +
72138
+ '┴' +
72139
+ '─'.repeat(uuidWidth + 2) +
72140
+ '┘');
72141
+ }
72142
+ catch (error) {
72143
+ console.error('Error fetching style info:', error);
72144
+ process.exit(1);
72145
+ }
72146
+ };
72147
+
71927
72148
  const program = new Command();
71928
72149
  program.name('mapples').description('Mapples CLI').version('0.0.0');
71929
72150
  program
@@ -71982,5 +72203,27 @@ program
71982
72203
  process.exit(1);
71983
72204
  }
71984
72205
  });
72206
+ program
72207
+ .command('style')
72208
+ .description('Manage Mapples style')
72209
+ .option('--sync', 'Synchronize style from the API')
72210
+ .option('--info', 'Show information about style')
72211
+ .action(async (options) => {
72212
+ try {
72213
+ if (options.sync) {
72214
+ await syncStyle();
72215
+ }
72216
+ else if (options.info) {
72217
+ await showStyleInfo();
72218
+ }
72219
+ else {
72220
+ console.log('Please specify an option: --sync, --info');
72221
+ }
72222
+ }
72223
+ catch (error) {
72224
+ console.error('Error managing style:', error);
72225
+ process.exit(1);
72226
+ }
72227
+ });
71985
72228
  program.parse(process.argv);
71986
72229
  //# sourceMappingURL=index.js.map