lucy-cli 1.2.5 → 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 (171) hide show
  1. package/dist/args.d.ts +7 -0
  2. package/dist/args.js +23 -0
  3. package/dist/commands.d.ts +3 -0
  4. package/dist/commands.js +18 -0
  5. package/dist/config.d.ts +20 -0
  6. package/dist/config.js +39 -0
  7. package/dist/error.d.ts +17 -0
  8. package/dist/error.js +5 -0
  9. package/dist/helpers.d.ts +1 -32
  10. package/dist/helpers.js +6 -261
  11. package/dist/index.d.ts +2 -59
  12. package/dist/index.js +25 -282
  13. package/dist/init.d.ts +4 -8
  14. package/dist/init.js +245 -160
  15. package/dist/params.d.ts +7 -0
  16. package/dist/params.js +23 -0
  17. package/dist/policy.d.ts +3 -0
  18. package/dist/policy.js +5 -0
  19. package/dist/prepare.d.ts +0 -8
  20. package/dist/prepare.js +20 -19
  21. package/dist/runtime.d.ts +5 -0
  22. package/dist/runtime.js +11 -0
  23. package/dist/schemas/index.d.ts +2 -0
  24. package/dist/schemas/index.js +2 -0
  25. package/dist/schemas/types.js +1 -0
  26. package/dist/states.d.ts +10 -0
  27. package/dist/states.js +7 -0
  28. package/files/expo/.env +1 -0
  29. package/files/expo/.nvmrc +1 -0
  30. package/files/expo/.prettierignore +23 -0
  31. package/files/expo/.prettierrc.json +16 -0
  32. package/files/expo/.yarnrc +1 -0
  33. package/files/expo/.yarnrc.yml +3 -0
  34. package/files/expo/app/(tabs)/_layout.tsx +45 -0
  35. package/files/expo/app/_layout.tsx +45 -0
  36. package/files/expo/babel.config.js +9 -0
  37. package/files/expo/constants/Colors.ts +27 -0
  38. package/files/expo/constants/theme.ts +18 -0
  39. package/files/expo/eas.json +26 -0
  40. package/files/expo/eslint.config.js +185 -0
  41. package/files/expo/global.css +47 -0
  42. package/files/expo/hooks/useColorScheme.ts +11 -0
  43. package/files/expo/hooks/useColorScheme.web.ts +21 -0
  44. package/files/expo/hooks/useColorSchemeRN.ts +1 -0
  45. package/files/expo/hooks/useThemeColor.ts +21 -0
  46. package/files/expo/lib/data.ts +45 -0
  47. package/files/expo/lib/utils/index.ts +6 -0
  48. package/files/expo/lib/utils/polyfills.ts +29 -0
  49. package/files/expo/lib/wix/client.ts +14 -0
  50. package/files/expo/lib/wix/index.ts +1 -0
  51. package/files/expo/lucy.json +8 -0
  52. package/files/expo/readme.md +45 -0
  53. package/files/expo/tailwind.config.js +198 -0
  54. package/files/expo/tsconfig.json +40 -0
  55. package/files/expo/types/nativewind-env.d.ts +1 -0
  56. package/files/expo/types/reset.d.ts +1 -0
  57. package/files/velo/typescript/styles/global.scss +0 -0
  58. package/package.json +14 -11
  59. package/src/args.ts +36 -0
  60. package/src/commands.ts +21 -0
  61. package/src/config.ts +61 -0
  62. package/src/error.ts +4 -0
  63. package/src/helpers.ts +7 -305
  64. package/src/index.ts +29 -369
  65. package/src/init.ts +345 -177
  66. package/src/policy.ts +6 -0
  67. package/src/prepare.ts +19 -19
  68. package/src/runtime.ts +20 -0
  69. package/src/schemas/index.ts +3 -0
  70. package/src/schemas/types.ts +0 -0
  71. package/src/states.ts +15 -0
  72. package/src copy/helpers.ts +307 -0
  73. package/src copy/index.ts +379 -0
  74. package/src copy/init.ts +183 -0
  75. package/src copy/models.ts +35 -0
  76. package/src copy/prepare.ts +24 -0
  77. package/src copy/schemas/index.ts +0 -0
  78. package/src copy/schemas/types.ts +0 -0
  79. package/src copy/settings.json +67 -0
  80. package/src copy/types.d.ts +8 -0
  81. package/dist/Gulpfile.d.ts +0 -34
  82. package/dist/Gulpfile.js +0 -115
  83. package/dist/cli.d.ts +0 -2
  84. package/dist/cli.js +0 -44
  85. package/dist/dev.d.ts +0 -2
  86. package/dist/dev.js +0 -14
  87. package/dist/gulp/backend copy.d.ts +0 -4
  88. package/dist/gulp/backend copy.js +0 -50
  89. package/dist/gulp/backend.d.ts +0 -3
  90. package/dist/gulp/backend.js +0 -91
  91. package/dist/gulp/checks.d.ts +0 -3
  92. package/dist/gulp/checks.js +0 -204
  93. package/dist/gulp/clean copy.d.ts +0 -2
  94. package/dist/gulp/clean copy.js +0 -19
  95. package/dist/gulp/clean.d.ts +0 -3
  96. package/dist/gulp/clean.js +0 -28
  97. package/dist/gulp/copy.d.ts +0 -2
  98. package/dist/gulp/copy.js +0 -33
  99. package/dist/gulp/docs.d.ts +0 -2
  100. package/dist/gulp/docs.js +0 -27
  101. package/dist/gulp/helpers.d.ts +0 -2
  102. package/dist/gulp/helpers.js +0 -24
  103. package/dist/gulp/pages copy.d.ts +0 -3
  104. package/dist/gulp/pages copy.js +0 -22
  105. package/dist/gulp/pages.d.ts +0 -2
  106. package/dist/gulp/pages.js +0 -36
  107. package/dist/gulp/pipeline.d.ts +0 -1
  108. package/dist/gulp/pipeline.js +0 -28
  109. package/dist/gulp/public.d.ts +0 -2
  110. package/dist/gulp/public.js +0 -49
  111. package/dist/gulp/styles.d.ts +0 -2
  112. package/dist/gulp/styles.js +0 -39
  113. package/dist/gulp/templates.d.ts +0 -2
  114. package/dist/gulp/templates.js +0 -32
  115. package/dist/gulp/test.d.ts +0 -2
  116. package/dist/gulp/test.js +0 -26
  117. package/dist/gulp/types.d.ts +0 -4
  118. package/dist/gulp/types.js +0 -288
  119. package/dist/gulp/watchers.d.ts +0 -9
  120. package/dist/gulp/watchers.js +0 -58
  121. package/dist/init copy.d.ts +0 -8
  122. package/dist/init copy.js +0 -167
  123. package/dist/install.d.ts +0 -2
  124. package/dist/install.js +0 -53
  125. package/dist/settings.json +0 -67
  126. package/dist/start_gulp.d.ts +0 -2
  127. package/dist/start_gulp.js +0 -14
  128. package/dist/sync.d.ts +0 -2
  129. package/dist/sync.js +0 -87
  130. /package/{files/.gitmodules → dist/schemas/types.d.ts} +0 -0
  131. /package/files/{typescript/__mocks__/.gitkeep → velo/.gitmodules} +0 -0
  132. /package/files/{.madgerc → velo/.madgerc} +0 -0
  133. /package/files/{.nvmrc → velo/.nvmrc} +0 -0
  134. /package/files/{.stylelintrc.js → velo/.stylelintrc.js} +0 -0
  135. /package/files/{.yarnrc.yml → velo/.yarnrc.yml} +0 -0
  136. /package/files/{currents.config.js → velo/currents.config.js} +0 -0
  137. /package/files/{cypress → velo/cypress}/e2e/base/base.cy.ts +0 -0
  138. /package/files/{cypress → velo/cypress}/fixtures/example.json +0 -0
  139. /package/files/{cypress → velo/cypress}/support/commands.ts +0 -0
  140. /package/files/{cypress → velo/cypress}/support/e2e.ts +0 -0
  141. /package/files/{cypress → velo/cypress}/tsconfig.json +0 -0
  142. /package/files/{cypress.config.mjs → velo/cypress.config.mjs} +0 -0
  143. /package/files/{eslint.config.mjs → velo/eslint.config.mjs} +0 -0
  144. /package/files/{local.tsconfig.json → velo/local.tsconfig.json} +0 -0
  145. /package/files/{typedoc.json → velo/typedoc.json} +0 -0
  146. /package/files/{typescript/pages → velo/typescript/__mocks__}/.gitkeep +0 -0
  147. /package/files/{typescript → velo/typescript}/backend/data.ts +0 -0
  148. /package/files/{typescript → velo/typescript}/backend/events.ts +0 -0
  149. /package/files/{typescript → velo/typescript}/backend/http-functions.ts +0 -0
  150. /package/files/{typescript → velo/typescript}/backend/lib/http-functions/sync.ts +0 -0
  151. /package/files/{typescript → velo/typescript}/backend/permissions.json +0 -0
  152. /package/files/{typescript/public → velo/typescript/pages}/.gitkeep +0 -0
  153. /package/files/{typescript/styles → velo/typescript/public}/.gitkeep +0 -0
  154. /package/files/{typescript → velo/typescript}/public/scss/app.scss +0 -0
  155. /package/files/{typescript/styles/global.scss → velo/typescript/styles/.gitkeep} +0 -0
  156. /package/files/{typescript → velo/typescript}/tsconfig.json +0 -0
  157. /package/files/{vitest.config.ts → velo/vitest.config.ts} +0 -0
  158. /package/{src → src copy}/Gulpfile.ts +0 -0
  159. /package/{src → src copy}/gulp/backend.ts +0 -0
  160. /package/{src → src copy}/gulp/checks.ts +0 -0
  161. /package/{src → src copy}/gulp/clean.ts +0 -0
  162. /package/{src → src copy}/gulp/copy.ts +0 -0
  163. /package/{src → src copy}/gulp/helpers.ts +0 -0
  164. /package/{src → src copy}/gulp/pages.ts +0 -0
  165. /package/{src → src copy}/gulp/pipeline.ts +0 -0
  166. /package/{src → src copy}/gulp/public.ts +0 -0
  167. /package/{src → src copy}/gulp/styles.ts +0 -0
  168. /package/{src → src copy}/gulp/templates.ts +0 -0
  169. /package/{src → src copy}/gulp/types.ts +0 -0
  170. /package/{src → src copy}/gulp/watchers.ts +0 -0
  171. /package/{src → src copy}/sync.ts +0 -0
