lucy-cli 0.8.3 → 0.9.0

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.
package/dist/Gulpfile.js CHANGED
@@ -87,6 +87,11 @@ export async function runTask(task, moduleSettings, projectSettings) {
87
87
  taskOptions.moduleSettings = moduleSettings;
88
88
  taskOptions.projectSettings = projectSettings;
89
89
  console.log("🐕" + magenta.underline(' => Starting Task => ' + orange(task)));
90
- await gulpTaskRunner(task);
90
+ try {
91
+ await gulpTaskRunner(task);
92
+ }
93
+ catch (err) {
94
+ console.log((`💩 ${red.underline.bold("=> Error starting tasks =>")} ${orange(err)}`));
95
+ }
91
96
  console.log("đŸļ" + green.underline.bold(' => Task completed: ' + task));
92
97
  }
@@ -1,8 +1,17 @@
1
1
  import gulp from 'gulp';
2
- import { createGulpEsbuild } from 'gulp-esbuild';
3
2
  import rename from 'gulp-rename';
4
3
  import * as path from 'path';
5
4
  import { blue, orange, red } from '../index.js';
5
+ import swc from 'gulp-swc';
6
+ const swcOptions = {
7
+ jsc: {
8
+ target: 'es2020',
9
+ parser: {
10
+ syntax: "typescript",
11
+ tsx: true,
12
+ },
13
+ },
14
+ };
6
15
  export function buildBackend(options) {
7
16
  const folders = ['typescript'];
8
17
  if (options.modulesSync) {
@@ -10,11 +19,7 @@ export function buildBackend(options) {
10
19
  folders.push(module);
11
20
  }
12
21
  }
13
- const { outputDir, enableIncrementalBuild } = options;
14
- const gulpEsbuild = createGulpEsbuild({
15
- incremental: enableIncrementalBuild,
16
- pipe: true,
17
- });
22
+ const { outputDir } = options;
18
23
  // Create tasks for each folder
19
24
  const tasks = folders.map((folder) => {
20
25
  const taskName = `build_Backend-${folder}`; // Create a unique name for each task
@@ -24,12 +29,17 @@ export function buildBackend(options) {
24
29
  `!${folder}/backend/**/*.jsw.ts`,
25
30
  `!${folder}/backend/**/*.spec.ts`,
26
31
  ])
27
- .pipe(gulpEsbuild({
28
- bundle: false,
29
- }))
32
+ .pipe(swc(swcOptions))
33
+ .pipe(swc(swcOptions))
34
+ .on('error', function (e) {
35
+ console.log("💩" + red.underline.bold(` => Build of Backend files for ${orange(folder)} failed!`));
36
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
37
+ this.emit('end');
38
+ })
30
39
  .pipe(gulp.dest(path.join(outputDir, 'backend')))
31
- .on('error', function () {
40
+ .on('error', function (e) {
32
41
  console.log("💩" + red.underline.bold(` => Build of Backend files for ${orange(folder)} failed!`));
42
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
33
43
  this.emit('end');
34
44
  })
35
45
  .on('end', function () {
@@ -49,24 +59,29 @@ export function buildBackendJSW(options) {
49
59
  folders.push(module);
50
60
  }
51
61
  }
52
- const { outputDir, enableIncrementalBuild } = options;
53
- const gulpEsbuild = createGulpEsbuild({
54
- incremental: enableIncrementalBuild,
55
- pipe: true,
56
- });
62
+ const swcOptions = {
63
+ jsc: {
64
+ target: 'es6',
65
+ },
66
+ };
67
+ const { outputDir } = options;
57
68
  // Create tasks for each folder
58
69
  const tasks = folders.map((folder) => {
59
70
  const taskName = `build-${folder}`; // Create a unique name for each task
60
71
  const task = () => gulp.src([
61
72
  `${folder}/backend/**/*.jsw.ts`,
62
73
  ])
63
- .pipe(gulpEsbuild({
64
- bundle: false,
65
- }))
74
+ .pipe(swc(swcOptions))
75
+ .on('error', function (e) {
76
+ console.log("💩" + red.underline.bold(` => Build of Public files for ${orange(folder)} failed!`));
77
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
78
+ this.emit('end');
79
+ })
66
80
  .pipe(rename({ extname: '' }))
67
81
  .pipe(gulp.dest(path.join(outputDir, 'backend')))
68
- .on('error', function () {
82
+ .on('error', function (e) {
69
83
  console.log("💩" + red.underline.bold(` => Build of JSW files for ${orange(folder)} failed!`));
84
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
70
85
  this.emit('end');
71
86
  })
72
87
  .on('end', function () {
@@ -128,8 +128,9 @@ export function checkTs(options) {
128
128
  const taskName = `test-${folder}`; // Create a unique name for each task
129
129
  const task = () => gulp.src([`${folder}/**/*.ts`, `!${folder}/types/**/*.ts`], { cwd: folder })
130
130
  .pipe(tsProject(ts.reporter.fullReporter()))
131
- .on('error', function () {
131
+ .on('error', function (e) {
132
132
  console.log("💩" + red.underline.bold(` => Typescriptcheck for ${orange(folder)} failed!`));
133
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
133
134
  this.emit('end');
134
135
  })
135
136
  .on('end', function () {
@@ -1,12 +1,13 @@
1
1
  import gulp from 'gulp';
2
2
  import clean from 'gulp-clean';
3
- import { blue, red } from '../index.js';
3
+ import { blue, orange, red } from '../index.js';
4
4
  export function cleanWix() {
5
5
  return () => {
6
6
  return gulp.src('./.wix', { read: false, allowEmpty: true })
7
7
  .pipe(clean({ force: true }))
8
- .on('error', function () {
8
+ .on('error', function (e) {
9
9
  console.log("💩" + red.underline.bold(' => Cleaning of .wix failed!'));
10
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
10
11
  this.emit('end');
11
12
  })
12
13
  .on('end', function () { console.log("đŸļ" + blue.underline(' => Cleaning of .wix succeeded!')); });
@@ -17,8 +18,9 @@ export function cleanSrc(options) {
17
18
  return () => {
18
19
  return gulp.src([`${outputDir}/pages`, `${outputDir}/public`, `${outputDir}/backend`], { read: false, allowEmpty: true })
19
20
  .pipe(clean({ force: true }))
20
- .on('error', function () {
21
+ .on('error', function (e) {
21
22
  console.log("💩" + red.underline.bold('Cleaning of output files failed!'));
23
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
22
24
  this.emit('end');
23
25
  })
24
26
  .on('end', function () { console.log("đŸļ" + blue.underline(' => Cleaning of .src succeeded!')); });
package/dist/gulp/copy.js CHANGED
@@ -21,8 +21,9 @@ export function copyFiles(options) {
21
21
  `!${folder}/styles/**`,
22
22
  ])
23
23
  .pipe(gulp.dest(outputDir))
24
- .on('error', function () {
24
+ .on('error', function (e) {
25
25
  console.log("💩" + red.underline.bold(` => Copy of files for ${orange(folder)} failed!`));
26
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
26
27
  this.emit('end');
27
28
  })
28
29
  .on('end', function () {
@@ -1,2 +1,2 @@
1
1
  import { TaskOptions } from '../Gulpfile';
2
- export declare function buildPages(options: TaskOptions): () => NodeJS.ReadWriteStream;
2
+ export declare function buildPages(options: TaskOptions): () => any;
@@ -1,21 +1,30 @@
1
1
  import gulp from 'gulp';
2
- import { createGulpEsbuild } from 'gulp-esbuild';
3
2
  import * as path from 'path';
4
- import { blue, red } from '../index.js';
3
+ import { blue, orange, red } from '../index.js';
4
+ import swc from 'gulp-swc';
5
+ const swcOptions = {
6
+ jsc: {
7
+ target: 'es2020',
8
+ parser: {
9
+ syntax: "typescript",
10
+ tsx: true,
11
+ },
12
+ },
13
+ };
5
14
  export function buildPages(options) {
6
- const { outputDir, enableIncrementalBuild } = options;
7
- const gulpEsbuild = createGulpEsbuild({
8
- incremental: enableIncrementalBuild, // enables the esbuild's incremental build
9
- pipe: true, // enables the esbuild's pipe mode
10
- });
15
+ const { outputDir } = options;
11
16
  return () => {
12
17
  return gulp.src('typescript/pages/*.ts')
13
- .pipe(gulpEsbuild({
14
- bundle: false,
15
- }))
18
+ .pipe(swc(swcOptions))
19
+ .on('error', function (e) {
20
+ console.log("💩" + red.underline.bold(` => Build of Pages files failed!`));
21
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
22
+ this.emit('end');
23
+ })
16
24
  .pipe(gulp.dest(path.join(outputDir, 'pages')))
17
- .on('error', function () {
25
+ .on('error', function (e) {
18
26
  console.log("💩" + red.underline.bold(' => Build of Pages TS files failed!'));
27
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
19
28
  this.emit('end');
20
29
  })
21
30
  .on('end', function () { console.log("đŸļ" + blue.underline(' => Build of Pages TS files succeeded!')); });
@@ -1,7 +1,7 @@
1
1
  import gulp from 'gulp';
2
2
  import * as path from 'path';
3
3
  import replace from 'gulp-string-replace';
4
- import { blue, red } from '../index.js';
4
+ import { blue, orange, red } from '../index.js';
5
5
  export function setProdConfig() {
6
6
  const tag = process.env.GIT_TAG || 'development';
7
7
  const regexGit = /gitTag:\s*(.*),/g;
@@ -16,8 +16,9 @@ export function setProdConfig() {
16
16
  const outputDir = path.dirname(filePath);
17
17
  return path.join(`${outputDir}/constants`);
18
18
  }))
19
- .on('error', function () {
19
+ .on('error', function (e) {
20
20
  console.log("💩" + red.underline.bold(' => Setting the git tag failed!'));
21
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
21
22
  this.emit('end');
22
23
  })
23
24
  .on('end', function () {
@@ -1,7 +1,16 @@
1
1
  import gulp from 'gulp';
2
- import { createGulpEsbuild } from 'gulp-esbuild';
3
2
  import * as path from 'path';
4
3
  import { blue, orange, red } from '../index.js';
4
+ import swc from 'gulp-swc';
5
+ const swcOptions = {
6
+ jsc: {
7
+ target: 'es2020',
8
+ parser: {
9
+ syntax: "typescript",
10
+ tsx: true,
11
+ },
12
+ },
13
+ };
5
14
  export function buildPublic(options) {
6
15
  const folders = ['typescript'];
7
16
  if (options.modulesSync) {
@@ -9,11 +18,7 @@ export function buildPublic(options) {
9
18
  folders.push(module);
10
19
  }
11
20
  }
12
- const { outputDir, enableIncrementalBuild } = options;
13
- const gulpEsbuild = createGulpEsbuild({
14
- incremental: enableIncrementalBuild,
15
- pipe: true,
16
- });
21
+ const { outputDir } = options;
17
22
  // Create tasks for each folder
18
23
  const tasks = folders.map((folder) => {
19
24
  const taskName = `build_Public-${folder}`; // Create a unique name for each task
@@ -21,15 +26,16 @@ export function buildPublic(options) {
21
26
  `${folder}/public/**/*.ts`,
22
27
  `${folder}/public/**/*.tsx`,
23
28
  ])
24
- .pipe(gulpEsbuild({
25
- bundle: false,
26
- loader: {
27
- '.tsx': 'tsx',
28
- },
29
- }))
29
+ .pipe(swc(swcOptions))
30
+ .on('error', function (e) {
31
+ console.log("💩" + red.underline.bold(` => Build of Public files for ${orange(folder)} failed!`));
32
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
33
+ this.emit('end');
34
+ })
30
35
  .pipe(gulp.dest(path.join(outputDir, 'public')))
31
- .on('error', function () {
36
+ .on('error', function (e) {
32
37
  console.log("💩" + red.underline.bold(` => Build of Public files for ${orange(folder)} failed!`));
38
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
33
39
  this.emit('end');
34
40
  })
35
41
  .on('end', function () {
@@ -13,9 +13,15 @@ export function compileScss(options) {
13
13
  const taskName = `compile_sass-${folder}`; // Create a unique name for each task
14
14
  const task = () => gulp.src(['typescript/styles/global.scss'])
15
15
  .pipe(sass().on('error', sass.logError))
16
+ .on('error', function (e) {
17
+ console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange(folder)} failed!`));
18
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
19
+ this.emit('end');
20
+ })
16
21
  .pipe(gulp.dest(`${outputDir}/styles`))
17
- .on('error', function () {
22
+ .on('error', function (e) {
18
23
  console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange(folder)} failed!`));
24
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
19
25
  this.emit('end');
20
26
  })
21
27
  .on('end', function () {
@@ -20,8 +20,9 @@ export function previewTemplates(options) {
20
20
  `!${folder}/backend/templates/render.ts`,
21
21
  ])
22
22
  .pipe(exec((file) => `npx ts-node-esm -T ${file.path}`, taskOpt))
23
- .on('error', function () {
23
+ .on('error', function (e) {
24
24
  console.log("💩" + red.underline.bold(` => Render of Template for ${orange(folder)} failed!`));
25
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
25
26
  this.emit('end');
26
27
  })
27
28
  .on('end', function () {
package/dist/gulp/test.js CHANGED
@@ -40,8 +40,9 @@ export function test(options) {
40
40
  'public/(.*)': '<rootDir>/public/$1'
41
41
  }
42
42
  }))
43
- .on('error', function () {
43
+ .on('error', function (e) {
44
44
  console.log("💩" + red.underline.bold(` => Tests for ${orange(folder)} failed!`));
45
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
45
46
  this.emit('end');
46
47
  })
47
48
  .on('end', function () {
@@ -5,7 +5,7 @@ import flatmap from 'gulp-flatmap';
5
5
  import jeditor from 'gulp-json-editor';
6
6
  import merge from 'merge-stream';
7
7
  import * as insert from 'gulp-insert';
8
- import { blue, red, yellow } from '../index.js';
8
+ import { blue, orange, red, yellow } from '../index.js';
9
9
  import tap from 'gulp-tap';
10
10
  export function updateWixTypes(options) {
11
11
  return () => {
@@ -141,7 +141,7 @@ export function updateWixTypes(options) {
141
141
  }))
142
142
  .on('error', function (e) {
143
143
  console.log("💩" + red.underline.bold('Modification of WIX configs failed!'));
144
- console.error(e);
144
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
145
145
  this.emit('end');
146
146
  })
147
147
  .on('end', function () { console.log("đŸļ" + blue.underline(`Modification of ${yellow(count)} WIX configs succeeded!`)); });
@@ -168,8 +168,8 @@ export function addTypes(options, done) {
168
168
  .pipe(gulp.dest('./.wix/types/wix-code-types/dist/types/common/'));
169
169
  return merge(processPages, processCommon, exportTypesBeta, exportTypes)
170
170
  .on('error', function (e) {
171
- console.error(e);
172
171
  console.log("💩" + red.underline.bold(' => Updating WIX failed!'));
172
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
173
173
  this.emit('end');
174
174
  done();
175
175
  })
package/dist/helpers.d.ts CHANGED
@@ -5,4 +5,9 @@ export declare function runGulp(moduleSettings: ModuleSettings, projectSettings:
5
5
  /**
6
6
  * Clean up and run a command before exiting the process.
7
7
  */
8
- export declare function handleExit(): void;
8
+ export declare function cleanupWatchers(): void;
9
+ /**
10
+ * Kill all processes matching a specific substring in their command, with a fallback for Windows.
11
+ * @param {string} processPattern - The substring to match (e.g., "wix:dev" or "@wix/cli/bin/wix.cjs").
12
+ */
13
+ export declare function killAllProcesses(processPattern: string): void;
package/dist/helpers.js CHANGED
@@ -5,7 +5,8 @@ import { spawnSync } from 'child_process';
5
5
  import path from 'path';
6
6
  import { fileURLToPath } from 'url';
7
7
  import { exec } from 'child_process';
8
- import { blue, green, orange, red } from './index.js';
8
+ import os from 'os';
9
+ import { blue, green, orange, red, yellow, magenta } from './index.js';
9
10
  export async function installPackages(wixPackages, devPackages, cwd, locked) {
10
11
  if (locked)
11
12
  console.log("🐕" + blue.underline(` => Installing & version locked packages!`));
@@ -71,18 +72,83 @@ export async function runGulp(moduleSettings, projectSettings, task) {
71
72
  /**
72
73
  * Clean up and run a command before exiting the process.
73
74
  */
74
- export function handleExit() {
75
+ export function cleanupWatchers() {
76
+ console.log(`🧹 ${magenta.underline('Cleaning up Watchman watchers...')}`);
75
77
  const cwd = process.cwd();
76
- const command = `watchman watch-del '${cwd}'`;
77
- console.log("🐕" + blue.underline(' => Cleaning up...'));
78
+ const command = `watchman watch-del "${cwd}"`; // Adjust for Windows paths
78
79
  exec(command, (error, stdout, stderr) => {
79
80
  if (error) {
80
- console.error(`💩 Failed to run cleanup: ${error.message}`);
81
+ console.error(`💩 ${red.underline('Failed to run cleanup:')} ${orange(error.message)}`);
81
82
  return;
82
83
  }
83
84
  if (stderr) {
84
- console.error(`âš ī¸ Watchman stderr: ${stderr}`);
85
+ console.error(`âš ī¸ ${yellow.underline('Watchman stderr:')} ${stderr}`);
85
86
  }
86
- console.log(`✅ Watchman cleanup success: ${stdout}`);
87
+ console.log(`✅ ${green.underline('Watchman cleanup success:')} ${stdout}`);
88
+ });
89
+ }
90
+ /**
91
+ * Kill all processes matching a specific substring in their command, with a fallback for Windows.
92
+ * @param {string} processPattern - The substring to match (e.g., "wix:dev" or "@wix/cli/bin/wix.cjs").
93
+ */
94
+ export function killAllProcesses(processPattern) {
95
+ const isWindows = os.platform() === 'win32';
96
+ const command = isWindows
97
+ ? `tasklist /FI "IMAGENAME eq node.exe" /FO CSV | findstr "${processPattern}"` // Adjust for Node.js processes
98
+ : `ps -eo pid,command | grep "${processPattern}" | grep -v grep`;
99
+ exec(command, (error, stdout, stderr) => {
100
+ if (error) {
101
+ console.error(`💩 ${red.underline('Failed to find processes:')} ${orange(error.message)}`);
102
+ return;
103
+ }
104
+ if (stderr) {
105
+ console.error(`âš ī¸ ${yellow.underline('Error output:')} ${stderr}`);
106
+ }
107
+ if (!stdout.trim()) {
108
+ console.log(`â„šī¸ ${blue.underline(`No processes found matching pattern:`)} ${orange(processPattern)}`);
109
+ return;
110
+ }
111
+ console.log(`📝 ${magenta.underline('Found matching processes:')}\n${stdout}`);
112
+ const lines = stdout.trim().split('\n');
113
+ const pids = isWindows
114
+ ? lines.map(line => line.match(/"(\d+)"/)?.[1]) // Extract PID from Windows tasklist output
115
+ : lines.map(line => line.trim().split(/\s+/)[0]).filter(pid => !isNaN(Number(pid)));
116
+ pids.forEach(pid => {
117
+ if (!pid)
118
+ return;
119
+ try {
120
+ const killCommand = isWindows
121
+ ? `taskkill /PID ${pid} /T /F` // Forcefully terminate the process on Windows
122
+ : `kill -SIGTERM ${pid}`;
123
+ exec(killCommand, (killError) => {
124
+ if (killError) {
125
+ console.error(`âš ī¸ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(killError.message)}`);
126
+ }
127
+ else {
128
+ console.log(`✅ ${green.underline('Killed process with PID:')} ${orange(pid)}`);
129
+ }
130
+ });
131
+ // Schedule SIGKILL fallback for non-Windows platforms
132
+ if (!isWindows) {
133
+ setTimeout(() => {
134
+ try {
135
+ process.kill(parseInt(pid, 10), 'SIGKILL');
136
+ console.log(`đŸ”Ē ${red.underline('Sent SIGKILL to process with PID:')} ${orange(pid)} (fallback).`);
137
+ }
138
+ catch (killError) {
139
+ if (killError.code === 'ESRCH') {
140
+ console.log(`✅ ${green.underline('Process with PID')} ${orange(pid)} ${green.underline('already terminated.')}`);
141
+ }
142
+ else {
143
+ console.error(`âš ī¸ ${yellow.underline('Failed to send SIGKILL to process with PID')} ${orange(pid)}: ${red(killError.message)}`);
144
+ }
145
+ }
146
+ }, 10000);
147
+ }
148
+ }
149
+ catch (err) {
150
+ console.error(`âš ī¸ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(err.message)}`);
151
+ }
152
+ });
87
153
  });
88
154
  }
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { join } from 'path';
9
9
  import fs from 'fs/promises';
10
10
  import { init } from './init.js';
11
11
  import { sync } from './sync.js';
12
- import { runGulp, installPackages, handleExit } from './helpers.js';
12
+ import { runGulp, installPackages, killAllProcesses, cleanupWatchers } from './helpers.js';
13
13
  import { prepare } from './prepare.js';
14
14
  import { spawnSync } from 'child_process';
15
15
  export const orange = chalk.hex('#FFA500');
@@ -22,10 +22,45 @@ export const magenta = chalk.magentaBright;
22
22
  const __filename = fileURLToPath(import.meta.url);
23
23
  // eslint-disable-next-line @typescript-eslint/naming-convention
24
24
  const __dirname = dirname(__filename);
25
+ // const cwd = process.cwd();
26
+ // const command = `watchman watch-del '${cwd}'`;
27
+ // killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
28
+ // killAllProcesses('wix:dev');
29
+ process.on('exit', (code) => {
30
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
31
+ killAllProcesses('wix:dev');
32
+ cleanupWatchers();
33
+ console.log(`đŸšĒ ${magenta.underline('Process exiting with code:')} ${orange(code)}`);
34
+ });
25
35
  process.on('SIGINT', () => {
26
- console.log("🐕 Received Ctrl+C, cleaning up...");
27
- handleExit();
28
- process.exit(); // Exit the process explicitly
36
+ console.log(`🐕 ${green.underline('Received Ctrl+C (SIGINT), cleaning up...')}`);
37
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
38
+ killAllProcesses('wix:dev');
39
+ cleanupWatchers();
40
+ process.exit(); // Exit explicitly after handling
41
+ });
42
+ process.on('SIGTERM', () => {
43
+ console.log(`🛑 ${red.underline('Received termination signal (SIGTERM), cleaning up...')}`);
44
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
45
+ killAllProcesses('wix:dev');
46
+ cleanupWatchers();
47
+ process.exit(); // Exit explicitly after handling
48
+ });
49
+ process.on('uncaughtException', (error) => {
50
+ console.error(`đŸ’Ĩ ${red.underline('Uncaught Exception:')}`, error);
51
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
52
+ killAllProcesses('wix:dev');
53
+ cleanupWatchers();
54
+ process.exit(1); // Exit with an error code
55
+ });
56
+ process.on('unhandledRejection', (reason, promise) => {
57
+ console.error(`🚨 ${yellow.underline('Unhandled Rejection at:')} ${orange(promise)}`);
58
+ console.error(`🚨 ${red.underline('Reason:')} ${reason}`);
59
+ cleanupWatchers();
60
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
61
+ killAllProcesses('wix:dev');
62
+ cleanupWatchers();
63
+ process.exit(1); // Exit with an error code
29
64
  });
30
65
  /**
31
66
  * Main function
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "lucy-cli",
4
- "version": "0.8.3",
4
+ "version": "0.9.0",
5
5
  "description": "Lucy Framework for WIX Studio Editor",
6
6
  "main": ".dist/index.js",
7
7
  "scripts": {
@@ -32,6 +32,7 @@
32
32
  "registry": "https://registry.npmjs.org"
33
33
  },
34
34
  "dependencies": {
35
+ "@swc/core": "^1.9.3",
35
36
  "@wix/cli": "^1.0.83",
36
37
  "@wix/eslint-plugin-cli": "^1.0.1",
37
38
  "chalk": "^5.3.0",
@@ -41,20 +42,21 @@
41
42
  "gulp-clean": "^0.4.0",
42
43
  "gulp-cli": "3.0.0",
43
44
  "gulp-concat": "^2.6.1",
44
- "gulp-esbuild": "0.12.1",
45
45
  "gulp-exec": "^5.0.0",
46
46
  "gulp-flatmap": "^1.0.2",
47
47
  "gulp-if": "^3.0.0",
48
48
  "gulp-insert": "^0.5.0",
49
49
  "gulp-jest": "^4.0.4",
50
50
  "gulp-json-editor": "2.6.0",
51
+ "gulp-plumber": "^1.2.1",
51
52
  "gulp-rename": "^2.0.0",
52
53
  "gulp-sass": "^5.1.0",
53
54
  "gulp-shell": "^0.8.0",
54
55
  "gulp-string-replace": "^1.1.2",
56
+ "gulp-swc": "^2.2.0",
55
57
  "gulp-tap": "^2.0.0",
56
58
  "gulp-typedoc": "^3.0.2",
57
- "gulp-typescript": "^6.0.0-alpha.1",
59
+ "gulp-typescript": "5.0.1",
58
60
  "gulp-wait": "^0.0.2",
59
61
  "jest": "^29.7.0",
60
62
  "merge-stream": "^2.0.0",
@@ -75,6 +77,7 @@
75
77
  "@types/gulp-concat": "^0.0.37",
76
78
  "@types/gulp-insert": "^0.5.13",
77
79
  "@types/gulp-json-editor": "^2.2.36",
80
+ "@types/gulp-plumber": "^0.0.37",
78
81
  "@types/gulp-rename": "^2.0.6",
79
82
  "@types/gulp-sass": "^5.0.4",
80
83
  "@types/gulp-tap": "^1.0.5",
@@ -84,13 +87,12 @@
84
87
  "@typescript-eslint/eslint-plugin": "8.14.0",
85
88
  "@typescript-eslint/parser": "8.14.0",
86
89
  "@typescript-eslint/utils": "8.14.0",
87
- "esbuild": "0.24.0",
88
90
  "eslint": "9.14.0",
89
91
  "eslint-plugin-import": "^2.27.5",
90
92
  "eslint-plugin-jsdoc": "50.5.0",
91
93
  "eslint-plugin-named-import-spacing": "^1.0.3",
92
94
  "eslint-plugin-simple-import-sort": "12.1.1",
93
95
  "ts-node": "^10.9.1",
94
- "typescript": "^5.1.6"
96
+ "typescript": "^5.6.3"
95
97
  }
96
98
  }
package/src/Gulpfile.ts CHANGED
@@ -133,7 +133,7 @@ gulp.task('fix-wix', gulp.series(
133
133
  gulp.task('build', gulp.parallel(
134
134
  'build-backend',
135
135
  'build-public',
136
- buildPages(taskOptions),
136
+ buildPages(taskOptions),
137
137
  compileScss(taskOptions),
138
138
  'copy-files'
139
139
  )
@@ -196,6 +196,10 @@ export async function runTask(task: string, moduleSettings: ModuleSettings, proj
196
196
  taskOptions.moduleSettings = moduleSettings;
197
197
  taskOptions.projectSettings = projectSettings;
198
198
  console.log("🐕" + magenta.underline(' => Starting Task => ' + orange(task)));
199
+ try {
199
200
  await gulpTaskRunner(task);
201
+ } catch (err) {
202
+ console.log((`💩 ${red.underline.bold("=> Error starting tasks =>")} ${orange(err)}`));
203
+ }
200
204
  console.log("đŸļ" + green.underline.bold(' => Task completed: ' + task));
201
205
  }
@@ -1,9 +1,20 @@
1
1
  import gulp from 'gulp';
2
- import { createGulpEsbuild } from 'gulp-esbuild';
3
2
  import rename from 'gulp-rename';
4
3
  import * as path from 'path';
5
4
  import { TaskOptions } from '../Gulpfile';
6
5
  import { blue, orange, red } from '../index.js';
6
+ import swc from 'gulp-swc';
7
+ import { cond } from 'cypress/types/lodash';
8
+
9
+ const swcOptions = {
10
+ jsc: {
11
+ target: 'es2020',
12
+ parser: {
13
+ syntax: "typescript",
14
+ tsx: true,
15
+ },
16
+ },
17
+ };
7
18
 
8
19
  export function buildBackend(options: TaskOptions) {
9
20
  const folders = ['typescript'];
@@ -13,11 +24,7 @@ export function buildBackend(options: TaskOptions) {
13
24
  }
14
25
  }
15
26
 
16
- const { outputDir, enableIncrementalBuild } = options;
17
- const gulpEsbuild = createGulpEsbuild({
18
- incremental: enableIncrementalBuild,
19
- pipe: true,
20
- });
27
+ const { outputDir } = options;
21
28
 
22
29
  // Create tasks for each folder
23
30
  const tasks = folders.map((folder) => {
@@ -30,14 +37,17 @@ export function buildBackend(options: TaskOptions) {
30
37
  `!${folder}/backend/**/*.jsw.ts`,
31
38
  `!${folder}/backend/**/*.spec.ts`,
32
39
  ])
33
- .pipe(
34
- gulpEsbuild({
35
- bundle: false,
36
- })
37
- )
40
+ .pipe(swc(swcOptions))
41
+ .pipe(swc(swcOptions))
42
+ .on('error', function (e: Error) {
43
+ console.log("💩" + red.underline.bold(` => Build of Backend files for ${orange(folder)} failed!`));
44
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
45
+ this.emit('end');
46
+ })
38
47
  .pipe(gulp.dest(path.join(outputDir, 'backend')))
39
- .on('error', function () {
48
+ .on('error', function (e: Error) {
40
49
  console.log("💩" + red.underline.bold(` => Build of Backend files for ${orange(folder)} failed!`));
50
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
41
51
  this.emit('end');
42
52
  })
43
53
  .on('end', function () {
@@ -61,12 +71,12 @@ export function buildBackendJSW(options: TaskOptions) {
61
71
  folders.push(module);
62
72
  }
63
73
  }
64
-
65
- const { outputDir, enableIncrementalBuild } = options;
66
- const gulpEsbuild = createGulpEsbuild({
67
- incremental: enableIncrementalBuild,
68
- pipe: true,
69
- });
74
+ const swcOptions = {
75
+ jsc: {
76
+ target: 'es6',
77
+ },
78
+ };
79
+ const { outputDir } = options;
70
80
 
71
81
  // Create tasks for each folder
72
82
  const tasks = folders.map((folder) => {
@@ -76,20 +86,22 @@ export function buildBackendJSW(options: TaskOptions) {
76
86
  gulp.src([
77
87
  `${folder}/backend/**/*.jsw.ts`,
78
88
  ])
79
- .pipe(
80
- gulpEsbuild({
81
- bundle: false,
82
- })
83
- )
84
- .pipe(rename({ extname: '' }))
85
- .pipe(gulp.dest(path.join(outputDir, 'backend')))
86
- .on('error', function () {
87
- console.log("💩" + red.underline.bold(` => Build of JSW files for ${orange(folder)} failed!`));
88
- this.emit('end');
89
- })
90
- .on('end', function () {
91
- console.log("đŸļ" + blue.underline(` => Build of JSW files for ${orange(folder)} succeeded!`));
92
- });
89
+ .pipe(swc(swcOptions))
90
+ .on('error', function (e: Error) {
91
+ console.log("💩" + red.underline.bold(` => Build of Public files for ${orange(folder)} failed!`));
92
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
93
+ this.emit('end');
94
+ })
95
+ .pipe(rename({ extname: '' }))
96
+ .pipe(gulp.dest(path.join(outputDir, 'backend')))
97
+ .on('error', function (e: Error) {
98
+ console.log("💩" + red.underline.bold(` => Build of JSW files for ${orange(folder)} failed!`));
99
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
100
+ this.emit('end');
101
+ })
102
+ .on('end', function () {
103
+ console.log("đŸļ" + blue.underline(` => Build of JSW files for ${orange(folder)} succeeded!`));
104
+ });
93
105
 
94
106
  // Register the task with Gulp
95
107
  Object.defineProperty(task, 'name', { value: taskName }); // Set a unique name for debugging
@@ -136,8 +136,9 @@ export function checkTs(options: TaskOptions) {
136
136
  const task = () =>
137
137
  gulp.src([`${folder}/**/*.ts`, `!${folder}/types/**/*.ts`], { cwd: folder })
138
138
  .pipe(tsProject(ts.reporter.fullReporter()))
139
- .on('error', function () {
139
+ .on('error', function (e: Error) {
140
140
  console.log("💩" + red.underline.bold(` => Typescriptcheck for ${orange(folder)} failed!`));
141
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
141
142
  this.emit('end');
142
143
  })
143
144
  .on('end', function () {
package/src/gulp/clean.ts CHANGED
@@ -2,14 +2,15 @@ import chalk from 'chalk';
2
2
  import gulp from 'gulp';
3
3
  import { TaskOptions } from '../Gulpfile';
4
4
  import clean from 'gulp-clean';
5
- import { blue, red } from '../index.js';
5
+ import { blue, orange, red } from '../index.js';
6
6
 
7
7
  export function cleanWix() {
8
8
  return () => {
9
9
  return gulp.src('./.wix', { read: false, allowEmpty: true })
10
10
  .pipe(clean({ force: true }))
11
- .on('error', function () {
11
+ .on('error', function (e: Error) {
12
12
  console.log("💩" + red.underline.bold(' => Cleaning of .wix failed!'));
13
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
13
14
  this.emit('end');
14
15
  })
15
16
  .on('end', function() { console.log("đŸļ" + blue.underline(' => Cleaning of .wix succeeded!')); });
@@ -22,8 +23,9 @@ export function cleanSrc(options: TaskOptions) {
22
23
  return () => {
23
24
  return gulp.src([`${outputDir}/pages`, `${outputDir}/public`, `${outputDir}/backend`], { read: false, allowEmpty: true })
24
25
  .pipe(clean({ force: true }))
25
- .on('error', function () {
26
+ .on('error', function (e: Error) {
26
27
  console.log("💩" + red.underline.bold('Cleaning of output files failed!'));
28
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
27
29
  this.emit('end');
28
30
  })
29
31
  .on('end', function() { console.log("đŸļ" + blue.underline(' => Cleaning of .src succeeded!')); });
package/src/gulp/copy.ts CHANGED
@@ -28,8 +28,9 @@ export function copyFiles(options: TaskOptions) {
28
28
  `!${folder}/styles/**`,
29
29
  ])
30
30
  .pipe(gulp.dest(outputDir))
31
- .on('error', function () {
31
+ .on('error', function (e: Error) {
32
32
  console.log("💩" + red.underline.bold(` => Copy of files for ${orange(folder)} failed!`));
33
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
33
34
  this.emit('end');
34
35
  })
35
36
  .on('end', function () {
package/src/gulp/pages.ts CHANGED
@@ -1,26 +1,36 @@
1
1
  import gulp from 'gulp';
2
2
  import { TaskOptions } from '../Gulpfile';
3
- import { createGulpEsbuild } from 'gulp-esbuild';
4
3
  import * as path from 'path';
5
- import { blue, red } from '../index.js';
4
+ import { blue, orange, red } from '../index.js';
5
+ import swc from 'gulp-swc';
6
+
7
+ const swcOptions = {
8
+ jsc: {
9
+ target: 'es2020',
10
+ parser: {
11
+ syntax: "typescript",
12
+ tsx: true,
13
+ },
14
+ },
15
+ };
6
16
 
7
17
  export function buildPages(options: TaskOptions) {
8
- const { outputDir, enableIncrementalBuild} = options;
9
- const gulpEsbuild = createGulpEsbuild({
10
- incremental: enableIncrementalBuild, // enables the esbuild's incremental build
11
- pipe: true, // enables the esbuild's pipe mode
12
- });
18
+ const { outputDir} = options;
13
19
 
14
20
  return () => {
15
21
  return gulp.src('typescript/pages/*.ts')
16
- .pipe(gulpEsbuild({
17
- bundle: false,
18
- }))
19
- .pipe(gulp.dest(path.join(outputDir, 'pages')))
20
- .on('error', function () {
21
- console.log("💩" + red.underline.bold(' => Build of Pages TS files failed!'));
22
- this.emit('end');
23
- })
24
- .on('end', function() { console.log("đŸļ" + blue.underline(' => Build of Pages TS files succeeded!')); });
22
+ .pipe(swc(swcOptions))
23
+ .on('error', function (e: Error) {
24
+ console.log("💩" + red.underline.bold(` => Build of Pages files failed!`));
25
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
26
+ this.emit('end');
27
+ })
28
+ .pipe(gulp.dest(path.join(outputDir, 'pages')))
29
+ .on('error', function (e: Error) {
30
+ console.log("💩" + red.underline.bold(' => Build of Pages TS files failed!'));
31
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
32
+ this.emit('end');
33
+ })
34
+ .on('end', function() { console.log("đŸļ" + blue.underline(' => Build of Pages TS files succeeded!')); });
25
35
  };
26
36
  }
@@ -2,7 +2,7 @@ import gulp from 'gulp';
2
2
  import * as path from 'path';
3
3
  import { File } from '../Gulpfile';
4
4
  import replace from 'gulp-string-replace';
5
- import { blue, red } from '../index.js';
5
+ import { blue, orange, red } from '../index.js';
6
6
 
7
7
  export function setProdConfig() {
8
8
  const tag = process.env.GIT_TAG || 'development';
@@ -20,8 +20,9 @@ export function setProdConfig() {
20
20
 
21
21
  return path.join(`${outputDir}/constants`);
22
22
  }))
23
- .on('error', function () {
23
+ .on('error', function (e: Error) {
24
24
  console.log("💩" + red.underline.bold(' => Setting the git tag failed!'));
25
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
25
26
  this.emit('end');
26
27
  })
27
28
  .on('end', function() { console.log("đŸļ" + blue.underline(' => Setting the git tag succeeded!'));
@@ -1,9 +1,18 @@
1
1
  import gulp from 'gulp';
2
- import { createGulpEsbuild } from 'gulp-esbuild';
3
-
4
2
  import * as path from 'path';
5
3
  import { TaskOptions } from '../Gulpfile';
6
4
  import { blue, orange, red } from '../index.js';
5
+ import swc from 'gulp-swc';
6
+
7
+ const swcOptions = {
8
+ jsc: {
9
+ target: 'es2020',
10
+ parser: {
11
+ syntax: "typescript",
12
+ tsx: true,
13
+ },
14
+ },
15
+ };
7
16
 
8
17
  export function buildPublic(options: TaskOptions) {
9
18
  const folders = ['typescript'];
@@ -13,11 +22,7 @@ export function buildPublic(options: TaskOptions) {
13
22
  }
14
23
  }
15
24
 
16
- const { outputDir, enableIncrementalBuild } = options;
17
- const gulpEsbuild = createGulpEsbuild({
18
- incremental: enableIncrementalBuild,
19
- pipe: true,
20
- });
25
+ const { outputDir } = options;
21
26
 
22
27
  // Create tasks for each folder
23
28
  const tasks = folders.map((folder) => {
@@ -28,15 +33,16 @@ export function buildPublic(options: TaskOptions) {
28
33
  `${folder}/public/**/*.ts`,
29
34
  `${folder}/public/**/*.tsx`,
30
35
  ])
31
- .pipe(gulpEsbuild({
32
- bundle: false,
33
- loader: {
34
- '.tsx': 'tsx',
35
- },
36
- }))
37
- .pipe(gulp.dest(path.join(outputDir, 'public')))
38
- .on('error', function () {
36
+ .pipe(swc(swcOptions))
37
+ .on('error', function (e: Error) {
38
+ console.log("💩" + red.underline.bold(` => Build of Public files for ${orange(folder)} failed!`));
39
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
40
+ this.emit('end');
41
+ })
42
+ .pipe(gulp.dest(path.join(outputDir, 'public')))
43
+ .on('error', function (e: Error) {
39
44
  console.log("💩" + red.underline.bold(` => Build of Public files for ${orange(folder)} failed!`));
45
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
40
46
  this.emit('end');
41
47
  })
42
48
  .on('end', function () {
@@ -21,9 +21,15 @@ export function compileScss(options: TaskOptions) {
21
21
  const task = () =>
22
22
  gulp.src(['typescript/styles/global.scss'])
23
23
  .pipe(sass().on('error', sass.logError))
24
+ .on('error', function (e: Error) {
25
+ console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange(folder)} failed!`));
26
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
27
+ this.emit('end');
28
+ })
24
29
  .pipe(gulp.dest(`${outputDir}/styles`))
25
- .on('error', function () {
30
+ .on('error', function (e: Error) {
26
31
  console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange(folder)} failed!`));
32
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
27
33
  this.emit('end');
28
34
  })
29
35
  .on('end', function () {
@@ -25,8 +25,9 @@ export function previewTemplates(options: TaskOptions) {
25
25
  `!${folder}/backend/templates/render.ts`,
26
26
  ])
27
27
  .pipe(exec((file: File) => `npx ts-node-esm -T ${file.path}`, taskOpt))
28
- .on('error', function () {
28
+ .on('error', function (e: Error) {
29
29
  console.log("💩" + red.underline.bold(` => Render of Template for ${orange(folder)} failed!`));
30
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
30
31
  this.emit('end');
31
32
  })
32
33
  .on('end', function () {
package/src/gulp/test.ts CHANGED
@@ -44,8 +44,9 @@ export function test(options: TaskOptions) {
44
44
  'public/(.*)': '<rootDir>/public/$1'
45
45
  }
46
46
  }))
47
- .on('error', function () {
47
+ .on('error', function (e: Error) {
48
48
  console.log("💩" + red.underline.bold(` => Tests for ${orange(folder)} failed!`));
49
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
49
50
  this.emit('end');
50
51
  })
51
52
  .on('end', function () {
package/src/gulp/types.ts CHANGED
@@ -7,7 +7,7 @@ import flatmap from 'gulp-flatmap';
7
7
  import jeditor from 'gulp-json-editor';
8
8
  import merge from 'merge-stream';
9
9
  import * as insert from 'gulp-insert';
10
- import { blue, red, yellow } from '../index.js';
10
+ import { blue, orange, red, yellow } from '../index.js';
11
11
  import tap from 'gulp-tap';
12
12
  import { TSConfig } from '../models';
13
13
 
@@ -150,7 +150,7 @@ export function updateWixTypes(options: TaskOptions) {
150
150
  }))
151
151
  .on('error', function (e: Error) {
152
152
  console.log("💩" + red.underline.bold('Modification of WIX configs failed!'));
153
- console.error(e);
153
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
154
154
  this.emit('end');
155
155
  })
156
156
  .on('end', function() { console.log("đŸļ" + blue.underline(`Modification of ${yellow(count)} WIX configs succeeded!`)); });
@@ -187,8 +187,8 @@ export function addTypes(options: TaskOptions, done: gulp.TaskFunctionCallback):
187
187
  exportTypes,
188
188
  )
189
189
  .on('error', function(e: Error) {
190
- console.error(e);
191
190
  console.log("💩" + red.underline.bold(' => Updating WIX failed!'));
191
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
192
192
  this.emit('end');
193
193
  done();
194
194
  })
package/src/helpers.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import chalk from 'chalk';
2
- import { join } from 'path';
3
2
  import { simpleGit } from 'simple-git';
4
- import fs from 'fs/promises';
5
3
  import { spawnSync } from 'child_process';
6
4
  // https://www.sergevandenoever.nl/run-gulp4-tasks-programatically-from-node/
7
5
  import path from 'path';
8
6
  import { fileURLToPath } from 'url';
9
7
  import { ModuleSettings, ProjectSettings } from '.';
10
8
  import { exec } from 'child_process';
9
+ import os from 'os';
11
10
 
12
- import { blue, green, orange, red } from './index.js';
11
+ import { blue, green, orange, red, yellow, magenta } from './index.js';
13
12
 
14
13
  export async function installPackages(wixPackages: Record<string, string>, devPackages: Record<string, string>, cwd: string, locked: boolean ) {
15
14
  if (locked) console.log("🐕" + blue.underline(` => Installing & version locked packages!`));
@@ -83,19 +82,84 @@ export async function runGulp(moduleSettings: ModuleSettings, projectSettings: P
83
82
  /**
84
83
  * Clean up and run a command before exiting the process.
85
84
  */
86
- export function handleExit() {
85
+ export function cleanupWatchers() {
86
+ console.log(`🧹 ${magenta.underline('Cleaning up Watchman watchers...')}`);
87
87
  const cwd = process.cwd();
88
- const command = `watchman watch-del '${cwd}'`;
89
-
90
- console.log("🐕" + blue.underline(' => Cleaning up...'));
88
+ const command = `watchman watch-del "${cwd}"`; // Adjust for Windows paths
91
89
  exec(command, (error, stdout, stderr) => {
92
90
  if (error) {
93
- console.error(`💩 Failed to run cleanup: ${error.message}`);
91
+ console.error(`💩 ${red.underline('Failed to run cleanup:')} ${orange(error.message)}`);
94
92
  return;
95
93
  }
96
94
  if (stderr) {
97
- console.error(`âš ī¸ Watchman stderr: ${stderr}`);
95
+ console.error(`âš ī¸ ${yellow.underline('Watchman stderr:')} ${stderr}`);
98
96
  }
99
- console.log(`✅ Watchman cleanup success: ${stdout}`);
97
+ console.log(`✅ ${green.underline('Watchman cleanup success:')} ${stdout}`);
100
98
  });
101
99
  }
100
+
101
+ /**
102
+ * Kill all processes matching a specific substring in their command, with a fallback for Windows.
103
+ * @param {string} processPattern - The substring to match (e.g., "wix:dev" or "@wix/cli/bin/wix.cjs").
104
+ */
105
+ export function killAllProcesses(processPattern: string) {
106
+ const isWindows = os.platform() === 'win32';
107
+ const command = isWindows
108
+ ? `tasklist /FI "IMAGENAME eq node.exe" /FO CSV | findstr "${processPattern}"` // Adjust for Node.js processes
109
+ : `ps -eo pid,command | grep "${processPattern}" | grep -v grep`;
110
+
111
+ exec(command, (error, stdout, stderr) => {
112
+ if (error) {
113
+ console.error(`💩 ${red.underline('Failed to find processes:')} ${orange(error.message)}`);
114
+ return;
115
+ }
116
+ if (stderr) {
117
+ console.error(`âš ī¸ ${yellow.underline('Error output:')} ${stderr}`);
118
+ }
119
+ if (!stdout.trim()) {
120
+ console.log(`â„šī¸ ${blue.underline(`No processes found matching pattern:`)} ${orange(processPattern)}`);
121
+ return;
122
+ }
123
+
124
+ console.log(`📝 ${magenta.underline('Found matching processes:')}\n${stdout}`);
125
+ const lines = stdout.trim().split('\n');
126
+ const pids = isWindows
127
+ ? lines.map(line => line.match(/"(\d+)"/)?.[1]) // Extract PID from Windows tasklist output
128
+ : lines.map(line => line.trim().split(/\s+/)[0]).filter(pid => !isNaN(Number(pid)));
129
+
130
+ pids.forEach(pid => {
131
+ if (!pid) return;
132
+ try {
133
+ const killCommand = isWindows
134
+ ? `taskkill /PID ${pid} /T /F` // Forcefully terminate the process on Windows
135
+ : `kill -SIGTERM ${pid}`;
136
+
137
+ exec(killCommand, (killError) => {
138
+ if (killError) {
139
+ console.error(`âš ī¸ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(killError.message)}`);
140
+ } else {
141
+ console.log(`✅ ${green.underline('Killed process with PID:')} ${orange(pid)}`);
142
+ }
143
+ });
144
+
145
+ // Schedule SIGKILL fallback for non-Windows platforms
146
+ if (!isWindows) {
147
+ setTimeout(() => {
148
+ try {
149
+ process.kill(parseInt(pid, 10), 'SIGKILL');
150
+ console.log(`đŸ”Ē ${red.underline('Sent SIGKILL to process with PID:')} ${orange(pid)} (fallback).`);
151
+ } catch (killError: any) {
152
+ if (killError.code === 'ESRCH') {
153
+ console.log(`✅ ${green.underline('Process with PID')} ${orange(pid)} ${green.underline('already terminated.')}`);
154
+ } else {
155
+ console.error(`âš ī¸ ${yellow.underline('Failed to send SIGKILL to process with PID')} ${orange(pid)}: ${red(killError.message)}`);
156
+ }
157
+ }
158
+ }, 10000);
159
+ }
160
+ } catch (err: any) {
161
+ console.error(`âš ī¸ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(err.message)}`);
162
+ }
163
+ });
164
+ });
165
+ }
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ import fs from 'fs/promises';
11
11
 
12
12
  import { init } from './init.js';
13
13
  import { sync } from './sync.js';
14
- import { runGulp, installPackages, handleExit } from './helpers.js';
14
+ import { runGulp, installPackages, killAllProcesses, cleanupWatchers } from './helpers.js';
15
15
  import { prepare } from './prepare.js';
16
16
  import { spawnSync } from 'child_process';
17
17
 
@@ -71,10 +71,50 @@ const __filename = fileURLToPath(import.meta.url);
71
71
  // eslint-disable-next-line @typescript-eslint/naming-convention
72
72
  const __dirname = dirname(__filename);
73
73
 
74
+ // const cwd = process.cwd();
75
+ // const command = `watchman watch-del '${cwd}'`;
76
+ // killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
77
+ // killAllProcesses('wix:dev');
78
+
79
+
80
+ process.on('exit', (code) => {
81
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
82
+ killAllProcesses('wix:dev');
83
+ cleanupWatchers();
84
+ console.log(`đŸšĒ ${magenta.underline('Process exiting with code:')} ${orange(code)}`);
85
+ });
86
+
74
87
  process.on('SIGINT', () => {
75
- console.log("🐕 Received Ctrl+C, cleaning up...");
76
- handleExit();
77
- process.exit(); // Exit the process explicitly
88
+ console.log(`🐕 ${green.underline('Received Ctrl+C (SIGINT), cleaning up...')}`);
89
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
90
+ killAllProcesses('wix:dev');
91
+ cleanupWatchers();
92
+ process.exit(); // Exit explicitly after handling
93
+ });
94
+
95
+ process.on('SIGTERM', () => {
96
+ console.log(`🛑 ${red.underline('Received termination signal (SIGTERM), cleaning up...')}`);
97
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
98
+ killAllProcesses('wix:dev');
99
+ cleanupWatchers();
100
+ process.exit(); // Exit explicitly after handling
101
+ });
102
+
103
+ process.on('uncaughtException', (error) => {
104
+ console.error(`đŸ’Ĩ ${red.underline('Uncaught Exception:')}`, error);
105
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
106
+ killAllProcesses('wix:dev');
107
+ cleanupWatchers();
108
+ process.exit(1); // Exit with an error code
109
+ });
110
+
111
+ process.on('unhandledRejection', (reason, promise) => {
112
+ console.error(`🚨 ${yellow.underline('Unhandled Rejection at:')} ${orange(promise)}`);
113
+ console.error(`🚨 ${red.underline('Reason:')} ${reason}`); cleanupWatchers();
114
+ killAllProcesses('@wix/cli/bin/wix.cjs'); // Matches processes running the Wix CLI
115
+ killAllProcesses('wix:dev');
116
+ cleanupWatchers();
117
+ process.exit(1); // Exit with an error code
78
118
  });
79
119
 
80
120
  /**
package/src/types.d.ts CHANGED
@@ -4,4 +4,5 @@ declare module 'gulp-foreach';
4
4
  declare module 'gulp-string-replace';
5
5
  declare module 'gulp-wait';
6
6
  declare module 'gulp-jest';
7
- declare module 'gulp-flatmap';
7
+ declare module 'gulp-flatmap';
8
+ declare module 'gulp-swc';