lucy-cli 1.2.4 → 2.0.0-alpha.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.
Files changed (173) hide show
  1. package/README.md +4 -3
  2. package/dist/args.d.ts +7 -0
  3. package/dist/args.js +23 -0
  4. package/dist/commands.d.ts +3 -0
  5. package/dist/commands.js +18 -0
  6. package/dist/config.d.ts +20 -0
  7. package/dist/config.js +39 -0
  8. package/dist/error.d.ts +17 -0
  9. package/dist/error.js +5 -0
  10. package/dist/helpers.d.ts +1 -32
  11. package/dist/helpers.js +6 -261
  12. package/dist/index.d.ts +2 -52
  13. package/dist/index.js +25 -282
  14. package/dist/init.d.ts +4 -8
  15. package/dist/init.js +245 -160
  16. package/dist/params.d.ts +7 -0
  17. package/dist/params.js +23 -0
  18. package/dist/policy.d.ts +3 -0
  19. package/dist/policy.js +5 -0
  20. package/dist/prepare.d.ts +0 -8
  21. package/dist/prepare.js +20 -19
  22. package/dist/runtime.d.ts +5 -0
  23. package/dist/runtime.js +11 -0
  24. package/dist/schemas/index.d.ts +2 -0
  25. package/dist/schemas/index.js +2 -0
  26. package/dist/schemas/types.js +1 -0
  27. package/dist/states.d.ts +10 -0
  28. package/dist/states.js +7 -0
  29. package/files/expo/.env +1 -0
  30. package/files/expo/.nvmrc +1 -0
  31. package/files/expo/.prettierignore +23 -0
  32. package/files/expo/.prettierrc.json +16 -0
  33. package/files/expo/.yarnrc +1 -0
  34. package/files/expo/.yarnrc.yml +3 -0
  35. package/files/expo/app/(tabs)/_layout.tsx +45 -0
  36. package/files/expo/app/_layout.tsx +45 -0
  37. package/files/expo/babel.config.js +9 -0
  38. package/files/expo/constants/Colors.ts +27 -0
  39. package/files/expo/constants/theme.ts +18 -0
  40. package/files/expo/eas.json +26 -0
  41. package/files/expo/eslint.config.js +185 -0
  42. package/files/expo/global.css +47 -0
  43. package/files/expo/hooks/useColorScheme.ts +11 -0
  44. package/files/expo/hooks/useColorScheme.web.ts +21 -0
  45. package/files/expo/hooks/useColorSchemeRN.ts +1 -0
  46. package/files/expo/hooks/useThemeColor.ts +21 -0
  47. package/files/expo/lib/data.ts +45 -0
  48. package/files/expo/lib/utils/index.ts +6 -0
  49. package/files/expo/lib/utils/polyfills.ts +29 -0
  50. package/files/expo/lib/wix/client.ts +14 -0
  51. package/files/expo/lib/wix/index.ts +1 -0
  52. package/files/expo/lucy.json +8 -0
  53. package/files/expo/readme.md +45 -0
  54. package/files/expo/tailwind.config.js +198 -0
  55. package/files/expo/tsconfig.json +40 -0
  56. package/files/expo/types/nativewind-env.d.ts +1 -0
  57. package/files/expo/types/reset.d.ts +1 -0
  58. package/files/velo/typescript/styles/global.scss +0 -0
  59. package/package.json +14 -11
  60. package/src/args.ts +36 -0
  61. package/src/commands.ts +21 -0
  62. package/src/config.ts +61 -0
  63. package/src/error.ts +4 -0
  64. package/src/helpers.ts +7 -305
  65. package/src/index.ts +29 -362
  66. package/src/init.ts +345 -177
  67. package/src/policy.ts +6 -0
  68. package/src/prepare.ts +19 -19
  69. package/src/runtime.ts +20 -0
  70. package/src/schemas/index.ts +3 -0
  71. package/src/schemas/types.ts +0 -0
  72. package/src/states.ts +15 -0
  73. package/{src/Gulpfile.ts → src copy/Gulpfile.ts } +3 -1
  74. package/{src/gulp/backend.ts → src copy/gulp/backend.ts } +3 -12
  75. package/{src/gulp/checks.ts → src copy/gulp/checks.ts } +2 -6
  76. package/{src/gulp/copy.ts → src copy/gulp/copy.ts } +1 -6
  77. package/src copy/gulp/helpers.ts +26 -0
  78. package/{src/gulp/public.ts → src copy/gulp/public.ts } +1 -6
  79. package/{src/gulp/styles.ts → src copy/gulp/styles.ts } +2 -7
  80. package/{src/gulp/templates.ts → src copy/gulp/templates.ts } +1 -6
  81. package/src copy/helpers.ts +307 -0
  82. package/src copy/index.ts +379 -0
  83. package/src copy/init.ts +183 -0
  84. package/src copy/models.ts +35 -0
  85. package/src copy/prepare.ts +24 -0
  86. package/src copy/schemas/index.ts +0 -0
  87. package/src copy/schemas/types.ts +0 -0
  88. package/src copy/settings.json +67 -0
  89. package/src copy/types.d.ts +8 -0
  90. package/dist/Gulpfile.d.ts +0 -33
  91. package/dist/Gulpfile.js +0 -114
  92. package/dist/cli.d.ts +0 -2
  93. package/dist/cli.js +0 -44
  94. package/dist/dev.d.ts +0 -2
  95. package/dist/dev.js +0 -14
  96. package/dist/gulp/backend copy.d.ts +0 -4
  97. package/dist/gulp/backend copy.js +0 -50
  98. package/dist/gulp/backend.d.ts +0 -3
  99. package/dist/gulp/backend.js +0 -101
  100. package/dist/gulp/checks.d.ts +0 -3
  101. package/dist/gulp/checks.js +0 -209
  102. package/dist/gulp/clean copy.d.ts +0 -2
  103. package/dist/gulp/clean copy.js +0 -19
  104. package/dist/gulp/clean.d.ts +0 -3
  105. package/dist/gulp/clean.js +0 -28
  106. package/dist/gulp/copy.d.ts +0 -2
  107. package/dist/gulp/copy.js +0 -38
  108. package/dist/gulp/docs.d.ts +0 -2
  109. package/dist/gulp/docs.js +0 -27
  110. package/dist/gulp/helpers.d.ts +0 -1
  111. package/dist/gulp/helpers.js +0 -7
  112. package/dist/gulp/pages copy.d.ts +0 -3
  113. package/dist/gulp/pages copy.js +0 -22
  114. package/dist/gulp/pages.d.ts +0 -2
  115. package/dist/gulp/pages.js +0 -36
  116. package/dist/gulp/pipeline.d.ts +0 -1
  117. package/dist/gulp/pipeline.js +0 -28
  118. package/dist/gulp/public.d.ts +0 -2
  119. package/dist/gulp/public.js +0 -54
  120. package/dist/gulp/styles.d.ts +0 -2
  121. package/dist/gulp/styles.js +0 -44
  122. package/dist/gulp/templates.d.ts +0 -2
  123. package/dist/gulp/templates.js +0 -37
  124. package/dist/gulp/test.d.ts +0 -2
  125. package/dist/gulp/test.js +0 -26
  126. package/dist/gulp/types.d.ts +0 -4
  127. package/dist/gulp/types.js +0 -288
  128. package/dist/gulp/watchers.d.ts +0 -9
  129. package/dist/gulp/watchers.js +0 -58
  130. package/dist/init copy.d.ts +0 -8
  131. package/dist/init copy.js +0 -167
  132. package/dist/install.d.ts +0 -2
  133. package/dist/install.js +0 -53
  134. package/dist/settings.json +0 -67
  135. package/dist/start_gulp.d.ts +0 -2
  136. package/dist/start_gulp.js +0 -14
  137. package/dist/sync.d.ts +0 -2
  138. package/dist/sync.js +0 -87
  139. package/src/gulp/helpers.ts +0 -9
  140. /package/{files/.gitmodules → dist/schemas/types.d.ts} +0 -0
  141. /package/files/{typescript/__mocks__/.gitkeep → velo/.gitmodules} +0 -0
  142. /package/files/{.madgerc → velo/.madgerc} +0 -0
  143. /package/files/{.nvmrc → velo/.nvmrc} +0 -0
  144. /package/files/{.stylelintrc.js → velo/.stylelintrc.js} +0 -0
  145. /package/files/{.yarnrc.yml → velo/.yarnrc.yml} +0 -0
  146. /package/files/{currents.config.js → velo/currents.config.js} +0 -0
  147. /package/files/{cypress → velo/cypress}/e2e/base/base.cy.ts +0 -0
  148. /package/files/{cypress → velo/cypress}/fixtures/example.json +0 -0
  149. /package/files/{cypress → velo/cypress}/support/commands.ts +0 -0
  150. /package/files/{cypress → velo/cypress}/support/e2e.ts +0 -0
  151. /package/files/{cypress → velo/cypress}/tsconfig.json +0 -0
  152. /package/files/{cypress.config.mjs → velo/cypress.config.mjs} +0 -0
  153. /package/files/{eslint.config.mjs → velo/eslint.config.mjs} +0 -0
  154. /package/files/{local.tsconfig.json → velo/local.tsconfig.json} +0 -0
  155. /package/files/{typedoc.json → velo/typedoc.json} +0 -0
  156. /package/files/{typescript/pages → velo/typescript/__mocks__}/.gitkeep +0 -0
  157. /package/files/{typescript → velo/typescript}/backend/data.ts +0 -0
  158. /package/files/{typescript → velo/typescript}/backend/events.ts +0 -0
  159. /package/files/{typescript → velo/typescript}/backend/http-functions.ts +0 -0
  160. /package/files/{typescript → velo/typescript}/backend/lib/http-functions/sync.ts +0 -0
  161. /package/files/{typescript → velo/typescript}/backend/permissions.json +0 -0
  162. /package/files/{typescript/public → velo/typescript/pages}/.gitkeep +0 -0
  163. /package/files/{typescript/styles → velo/typescript/public}/.gitkeep +0 -0
  164. /package/files/{typescript → velo/typescript}/public/scss/app.scss +0 -0
  165. /package/files/{typescript/styles/global.scss → velo/typescript/styles/.gitkeep} +0 -0
  166. /package/files/{typescript → velo/typescript}/tsconfig.json +0 -0
  167. /package/files/{vitest.config.ts → velo/vitest.config.ts} +0 -0
  168. /package/{src → src copy}/gulp/clean.ts +0 -0
  169. /package/{src → src copy}/gulp/pages.ts +0 -0
  170. /package/{src → src copy}/gulp/pipeline.ts +0 -0
  171. /package/{src → src copy}/gulp/types.ts +0 -0
  172. /package/{src → src copy}/gulp/watchers.ts +0 -0
  173. /package/{src → src copy}/sync.ts +0 -0