@@ -0,0 +1,307 @@
1
+ import chalk from 'chalk';
2
+ import { simpleGit, SimpleGit } from 'simple-git';
3
+ import { spawnSync, exec } from 'child_process';
4
+ // https://www.sergevandenoever.nl/run-gulp4-tasks-programatically-from-node/
5
+ import path, { join } from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ import { LucySettings, ModuleSettings, ProjectSettings } from '.';
8
+ import os from 'os';
9
+ import fs, { mkdirSync } from 'fs';
10
+ import fse from 'fs-extra';
11
+ import { writeFile } from 'fs/promises';
12
+
13
+ import { blue, green, orange, red, yellow, magenta } from './index.js';
14
+
15
+ export async function installPackages(wixPackages: Record<string, string>, devPackages: Record<string, string>, cwd: string, locked: boolean ) {
16
+ if (locked) console.log("🐕" + blue.underline(` => Installing & version locked packages!`));
17
+
18
+ const wixPackageNames = Object.keys(wixPackages);
19
+ const wixPackageVersions = Object.values(wixPackages);
20
+ const wixPackageNamesAndVersions = wixPackageNames.map((name, index) => `${name}@${wixPackageVersions[index]}`);
21
+
22
+ const devPackageNames = Object.keys(devPackages);
23
+ const devPackageVersions = Object.values(devPackages);
24
+ const devPackageNamesAndVersions = devPackageNames.map((name, index) => `${name}@${devPackageVersions[index]}`);
25
+
26
+ let success = true;
27
+
28
+ // Dev packages are installed all at once with yarn.
29
+ if (devPackageNames.length > 0) {
30
+ console.log(`🐕 => Installing dev packages with yarn...`);
31
+ const packagesToInstall = locked ? devPackageNamesAndVersions.join(' ') : devPackageNames.join(' ');
32
+ const yarnAdd = `yarn add -D ${packagesToInstall}`;
33
+ const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
34
+ if (yarnRes.error) {
35
+ success = false;
36
+ console.log((`💩 ${red.underline.bold("=> Failed to install dev packages =>")} ${orange(yarnRes.error.message)}`));
37
+ } else {
38
+ console.log("🐕" + blue.underline(` => Dev packages installed!`));
39
+ }
40
+ }
41
+
42
+ // Packages are installed all at once with yarn.
43
+ if (wixPackageNames.length > 0) {
44
+ console.log(`🐕 => Installing packages with yarn...`);
45
+ const packagesToInstall = locked ? wixPackageNamesAndVersions.join(' ') : wixPackageNames.join(' ');
46
+ const yarnAdd = `yarn add ${packagesToInstall}`;
47
+ const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
48
+ if (yarnRes.error) {
49
+ success = false;
50
+ console.log((`💩 ${red.underline.bold("=> Failed to install packages =>")} ${orange(yarnRes.error.message)}`));
51
+ } else {
52
+ console.log("🐕" + blue.underline(` => Packages installed!`));
53
+ }
54
+ }
55
+
56
+ // Wix packages are installed one by one.
57
+ if (wixPackageNames.length > 0) {
58
+ wixPackageNames.forEach((name, index) => {
59
+ console.log(`🐕 => Installing wix package ${orange(name)}`);
60
+ const wixInstall = locked ? `wix install ${wixPackageNamesAndVersions[index]}`: `wix install ${name}`;
61
+ const wixres = spawnSync(wixInstall, { shell: true, stdio: 'inherit' });
62
+ if (wixres.error) {
63
+ console.log((`💩 ${red.underline.bold("=> Failed to install wix package =>")} ${orange(wixres.error.message)}`));
64
+ success = false;
65
+ } else {
66
+ console.log("🐕" + blue.underline(` => Wix package ${orange(name)} installed!`));
67
+ }
68
+ });
69
+ }
70
+
71
+ if(success) {
72
+ console.log("🐕" + blue.underline(` => All Packages installed!`));
73
+ } else {
74
+ console.log("🐕" + red.underline(` => Some packages failed to install!`));
75
+ }
76
+ }
77
+
78
+ async function isSubmoduleRegistered(git: SimpleGit, submoduleName: string): Promise<boolean> {
79
+ try {
80
+ const urlConfig = await git.getConfig(`submodule.${submoduleName}.url`);
81
+ return !!urlConfig.value;
82
+ } catch (e) {
83
+ // simple-git throws an error if the config key doesn't exist
84
+ return false;
85
+ }
86
+ }
87
+
88
+ export async function gitInit(cwd: string, modules: LucySettings['modules'] | undefined, force: boolean) {
89
+ const git = simpleGit({ baseDir: cwd });
90
+
91
+ if (!(await git.checkIsRepo())) {
92
+ console.log(chalk.yellow('Project is not a git repository. Initializing...'));
93
+ await git.init();
94
+ }
95
+
96
+ if (!modules) {
97
+ console.log(chalk.yellow('No submodules defined in settings, skipping.'));
98
+ return;
99
+ }
100
+
101
+ const dotGitmodulesPath = path.join(cwd, '.gitmodules');
102
+
103
+ for (const [name, repo] of Object.entries(modules)) {
104
+ console.log(chalk.green.underline.bold(`Processing submodule ${name}`));
105
+ const clonePath = repo.path || name;
106
+
107
+ try {
108
+ const isRegistered = await isSubmoduleRegistered(git, clonePath);
109
+ // Check that .gitmodules exists AND contains the entry for this specific submodule.
110
+ const isConfiguredInFile = fs.existsSync(dotGitmodulesPath) &&
111
+ fs.readFileSync(dotGitmodulesPath, 'utf-8').includes(`[submodule "${clonePath}"]`);
112
+
113
+ // Add/repair if not configured in .gitmodules, or if forced by the user.
114
+ if (!isConfiguredInFile || force) {
115
+ console.log(`🐕 ${blue.underline(`Adding/updating submodule ${name} at ${clonePath}...`)}`);
116
+ // If git already has a config entry, we must use --force to repair it.
117
+ const submoduleArgs = ['add', ...(force || isRegistered ? ['--force'] : []), repo.url, clonePath];
118
+ await git.subModule(submoduleArgs);
119
+ } else {
120
+ console.log(`🐕 ${blue.underline(`Submodule ${name} at ${clonePath} already registered. Skipping add.`)}`);
121
+ }
122
+
123
+ await git.submoduleUpdate(['--init', '--recursive', clonePath]);
124
+ await simpleGit({ baseDir: path.join(cwd, clonePath) }).checkout(repo.branch);
125
+ } catch (err) {
126
+ console.log((`💩 ${red.underline.bold(`=> Command failed for submodule ${name} =>`)} ${orange(err)}`));
127
+ }
128
+ }
129
+ console.log("🐶" + green.underline(' => All modules processed!'));
130
+ }
131
+
132
+
133
+ export async function runGulp(moduleSettings: ModuleSettings, projectSettings: ProjectSettings, task: string) {
134
+ // Get the directory name of the current module
135
+ const __filename = fileURLToPath(import.meta.url);
136
+ const __dirname = path.dirname(__filename);
137
+
138
+ // Resolve the path to the Gulpfile
139
+ const gulpfilePath = path.resolve(__dirname, 'Gulpfile.js');
140
+
141
+ // Dynamically import the Gulpfile
142
+ const gulpfile = await import(`file://${gulpfilePath}`);
143
+
144
+ // Check if 'dev' task exists
145
+ gulpfile.runTask(task, moduleSettings, projectSettings)
146
+ }
147
+
148
+
149
+ /**
150
+ * Clean up and run a command before exiting the process.
151
+ */
152
+ export function cleanupWatchers() {
153
+ console.log(`🧹 ${magenta.underline('Cleaning up Watchman watchers...')}`);
154
+ const cwd = process.cwd();
155
+ const command = `watchman watch-del "${cwd}"`; // Adjust for Windows paths
156
+ exec(command, (error, stdout, stderr) => {
157
+ if (error) {
158
+ console.error(`💩 ${red.underline('Failed to run cleanup:')} ${orange(error.message)}`);
159
+ return;
160
+ }
161
+ if (stderr) {
162
+ console.error(`⚠️ ${yellow.underline('Watchman stderr:')} ${stderr}`);
163
+ }
164
+ console.log(`✅ ${green.underline('Watchman cleanup success:')} ${stdout}`);
165
+ });
166
+ }
167
+
168
+ /**
169
+ * Kill all processes matching a specific substring in their command, with a fallback for Windows.
170
+ * @param {string} processPattern - The substring to match (e.g., "wix:dev" or "@wix/cli/bin/wix.cjs").
171
+ */
172
+ export function killAllProcesses(processPattern: string) {
173
+ const isWindows = os.platform() === 'win32';
174
+ const command = isWindows
175
+ ? `tasklist /FI "IMAGENAME eq node.exe" /FO CSV | findstr "${processPattern}"` // Adjust for Node.js processes
176
+ : `ps -eo pid,command | grep "${processPattern}" | grep -v grep`;
177
+
178
+ exec(command, (error, stdout, stderr) => {
179
+ if (error) {
180
+ console.error(`💩 ${red.underline('Failed to find processes:')} ${orange(error.message)}`);
181
+ return;
182
+ }
183
+ if (stderr) {
184
+ console.error(`⚠️ ${yellow.underline('Error output:')} ${stderr}`);
185
+ }
186
+ if (!stdout.trim()) {
187
+ console.log(`ℹ️ ${blue.underline(`No processes found matching pattern:`)} ${orange(processPattern)}`);
188
+ return;
189
+ }
190
+
191
+ console.log(`📝 ${magenta.underline('Found matching processes:')}\n${stdout}`);
192
+ const lines = stdout.trim().split('\n');
193
+ const pids = isWindows
194
+ ? lines.map(line => line.match(/"(\d+)"/)?.[1]) // Extract PID from Windows tasklist output
195
+ : lines.map(line => line.trim().split(/\s+/)[0]).filter(pid => !isNaN(Number(pid)));
196
+
197
+ pids.forEach(pid => {
198
+ if (!pid) return;
199
+ try {
200
+ const killCommand = isWindows
201
+ ? `taskkill /PID ${pid} /T /F` // Forcefully terminate the process on Windows
202
+ : `kill -SIGTERM ${pid}`;
203
+
204
+ exec(killCommand, (killError) => {
205
+ if (killError) {
206
+ console.error(`⚠️ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(killError.message)}`);
207
+ } else {
208
+ console.log(`✅ ${green.underline('Killed process with PID:')} ${orange(pid)}`);
209
+ }
210
+ });
211
+
212
+ // Schedule SIGKILL fallback for non-Windows platforms
213
+ if (!isWindows) {
214
+ setTimeout(() => {
215
+ try {
216
+ process.kill(parseInt(pid, 10), 'SIGKILL');
217
+ console.log(`🔪 ${red.underline('Sent SIGKILL to process with PID:')} ${orange(pid)} (fallback).`);
218
+ } catch (killError: any) {
219
+ if (killError.code === 'ESRCH') {
220
+ console.log(`✅ ${green.underline('Process with PID')} ${orange(pid)} ${green.underline('already terminated.')}`);
221
+ } else {
222
+ console.error(`⚠️ ${yellow.underline('Failed to send SIGKILL to process with PID')} ${orange(pid)}: ${red(killError.message)}`);
223
+ }
224
+ }
225
+ }, 10000);
226
+ }
227
+ } catch (err: any) {
228
+ console.error(`⚠️ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(err.message)}`);
229
+ }
230
+ });
231
+ });
232
+ }
233
+
234
+ export interface VeloSyncConfig {
235
+ siteUrl: string;
236
+ secret: string;
237
+ }
238
+ export async function saveConfig(config:VeloSyncConfig, file: string) {
239
+ await fs.promises.writeFile(file, JSON.stringify(config));
240
+ }
241
+ export async function readConfig(file: string): Promise<VeloSyncConfig> {
242
+ let content = await fs.promises.readFile(file, 'utf-8');
243
+ return JSON.parse(content);
244
+ }
245
+
246
+ export async function createTemplateFolder(moduleSettings: ModuleSettings) {
247
+ const templatesPath = join(os.homedir(), '.lucy-cli');
248
+
249
+ try {
250
+ mkdirSync(templatesPath);
251
+
252
+ const defaultTemplatePath = join(templatesPath, 'default');
253
+ mkdirSync(defaultTemplatePath);
254
+
255
+ const sourceFilesPath = join(moduleSettings.packageRoot, 'files');
256
+ const defaultTemplateFilesPath = join(defaultTemplatePath, 'files');
257
+ await fse.copy(sourceFilesPath, defaultTemplateFilesPath);
258
+
259
+ const defaultTemplateSettingsPath = join(defaultTemplatePath, 'settings.json');
260
+ await writeFile(defaultTemplateSettingsPath, JSON.stringify(moduleSettings.settings, null, 2));
261
+
262
+ console.log(green('✅ Default template created successfully!'));
263
+ } catch (e) {
264
+ console.log((`💩 ${red.underline.bold("=> Error creating default template =>")} ${orange(e)}`));
265
+ return;
266
+ }
267
+ }
268
+
269
+ export type PackageJson = {
270
+ dependencies?: Record<string, string>;
271
+ devDependencies?: Record<string, string>;
272
+ [key: string]: any;
273
+ }
274
+
275
+ /**
276
+ * Updates a lucy.json file with dependencies from a package.json file.
277
+ * It replaces 'wixPackages' with 'dependencies' and 'devPackages' with 'devDependencies'.
278
+ * @param {string} packageJsonPath - Path to the package.json file.
279
+ * @param {string} lucyConfigPath - Path to the lucy.json file.
280
+ */
281
+ export async function updateLucyConfigFromPackageJson(packageJsonPath: string, lucyConfigPath: string): Promise<void> {
282
+ try {
283
+ console.log(`🐕 Reading package definitions from ${orange(packageJsonPath)}...`);
284
+ const pkgJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
285
+ const packageJson: PackageJson = JSON.parse(pkgJsonContent);
286
+
287
+ console.log(`🐕 Reading Lucy configuration from ${orange(lucyConfigPath)}...`);
288
+ const lucyConfigContent = await fs.promises.readFile(lucyConfigPath, 'utf-8');
289
+ const lucyConfig: LucySettings = JSON.parse(lucyConfigContent);
290
+
291
+ const { dependencies = {}, devDependencies = {} } = packageJson;
292
+
293
+ // Note: `wixPackages` are installed using `wix install`. If your `dependencies`
294
+ // contain packages that are not Wix packages, `lucy-cli install` might fail.
295
+ lucyConfig.wixPackages = dependencies;
296
+ lucyConfig.devPackages = devDependencies;
297
+
298
+ console.log(`🐕 Writing updated configuration to ${orange(lucyConfigPath)}...`);
299
+ await fs.promises.writeFile(lucyConfigPath, JSON.stringify(lucyConfig, null, 2));
300
+
301
+ console.log(green.underline('✅ Lucy configuration updated successfully!'));
302
+
303
+ } catch (error: any) {
304
+ console.error(`💩 ${red.underline.bold('=> Error updating lucy.json from package.json:')} ${orange(error.message)}`);
305
+ throw error; // re-throw to allow caller to handle
306
+ }
307
+ }
@@ -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
+ });