@caweb/cli 1.11.0 → 1.11.1

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,102 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+ import { confirm } from '@inquirer/prompts';
7
+ import chalk from 'chalk';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import { appPath, writeLine } from '../../lib/index.js';
13
+
14
+ import {
15
+ promptForGeneralInfo,
16
+ promptForSocial,
17
+ promptForGoogleOptions,
18
+ promptForAlerts,
19
+ promptForHeader,
20
+ promptForFooter
21
+ } from './prompts.js';
22
+
23
+ /**
24
+ * Promisified dependencies
25
+ */
26
+
27
+ /**
28
+ * Creates a new CAWebPublishing Site Configuration file
29
+ *
30
+ * @param {Object} options
31
+ * @param {Object} options.spinner A CLI spinner which indicates progress.
32
+ * @param {boolean} options.debug True if debug mode is enabled.
33
+ * @param {boolean} options.siteTitle Site Title.
34
+ * @param {boolean} options.silent Runs the site creation process without prompts, this is useful for CI/CD pipelines.
35
+ */
36
+ export default async function createSite({
37
+ spinner,
38
+ debug,
39
+ siteTitle
40
+ } ) {
41
+ spinner.stop();
42
+
43
+ let filePath = path.join( appPath, 'caweb.json' );
44
+ let siteData = {};
45
+
46
+ // check if the site data file exists
47
+ if( fs.existsSync( filePath ) ) {
48
+ let file = fs.readFileSync( filePath, 'utf8' );
49
+ let data = JSON.parse( file );
50
+
51
+ // check if the data file has site data
52
+ if( data.site ) {
53
+ const continueProcess = await confirm(
54
+ {
55
+ message: `Site data already exists, existing data will be overwritten.\nWould you like to continue?`,
56
+ default: true
57
+ },
58
+ {
59
+ clearPromptOnDone: true,
60
+ }
61
+ ).catch(() => {process.exit(1);});
62
+
63
+ // if the user wants to continue, set the site data
64
+ // otherwise exit the process
65
+ if( continueProcess ){
66
+ siteData = data.site;
67
+ }else{
68
+ spinner.fail( 'Site creation cancelled.' );
69
+ process.exit( 0 );
70
+ }
71
+ }
72
+ }
73
+
74
+ writeLine('CAWebPublishing Site Creation Process', {char: '#', borderColor: 'green'});
75
+ writeLine('This process will create a site configuration file for CAWebPublishing.', {color: 'cyan', prefix: 'i'});
76
+ writeLine('Please answer the following questions to create your site configuration file.', {color: 'cyan', prefix: 'i'});
77
+ writeLine('You can skip any question by pressing enter.', {color: 'cyan', prefix: 'i'});
78
+ writeLine('You can also edit the configuration file later.', {color: 'cyan', prefix: 'i'});
79
+
80
+ // populate the site data
81
+ siteData = {
82
+ ...await promptForGeneralInfo(siteTitle),
83
+ header: await promptForHeader(),
84
+ alerts: await promptForAlerts(),
85
+ social: await promptForSocial(),
86
+ google: await promptForGoogleOptions(),
87
+ footer: await promptForFooter(),
88
+ };
89
+
90
+ // write the site data to the file
91
+ fs.writeFileSync(
92
+ path.join( appPath, 'caweb.json' ),
93
+ JSON.stringify( {site:siteData}, null, 4 )
94
+ );
95
+
96
+ writeLine('CAWebPublishing Site Creation Process Complete', {char: '#', borderColor: 'green'});
97
+ writeLine('You can now start the site by running the following command:', {color: 'cyan', prefix: 'i'});
98
+ writeLine(`npm run caweb serve`, {color: 'cyan', prefix: 'i'});
99
+
100
+ spinner.start('CAWebPublishing Site Configuration file saved.');
101
+
102
+ };