@@ -0,0 +1,379 @@
1
+ #!/usr/bin/env node --no-warnings
2
+ import { dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { existsSync } from 'fs';
5
+ import chalk from 'chalk';
6
+ import settings from './settings.json' with { type: "json" };;
7
+ import projectPackageJSON from '../package.json' with { type: "json" };;
8
+
9
+ import { join } from 'path';
10
+ import fs from 'fs/promises';
11
+
12
+ import { init } from './init.js';
13
+ import { sync } from './sync.js';
14
+ import { runGulp, installPackages, killAllProcesses, cleanupWatchers, createTemplateFolder, updateLucyConfigFromPackageJson } from './helpers.js';
15
+ import { prepare } from './prepare.js';
16
+ import { spawn, spawnSync } from 'child_process';
17
+ import os from 'os';
18
+
19
+ export type ModulesSettings = {
20
+ packageRoot: string;
21
+ targetFolder: string;
22
+ args: string[];
23
+ settings: LucySettings;
24
+ }
25
+ export type LucySettings = {
26
+ modules: {
27
+ [libName: string]: {
28
+ url: string;
29
+ branch: string;
30
+ path?: string;
31
+ noCompile?: boolean;
32
+ };
33
+ };
34
+ wixSettings: {
35
+ compilerOptions: {
36
+ composite: boolean;
37
+ noEmit: boolean;
38
+ lib: string[];
39
+ jsx: string;
40
+ };
41
+ exclude: string[];
42
+ };
43
+ initialized: boolean;
44
+ wixPackages: {
45
+ [packageName: string]: string;
46
+ };
47
+ devPackages: {
48
+ [packageName: string]: string;
49
+ };
50
+ scripts: {
51
+ [commandName: string]: string;
52
+ };
53
+ };
54
+
55
+ export type ModuleSettings = {
56
+ packageRoot: string;
57
+ targetFolder: string;
58
+ args: string[];
59
+ wixConfigPath: string;
60
+ lucyConfigPath: string;
61
+ packageJsonPath: string;
62
+ settings: LucySettings;
63
+ lockVersion: boolean;
64
+ force: boolean;
65
+ veloConfigName: string;
66
+ }
67
+
68
+ export type ProjectSettings = {
69
+ // packages?: Record<string, string>;
70
+ modules?: Record<string, string>;
71
+ lucySettings?: LucySettings;
72
+ packageJSON?: Record<string, any>;
73
+ }
74
+
75
+ export const orange = chalk.hex('#FFA500');
76
+ export const blue = chalk.blueBright;
77
+ export const green = chalk.greenBright;
78
+ export const red = chalk.redBright;
79
+ export const yellow = chalk.yellow;
80
+ export const magenta = chalk.magentaBright;
81
+
82
+ // eslint-disable-next-line @typescript-eslint/naming-convention
83
+ const __filename = fileURLToPath(import.meta.url);
84
+ // eslint-disable-next-line @typescript-eslint/naming-convention
85
+ const __dirname = dirname(__filename);
86
+
87
+ // const cwd = process.cwd();
88
+ // const command = `watchman watch-del '${cwd}'`;
89
+ // killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
90
+ // killAllProcesses('wix:dev');
91
+
92
+
93
+ process.on('exit', (code) => {
94
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
95
+ killAllProcesses('wix:dev');
96
+ cleanupWatchers();
97
+ console.log(`🚪 ${magenta.underline('Process exiting with code:')} ${orange(code)}`);
98
+ });
99
+
100
+ process.on('SIGINT', () => {
101
+ console.log(`🐕 ${green.underline('Received Ctrl+C (SIGINT), cleaning up...')}`);
102
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
103
+ killAllProcesses('wix:dev');
104
+ cleanupWatchers();
105
+ process.exit(); // Exit explicitly after handling
106
+ });
107
+
108
+ process.on('SIGTERM', () => {
109
+ console.log(`🛑 ${red.underline('Received termination signal (SIGTERM), cleaning up...')}`);
110
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
111
+ killAllProcesses('wix:dev');
112
+ cleanupWatchers();
113
+ process.exit(); // Exit explicitly after handling
114
+ });
115
+
116
+ process.on('uncaughtException', (error) => {
117
+ console.error(`💥 ${red.underline('Uncaught Exception:')}`, error);
118
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
119
+ killAllProcesses('wix:dev');
120
+ cleanupWatchers();
121
+ process.exit(1); // Exit with an error code
122
+ });
123
+
124
+ process.on('unhandledRejection', (reason, promise) => {
125
+ console.error(`🚨 ${yellow.underline('Unhandled Rejection at:')} ${orange(promise)}`);
126
+ console.error(`🚨 ${red.underline('Reason:')} ${reason}`); cleanupWatchers();
127
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
128
+ killAllProcesses('wix:dev');
129
+ cleanupWatchers();
130
+ process.exit(1); // Exit with an error code
131
+ });
132
+
133
+ /**
134
+ * Main function
135
+ * @returns {Promise<void>}
136
+ */
137
+ async function main(): Promise<void> {
138
+ // INFO: Module settings
139
+ const moduleSettings: ModuleSettings = {
140
+ packageRoot: dirname(__dirname),
141
+ targetFolder: process.cwd(),
142
+ args: process.argv.slice(2),
143
+ settings,
144
+ wixConfigPath: join(process.cwd(), 'wix.config.json'),
145
+ lucyConfigPath: join(process.cwd(), 'lucy.json'),
146
+ packageJsonPath: join(process.cwd(), 'package.json'),
147
+ force: false,
148
+ lockVersion: false,
149
+ veloConfigName: 'config.json'
150
+ }
151
+
152
+ let projectSettings: ProjectSettings = {};
153
+
154
+ if(moduleSettings.args.includes('version') || moduleSettings.args.includes('-v')){
155
+ console.log("🐾" + blue.bold(` => ${projectPackageJSON.version}`));
156
+
157
+ return;
158
+ }
159
+
160
+ if (moduleSettings.args.includes('templates')) {
161
+ const templatesPath = join(os.homedir(), '.lucy-cli');
162
+ if (!existsSync(templatesPath)) {
163
+ console.log((`💩 ${red.underline.bold("=> Lucy templates folder not found at =>")} ${orange(templatesPath)}`));
164
+ console.log(chalk.yellow('🐕 Creating templates folder with default template...'));
165
+ await createTemplateFolder(moduleSettings);
166
+ }
167
+
168
+ console.log(`🐕 ${blue.underline('Opening templates folder at:')} ${orange(templatesPath)}`);
169
+
170
+ let command: string;
171
+ switch (process.platform) {
172
+ case 'darwin': command = 'open'; break;
173
+ case 'win32': command = 'start'; break;
174
+ default: command = 'xdg-open'; break;
175
+ }
176
+
177
+ const child = spawn(command, [templatesPath], { detached: true, stdio: 'ignore' });
178
+ child.on('error', (err) => {
179
+ console.error(`💩 ${red.underline.bold('Failed to open folder:')} ${orange(err.message)}`);
180
+ });
181
+ child.unref();
182
+ return;
183
+ }
184
+
185
+
186
+ // Run velo sync
187
+ if(moduleSettings.args.includes('velo-sync')){
188
+ await sync(moduleSettings, projectSettings);
189
+
190
+ return;
191
+ }
192
+
193
+ if(moduleSettings.args.includes('help') || moduleSettings.args.includes('-h')){
194
+ console.log("🦮 " + green.underline.bold(' => Lucy CLI Help'));
195
+ console.log("Usage: lucy-cli <command> [options]");
196
+ console.log("\nCommands:");
197
+ console.log("🦮 " + magenta.bold('init') + " : Initializes caontaining a WIX project to enable full TS support");
198
+ console.log("🦮 " + magenta.bold('dev') + " : Starts the development environment. This includes setting up any required services for local development.");
199
+ console.log("🦮 " + magenta.bold('build-prod') + " : Builds the project in production mode, optimizing files for deployment.");
200
+ console.log("🦮 " + magenta.bold('prepare') + " : Prepares the project by installing packages & initializing git modules, configured in lucy.json");
201
+ console.log("🦮 " + magenta.bold('velo-sync') + " : Synchronizes wix collections(velo-sync -h for help)");
202
+ console.log("🦮 " + magenta.bold('install') + " : Installs all Wix npm packages listed in the 'lucy.json' file in the project directory.");
203
+ console.log("🦮 " + magenta.bold('fix') + " : Runs a fix command to resolve common issues in development or production settings.");
204
+ console.log("🦮 " + magenta.bold('docs') + " : Generates documentation for the project.");
205
+ console.log("🦮 " + magenta.bold('cypress') + " : Starts the cypress test runner.");
206
+ console.log("🦮 " + magenta.bold('templates') + " : Opens the Lucy CLI templates folder.");
207
+ console.log("🦮 " + magenta.bold('sync-pkgs') + " : Syncs dependencies from package.json to lucy.json.");
208
+ console.log("🦮 " + magenta.bold('e2e') + " : Starts the cypress test runner in CI mode. first argument is the key second is the build id <e2e <somekey <someID>");
209
+ console.log("\nOptions:");
210
+ console.log("🦮 " + magenta.bold('-h, help') + " : Displays this help message.");
211
+ console.log("🦮 " + magenta.bold('-v, version') + " : Displays the current version of Lucy CLI as defined in the project’s package.json.");
212
+ console.log("🦮 " + magenta.bold('-f, force') + " : Forces specific commands to execute even if they may lead to potential issues.");
213
+ console.log(" Used for functions like deleting obsolete pages or initializing missing components.");
214
+ console.log("🦮 " + magenta.bold('-l') + " : Locks package versions to those specified in the configuration file lucy.json");
215
+ console.log("\nExamples:");
216
+ console.log("🦮 " + magenta.bold('lucy-cli init') + " : Initializes a new Wix project.");
217
+ console.log("🦮 " + magenta.bold('lucy-cli dev') + " : Starts the development environment.");
218
+ console.log("🦮 " + magenta.bold('lucy-cli sync') + " : Synchronizes database and settings.");
219
+ console.log("🦮 " + magenta.bold('lucy-cli install') + " : Installs all Wix npm packages from 'lucy.json'.");
220
+ console.log("🦮 " + magenta.bold('lucy-cli dev -f') + " : Starts the dev environment with forced settings.");
221
+ console.log("🦮 " + magenta.bold('lucy-cli install -l') + " : Installs Wix npm packages, respecting locked versions specified in the configuration.");
222
+
223
+ return;
224
+ }
225
+
226
+ if (!existsSync(moduleSettings.wixConfigPath)) {
227
+ console.log((`💩 ${red.underline.bold("=> This is not a WIX project =>")} ${orange(moduleSettings.targetFolder)}`));
228
+ return;
229
+ }
230
+
231
+ //INFO: Collect project settings
232
+ if(moduleSettings.args.includes('-f')) moduleSettings.force = true;
233
+ if(moduleSettings.args.includes('-l')) moduleSettings.lockVersion = true;
234
+
235
+ if(existsSync(moduleSettings.packageJsonPath)) {
236
+ const packageJSONraw = await fs.readFile(join(moduleSettings.packageJsonPath), 'utf8');
237
+ try {
238
+ projectSettings.packageJSON = JSON.parse(packageJSONraw);
239
+ if(moduleSettings.force) {
240
+ console.log("❗️" + red.underline(' => Forcing'));
241
+ moduleSettings.force = true;
242
+ }
243
+ } catch (parseError) {
244
+ console.log((`💩 ${red.underline.bold("=> Error parsing package.json =>")} ${orange(parseError)}`));
245
+ return;
246
+ }
247
+ }
248
+
249
+ if(existsSync(moduleSettings.lucyConfigPath)) {
250
+ try {
251
+ const data = await fs.readFile(moduleSettings.lucyConfigPath, 'utf8');
252
+ projectSettings.lucySettings = JSON.parse(data);
253
+ } catch (parseError) {
254
+ console.log((`💩 ${red.underline.bold("=> Error parsing Lucy.json =>")} ${orange(parseError)}`));
255
+ }
256
+ } else {
257
+ if(!moduleSettings.args.includes('init')) {
258
+ return console.log(yellow.underline.bold('🐶 => Project not Initialized! Please initialize using "lucy-cli init"'));
259
+ };
260
+ }
261
+
262
+ if(!projectSettings.lucySettings?.initialized) {
263
+ if(!moduleSettings.args.includes('init')) {
264
+ return console.log(yellow.underline.bold('🐶 => Project not Initialized! Please initialize using "lucy-cli init"'));
265
+ }
266
+ }
267
+
268
+ if(moduleSettings.args.includes('-l')) moduleSettings.lockVersion = true;
269
+
270
+ console.log("🐕" + magenta.underline(' => Lucy CLI => RUNNING: ' + orange('Press Ctrl+C to stop.')));
271
+ // INFO: Run commands
272
+
273
+ if(moduleSettings.args.includes('init')){
274
+ if(projectSettings.lucySettings?.initialized && !moduleSettings.force) {
275
+ console.log((`💩 ${red.underline.bold("=> This project is already initialized =>")} ${orange(moduleSettings.targetFolder)}`));
276
+ console.log("🐕" + magenta.underline(' => Use -f to force initialization'));
277
+ return;
278
+ }
279
+ console.log("🐕" + magenta.underline(' => Initializing project'));
280
+ init(moduleSettings, projectSettings);
281
+
282
+ return;
283
+ }
284
+
285
+
286
+ if(moduleSettings.args.includes('docs')){
287
+ const res = spawnSync('yarn docs', { shell: true, stdio: 'inherit' });
288
+ if (res.error) {
289
+ return console.log((`💩 ${red.underline.bold("=> Failed to Docs generated => ")} ${orange(res.error.message)}`));
290
+ }
291
+ return console.log("🐕" + blue.underline(` => Docs generated!`));
292
+ }
293
+
294
+ if(moduleSettings.args.includes('cypress')){
295
+ const res = spawnSync('yarn cypress', { shell: true, stdio: 'inherit' });
296
+ if (res.error) {
297
+ return console.log((`💩 ${red.underline.bold("=> Failed to start cypress => ")} ${orange(res.error.message)}`));
298
+ }
299
+ return console.log("🐕" + blue.underline(` => Started Cypress`));
300
+ }
301
+
302
+ if (moduleSettings.args.includes('e2e')) {
303
+ // Extract arguments
304
+ const e2eIndex = moduleSettings.args.indexOf('e2e');
305
+ const key = moduleSettings.args[e2eIndex + 1];
306
+ const buildId = moduleSettings.args[e2eIndex + 2];
307
+
308
+ // Validate that both arguments are provided
309
+ if (!key && !buildId) {
310
+ console.log(`💩 ${red.underline.bold("=> Missing required arguments:")} ${orange("key")} and ${orange("build ID")}`);
311
+ process.exit(1);
312
+ }
313
+
314
+ // Run Cypress with the provided arguments
315
+ const res = spawnSync(`yarn e2e --key ${key} --ci-build-id ${buildId}`, { shell: true, stdio: 'inherit' });
316
+ if (res.error) {
317
+ console.log(`💩 ${red.underline.bold("=> Failed to start Cypress =>")} ${orange(res.error.message)}`);
318
+ process.exit(1);
319
+ }
320
+ return console.log("🐕 " + blue.underline(`=> Started Cypress successfully`));
321
+ }
322
+
323
+ if(moduleSettings.args.includes('prepare')){
324
+ await prepare( moduleSettings, projectSettings);
325
+
326
+ return;
327
+ }
328
+
329
+ if(moduleSettings.args.includes('install')){
330
+ if(!projectSettings.lucySettings?.initialized) {
331
+ console.log((`💩 ${red.underline.bold("=> This project is not initialized =>")} ${orange(moduleSettings.targetFolder)}`));
332
+ console.log("🐕" + magenta.underline(' => Use init to initialize'));
333
+ return;
334
+ }
335
+ await installPackages(projectSettings.lucySettings.wixPackages, projectSettings.lucySettings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
336
+
337
+ return;
338
+ }
339
+
340
+
341
+ if(moduleSettings.args.includes('dev')){
342
+ runGulp(moduleSettings, projectSettings, 'dev');
343
+
344
+ return;
345
+ }
346
+ if(moduleSettings.args.includes('build-prod')){
347
+ runGulp(moduleSettings, projectSettings, 'build-prod');
348
+
349
+ return;
350
+ }
351
+ if(moduleSettings.args.includes('fix')){
352
+ runGulp(moduleSettings, projectSettings, 'fix-wix');
353
+
354
+ return;
355
+ }
356
+
357
+ if(moduleSettings.args.includes('sync-pkgs')){
358
+ console.log("🐕" + magenta.underline(' => Syncing package.json with lucy.json'));
359
+ if (!existsSync(moduleSettings.packageJsonPath)) {
360
+ console.log((`💩 ${red.underline.bold("=> package.json not found at =>")} ${orange(moduleSettings.packageJsonPath)}`));
361
+ return;
362
+ }
363
+ if (!existsSync(moduleSettings.lucyConfigPath)) {
364
+ console.log((`💩 ${red.underline.bold("=> lucy.json not found at =>")} ${orange(moduleSettings.lucyConfigPath)}`));
365
+ return;
366
+ }
367
+ await updateLucyConfigFromPackageJson(moduleSettings.packageJsonPath, moduleSettings.lucyConfigPath);
368
+ return;
369
+ }
370
+
371
+
372
+ console.log("🐕" + blue.underline.bold(' => Running dev'));
373
+ runGulp(moduleSettings, projectSettings, 'dev');
374
+ }
375
+
376
+ main().catch((error) => {
377
+ console.error("Error:", error);
378
+ process.exit(1);
379
+ });
@@ -0,0 +1,183 @@
1
+ import chalk from 'chalk';
2
+ import { existsSync, mkdirSync, promises as fsPromises } from 'fs';
3
+ import fse from 'fs-extra';
4
+ import { join } from 'path';
5
+ import fs from 'fs/promises';
6
+ import path from 'path';
7
+ import os from 'os';
8
+ import enquirer from 'enquirer';
9
+ import { ModuleSettings, ProjectSettings, blue, green, orange, red } from './index.js';
10
+ import { createTemplateFolder, gitInit, installPackages } from './helpers.js';
11
+
12
+ const { Select } = enquirer as any;
13
+ /**
14
+ * Init Lucy project
15
+ * @param {string} cwd Current working directory
16
+ * @param {string} packageRoot Package root directory
17
+ * @returns {void}
18
+ */
19
+ export async function init(moduleSettings: ModuleSettings, projectSettings: ProjectSettings) {
20
+
21
+ if(projectSettings.packageJSON && projectSettings.packageJSON.wixLucy?.initialized && !moduleSettings.args.includes('-f')) {
22
+ console.log((`💩 ${red.underline.bold("=> This project is already initialized =>")} ${orange(moduleSettings.targetFolder)}`));
23
+ return;
24
+ }
25
+
26
+ const templatesPath = join(os.homedir(), '.lucy-cli');
27
+ if (!existsSync(templatesPath)) {
28
+ console.log(chalk.yellow(`Templates folder not found at ${orange(templatesPath)}. Creating it with a default template...`));
29
+ await createTemplateFolder(moduleSettings);
30
+ }
31
+
32
+ const templateChoices = (await fs.readdir(templatesPath, { withFileTypes: true }))
33
+ .filter(dirent => dirent.isDirectory())
34
+ .map(dirent => dirent.name);
35
+
36
+ if (templateChoices.length === 0) {
37
+ console.log((`💩 ${red.underline.bold("=> No templates found in =>")} ${orange(templatesPath)}`));
38
+ return;
39
+ }
40
+
41
+ const prompt = new Select({
42
+ name: 'template',
43
+ message: 'Select a project template',
44
+ choices: templateChoices
45
+ });
46
+
47
+ const selectedTemplate = await prompt.run();
48
+ const templateDir = join(templatesPath, selectedTemplate);
49
+ const templateFilesDir = join(templateDir, 'files');
50
+ const templateSettingsPath = join(templateDir, 'settings.json');
51
+
52
+ if (!existsSync(templateSettingsPath)) {
53
+ console.log((`💩 ${red.underline.bold("=> Template is missing settings.json at =>")} ${orange(templateSettingsPath)}`));
54
+ return;
55
+ }
56
+
57
+ try {
58
+ const templateSettingsRaw = await fs.readFile(templateSettingsPath, 'utf8');
59
+ moduleSettings.settings = JSON.parse(templateSettingsRaw);
60
+ } catch (e) {
61
+ console.log((`💩 ${red.underline.bold("=> Error reading or parsing template settings =>")} ${orange(e)}`));
62
+ return;
63
+ }
64
+
65
+ await copyFolder(templateFilesDir, moduleSettings.targetFolder);
66
+
67
+ await editJson(moduleSettings.packageJsonPath, ['type', 'scripts'], ['module', moduleSettings.settings.scripts ]);
68
+ await stringReplace(join(moduleSettings.targetFolder, 'currents.config.js'), ['__ProjectName__'], [path.basename(moduleSettings.targetFolder)]);
69
+
70
+ await installPackages(moduleSettings.settings.wixPackages, moduleSettings.settings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
71
+
72
+ await editJson(join(moduleSettings.targetFolder, 'jsconfig.json'), ['compilerOptions', 'exclude'], [moduleSettings.settings.wixSettings.compilerOptions, moduleSettings.settings.wixSettings.exclude]);
73
+ await editJson(join(moduleSettings.targetFolder, 'typedoc.json'), ['name'], [path.basename(moduleSettings.targetFolder)]);
74
+
75
+ await gitInit(moduleSettings.targetFolder, moduleSettings.settings.modules, moduleSettings.force);
76
+
77
+ moduleSettings.settings.initialized = true;
78
+
79
+ const eslintrcPath = join(moduleSettings.targetFolder, '.eslintrc.json');
80
+ if(existsSync(eslintrcPath)) {
81
+ console.log((`🐕 ${blue.underline.bold("=> Deleting .eslintrc.json")}`));
82
+ await fs.rm(join(eslintrcPath), { recursive: false }).catch(e => {
83
+ console.log((`💩 ${red.underline.bold("=> Could not delete .eslintrc.json ")} ${red.bold("=> ", e)}`));
84
+ });
85
+ }
86
+
87
+ console.log((`🐕 ${blue.underline.bold("=> Writing settings to lucy.json")}`));
88
+ await fs.writeFile(join(moduleSettings.targetFolder, 'lucy.json'), JSON.stringify(moduleSettings.settings, null, 2));
89
+
90
+ console.log(chalk.greenBright.underline('🐶 => Initialization done!'));
91
+ }
92
+
93
+ /**
94
+ * Copy files from source to target
95
+ * @param {string} source Source folder
96
+ * @param {string} target Target folder
97
+ * @returns {Promise<void>}
98
+ */
99
+ async function copyFolder(source: string, target: string): Promise<void> {
100
+ if (!existsSync(target)){
101
+ console.log((`💩 ${red.underline.bold("=> Target folder doesn't exist =>")} ${orange(target)}`));
102
+ return;
103
+ }
104
+
105
+ try {
106
+ const files = await fsPromises.readdir(source);
107
+ for (const file of files){
108
+ const sourcePath = join(source, file);
109
+ const targetPath = join(target, file);
110
+
111
+ if (file === 'lucy.json' && existsSync(targetPath)){
112
+ continue;
113
+ }
114
+ const stats = await fsPromises.stat(sourcePath);
115
+ if (stats.isDirectory()){
116
+ if (!existsSync(file)){
117
+ mkdirSync(file);
118
+ }
119
+ await fse.copySync(sourcePath, targetPath, { overwrite: true });
120
+ } else {
121
+ fse.copySync(sourcePath, targetPath, { overwrite: true });
122
+ }
123
+ }
124
+ } catch (err){
125
+ console.log((`💩 ${red.underline.bold("=> There was an error while copying files =>")} ${orange(err)}`));
126
+ } finally {
127
+ console.log("🐕" + blue.underline.bold(' => Copy files completed!'));
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Edit Json files
133
+ * @param {string} filePath File path
134
+ * @param {string[]} keys Keys to edit
135
+ * @param {string[]} values Values to edit
136
+ * @returns {void}
137
+ */
138
+ async function editJson(filePath: string, keys: string[], values: string[] | Object[] ) {
139
+ try {
140
+ const data = await fs.readFile(filePath, 'utf8');
141
+
142
+ let jsonData;
143
+ try {
144
+ jsonData = JSON.parse(data);
145
+ } catch (parseError) {
146
+ console.log((`💩 ${red.underline.bold("=> Error parsing JSON =>")} ${orange(parseError)}`));
147
+ return;
148
+ }
149
+
150
+ for (const key of keys){
151
+ const index = keys.indexOf(key);
152
+ const value = values[index];
153
+ jsonData[key] = value;
154
+ }
155
+
156
+ const updatedJsonData = JSON.stringify(jsonData, null, 2);
157
+ await fs.writeFile(filePath, updatedJsonData, 'utf8');
158
+ } catch (err) {
159
+ console.log((`💩 ${red.underline.bold("=> Error editing JSON Data =>")} ${orange(err)}`));
160
+ } finally {
161
+ console.log("🐕" + blue.underline(` => Updated file ${orange(filePath)}`));
162
+ }
163
+ }
164
+
165
+ async function stringReplace(filePath: string, keys: string[], values: string[]) {
166
+ try {
167
+ let modifiedContent: string = '';
168
+ const data = await fs.readFile(filePath, 'utf8');
169
+
170
+ for (const key of keys){
171
+ const index = keys.indexOf(key);
172
+ const value = values[index];
173
+ const regex = new RegExp(`${key}`, 'g');
174
+ modifiedContent = data.replace(regex, `${value}`);
175
+ }
176
+
177
+ await fs.writeFile(filePath, modifiedContent, 'utf8');
178
+ } catch (err) {
179
+ console.log((`💩 ${red.underline.bold("=> During string replace =>")} ${orange(err)}`));
180
+ } finally {
181
+ console.log(blue.underline(`🐕 => Updated file ${orange(filePath)}`));
182
+ }
183
+ }
@@ -0,0 +1,35 @@
1
+ export type TSConfig = {
2
+ compilerOptions?: {
3
+ target?: string; // e.g., "ES5", "ES6", "ES2015", "ESNext"
4
+ module?: string; // e.g., "CommonJS", "ES6", "ESNext"
5
+ lib?: string[]; // e.g., ["ES2015", "DOM"]
6
+ outDir?: string;
7
+ rootDir?: string;
8
+ strict?: boolean;
9
+ esModuleInterop?: boolean;
10
+ allowJs?: boolean;
11
+ checkJs?: boolean;
12
+ declaration?: boolean;
13
+ declarationMap?: boolean;
14
+ sourceMap?: boolean;
15
+ removeComments?: boolean;
16
+ noImplicitAny?: boolean;
17
+ moduleResolution?: "node" | "classic";
18
+ resolveJsonModule?: boolean;
19
+ skipLibCheck?: boolean;
20
+ types?: string[]; // e.g., ["node", "jest"]
21
+ typeRoots?: string[]; // e.g., ["./types"]
22
+ jsx?: "preserve" | "react" | "react-jsx" | "react-jsxdev" | "react-native";
23
+ incremental?: boolean;
24
+ noEmit?: boolean;
25
+ paths?: Record<string, string[]>; // Aliases for module paths
26
+ [key: string]: any; // Allow additional compiler options
27
+ };
28
+ include?: string[]; // Glob patterns to include
29
+ exclude?: string[]; // Glob patterns to exclude
30
+ files?: string[]; // Specific files to include
31
+ extends?: string; // Path to a base tsconfig.json
32
+ references?: { path: string }[]; // Project references
33
+ compileOnSave?: boolean;
34
+ [key: string]: any; // Allow additional top-level options
35
+ };
@@ -0,0 +1,24 @@
1
+ import chalk from 'chalk';
2
+ import { ModuleSettings, ProjectSettings, blue, green, orange, red, magenta } from './index.js';
3
+ import { gitInit, installPackages } from './helpers.js';
4
+
5
+ /**
6
+ * Init Lucy project
7
+ * @param {string} cwd Current working directory
8
+ * @param {string} packageRoot Package root directory
9
+ * @returns {void}
10
+ */
11
+ export async function prepare(moduleSettings: ModuleSettings, projectSettings: ProjectSettings) {
12
+
13
+ if(!projectSettings.lucySettings?.initialized) {
14
+ console.log((`💩 ${red.underline.bold("=> This project is not initialized =>")} ${orange(moduleSettings.targetFolder)}`));
15
+ console.log("🐕" + magenta.underline(' => Use init to initialize'));
16
+ return;
17
+ }
18
+
19
+ await installPackages(projectSettings.lucySettings.wixPackages, projectSettings.lucySettings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
20
+
21
+ await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules, moduleSettings.force);
22
+
23
+ console.log(chalk.greenBright.underline('🐶 => Prepare done!'));
24
+ }
File without changes
File without changes