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
@@ -23,12 +23,7 @@ const swcOptions = {
23
23
  };
24
24
 
25
25
  export function buildBackend(options: TaskOptions) {
26
- const folders = ['typescript'];
27
- if (options.modulesSync){
28
- for (const module of Object.keys(options.modulesSync)) {
29
- folders.push(module);
30
- }
31
- }
26
+ const folders = ['typescript', ...options.modulesSourcePaths];
32
27
 
33
28
  const { outputDir } = options;
34
29
 
@@ -70,12 +65,8 @@ export function buildBackend(options: TaskOptions) {
70
65
 
71
66
 
72
67
  export function buildBackendJSW(options: TaskOptions) {
73
- const folders = ['typescript'];
74
- if (options.modulesSync){
75
- for (const module of Object.keys(options.modulesSync)) {
76
- folders.push(module);
77
- }
78
- }
68
+ const folders = ['typescript', ...options.modulesSourcePaths];
69
+
79
70
  const swcOptions = {
80
71
  jsc: {
81
72
  target: 'es6',
@@ -186,12 +186,8 @@ const customReporter: ts.reporter.Reporter = {
186
186
  };
187
187
 
188
188
  export function checkTs(options: TaskOptions) {
189
- const folders = ['typescript'];
190
- if (options.modulesSync){
191
- for (const module of Object.keys(options.modulesSync)) {
192
- folders.push(module);
193
- }
194
- }
189
+ const folders = ['typescript', ...options.modulesSourcePaths];
190
+
195
191
 
196
192
  // Create tasks for each folder
197
193
  const tasks = folders.map((folder) => {
@@ -4,12 +4,7 @@ import { TaskOptions } from '../Gulpfile';
4
4
  import { blue, orange, red } from '../index.js';
5
5
 
6
6
  export function copyFiles(options: TaskOptions) {
7
- const folders = ['typescript'];
8
- if (options.modulesSync){
9
- for (const module of Object.keys(options.modulesSync)) {
10
- folders.push(module);
11
- }
12
- }
7
+ const folders = ['typescript', ...options.modulesSourcePaths];
13
8
 
14
9
  // Create tasks for each folder
15
10
  const tasks = folders.map((folder) => {
@@ -0,0 +1,26 @@
1
+
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+
5
+ export function getModulesSync(): Record<string, string> | undefined {
6
+ const absolutePath = path.resolve('./lucy.json');
7
+ const fileContent = fs.readFileSync(absolutePath, 'utf8') as any;
8
+ return JSON.parse(fileContent).modules;
9
+ }
10
+
11
+ export function getModulesSourcePaths(): string[] {
12
+ const absolutePath = path.resolve('./lucy.json');
13
+ const fileContent = fs.readFileSync(absolutePath, 'utf8') as any;
14
+ const data = JSON.parse(fileContent).modules;
15
+ const paths: string[] = [];
16
+ for (const module of Object.keys(data)) {
17
+ if (!data[module].noCompile) {
18
+ if (data[module].path) {
19
+ paths.push(data[module].path);
20
+ } else {
21
+ paths.push(module);
22
+ }
23
+ }
24
+ }
25
+ return paths;
26
+ }
@@ -19,12 +19,7 @@ const swcOptions = {
19
19
  };
20
20
 
21
21
  export function buildPublic(options: TaskOptions) {
22
- const folders = ['typescript'];
23
- if (options.modulesSync){
24
- for (const module of Object.keys(options.modulesSync)) {
25
- folders.push(module);
26
- }
27
- }
22
+ const folders = ['typescript', ...options.modulesSourcePaths];
28
23
 
29
24
  const { outputDir } = options;
30
25
 
@@ -5,15 +5,10 @@ import { blue, orange, red } from '../index.js';
5
5
 
6
6
  export function compileScss(options: TaskOptions) {
7
7
  const folders = ['typescript'];
8
- // if (options.modulesSync){
9
- // for (const module of Object.keys(options.modulesSync)) {
10
- // folders.push(module);
11
- // }
12
- // }
13
8
 
14
9
  const { sass, outputDir} = options;
15
10
 
16
- const buildWixScss = () => gulp.src(['typescript/styles/global.scss'])
11
+ const buildWixScss = () => gulp.src(['typescript/styles/global.scss'], { allowEmpty: true })
17
12
  .pipe(sass().on('error', sass.logError))
18
13
  .on('error', function (e: Error) {
19
14
  console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange('global.scs')} failed!`));
@@ -30,7 +25,7 @@ export function compileScss(options: TaskOptions) {
30
25
  console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange('global.scs')} succeeded!`));
31
26
  });
32
27
 
33
- const buildScss = () => gulp.src(['typescript/public/scss/app.scss'])
28
+ const buildScss = () => gulp.src(['typescript/public/scss/app.scss'], { allowEmpty: true })
34
29
  .pipe(sass().on('error', sass.logError))
35
30
  .on('error', function (e: Error) {
36
31
  console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange('app.scss')} failed!`));
@@ -4,12 +4,7 @@ import exec from 'gulp-exec';
4
4
  import { blue, orange, red } from '../index.js';
5
5
 
6
6
  export function previewTemplates(options: TaskOptions) {
7
- const folders = ['typescript'];
8
- if (options.modulesSync){
9
- for (const module of Object.keys(options.modulesSync)) {
10
- folders.push(module);
11
- }
12
- }
7
+ const folders = ['typescript', ...options.modulesSourcePaths];
13
8
 
14
9
  const taskOpt = {
15
10
  continueOnError: true,
@@ -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
+ }