lucy-cli 0.7.14 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/gulp/test.js CHANGED
@@ -1,11 +1,19 @@
1
1
  import gulp from 'gulp';
2
- import { blue, red } from '../index.js';
2
+ import { blue, orange, red } from '../index.js';
3
3
  import gulpJest from 'gulp-jest';
4
4
  const jest = gulpJest.default;
5
- export function test() {
6
- return () => {
7
- return gulp.src([
8
- 'typescript/backend/**/*.spec.ts',
5
+ export function test(options) {
6
+ const folders = ['typescript'];
7
+ if (options.modulesSync) {
8
+ for (const module of Object.keys(options.modulesSync)) {
9
+ folders.push(module);
10
+ }
11
+ }
12
+ // Create tasks for each folder
13
+ const tasks = folders.map((folder) => {
14
+ const taskName = `tests-${folder}`; // Create a unique name for each task
15
+ const task = () => gulp.src([
16
+ `${folder}/backend/**/*.spec.ts`,
9
17
  ])
10
18
  .pipe(jest({
11
19
  verbose: true,
@@ -14,7 +22,7 @@ export function test() {
14
22
  '^.+\\.tsx?$': [
15
23
  'ts-jest',
16
24
  {
17
- tsconfig: './typescript/tsconfig.json',
25
+ tsconfig: `./${folder}/tsconfig.json`,
18
26
  usESM: true,
19
27
  },
20
28
  ],
@@ -23,60 +31,26 @@ export function test() {
23
31
  setupFilesAfterEnv: [],
24
32
  testEnvironment: 'node',
25
33
  collectCoverage: true,
26
- coverageDirectory: '../coverage',
27
- coverageReporters: ['clover', 'json', 'lcov', 'text'],
28
- rootDir: './typescript',
29
- testMatch: ['**/*.spec.ts'],
30
- passWithNoTests: true,
31
- moduleNameMapper: {
32
- 'public/(.*)': '<rootDir>/public/$1'
33
- }
34
- }))
35
- .on('error', function () {
36
- console.log("💩" + red.underline.bold(' => Tests failed!'));
37
- this.emit('end');
38
- })
39
- .on('end', function () {
40
- console.log("🐶" + blue.underline(' => Test succeeded!'));
41
- });
42
- };
43
- }
44
- export function testLib() {
45
- return () => {
46
- return gulp.src([
47
- 'lib/backend/**/*.spec.ts',
48
- ])
49
- .pipe(jest({
50
- verbose: true,
51
- extensionsToTreatAsEsm: ['.ts'],
52
- transform: {
53
- '^.+\\.tsx?$': [
54
- 'ts-jest',
55
- {
56
- tsconfig: './lib/tsconfig.json',
57
- usESM: true,
58
- },
59
- ],
60
- },
61
- preset: 'ts-jest',
62
- setupFilesAfterEnv: [],
63
- testEnvironment: 'node',
64
- collectCoverage: true,
65
- passWithNoTests: true,
66
34
  coverageDirectory: './coverage',
67
35
  coverageReporters: ['clover', 'json', 'lcov', 'text'],
68
- rootDir: './lib',
36
+ rootDir: `./${folder}`,
69
37
  testMatch: ['**/*.spec.ts'],
38
+ passWithNoTests: true,
70
39
  moduleNameMapper: {
71
40
  'public/(.*)': '<rootDir>/public/$1'
72
41
  }
73
42
  }))
74
43
  .on('error', function () {
75
- console.log("💩" + red.underline.bold(' => Test (LIB) failed!'));
44
+ console.log("💩" + red.underline.bold(` => Tests for ${orange(folder)} failed!`));
76
45
  this.emit('end');
77
46
  })
78
47
  .on('end', function () {
79
- console.log("🐶" + blue.underline(' => Test (LIB) succeeded!'));
48
+ console.log("🐶" + blue.underline(` => Tests for ${orange(folder)} succeeded!`));
80
49
  });
81
- };
50
+ // Register the task with Gulp
51
+ Object.defineProperty(task, 'name', { value: taskName }); // Set a unique name for debugging
52
+ return task;
53
+ });
54
+ // Run all tasks in parallel
55
+ return gulp.parallel(...tasks);
82
56
  }
@@ -105,7 +105,8 @@ export function updateWixTypes(options) {
105
105
  return stream.pipe(jeditor(publicSettings))
106
106
  .pipe(jeditor((json) => cleanTsConfig(json)))
107
107
  .pipe(jeditor((json) => processJson(json)))
108
- .pipe(replace('"../backend.d.ts",', '', replaceOptions));
108
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
109
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
109
110
  }
110
111
  if (file.dirname.endsWith('backend')) {
111
112
  return stream.pipe(jeditor(backendSettings))
@@ -117,13 +118,15 @@ export function updateWixTypes(options) {
117
118
  return stream.pipe(jeditor(masterSettings))
118
119
  .pipe(jeditor((json) => cleanTsConfig(json)))
119
120
  .pipe(jeditor((json) => processJson(json)))
120
- .pipe(replace('"../backend.d.ts",', '', replaceOptions));
121
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
122
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
121
123
  }
122
124
  ;
123
125
  return stream.pipe(jeditor(pageSettings))
124
126
  .pipe(jeditor((json) => cleanTsConfig(json)))
125
127
  .pipe(jeditor((json) => processJson(json)))
126
- .pipe(replace('"../backend.d.ts",', '', replaceOptions));
128
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
129
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
127
130
  }))
128
131
  .pipe(replace('masterPage.masterPage.js', 'masterPage.ts', replaceOptions))
129
132
  .pipe(replace('/src/', '/typescript/', replaceOptions))
@@ -1,15 +1,9 @@
1
1
  import { TaskOptions } from '../Gulpfile.js';
2
2
  export declare function watchSCSS(): import("fs").FSWatcher;
3
3
  export declare function watchBackend(): import("fs").FSWatcher;
4
- export declare function watchBackendLib(): import("fs").FSWatcher;
5
- export declare function watchJSW(): import("fs").FSWatcher;
6
- export declare function watchJSWLib(): import("fs").FSWatcher;
7
4
  export declare function watchPublic(): import("fs").FSWatcher;
8
- export declare function watchPublicLib(): import("fs").FSWatcher;
9
5
  export declare function watchPages(): import("fs").FSWatcher;
10
6
  export declare function watchFiles(): import("fs").FSWatcher;
11
- export declare function watchFilesLib(): import("fs").FSWatcher;
12
7
  export declare function watchTemplates(): import("fs").FSWatcher;
13
- export declare function watchTemplatesLib(): import("fs").FSWatcher;
14
8
  export declare function watchTypes(): import("fs").FSWatcher;
15
9
  export declare function watchAll(options: TaskOptions): import("undertaker").TaskFunction;
@@ -1,85 +1,51 @@
1
1
  import gulp from 'gulp';
2
2
  import { green } from '../index.js';
3
- import { buildBackend, buildBackendJSW, buildBackendJSWLib, buildBackendLib } from './backend.js';
4
- import { buildPublic, buildPublicLib } from './public.js';
3
+ import { buildBackend } from './backend.js';
4
+ import { buildPublic } from './public.js';
5
5
  import { buildPages } from './pages.js';
6
- import { copyFiles, copyFilesLib } from './copy.js';
7
- import { previewTemplates, previewTemplatesLib } from './templates.js';
8
- import { checkTs, checkTsLib } from './checks.js';
9
- import { testLib, test } from './test.js';
6
+ import { copyFiles } from './copy.js';
7
+ import { previewTemplates } from './templates.js';
8
+ import { checkTs } from './checks.js';
9
+ import { test } from './test.js';
10
10
  let taskOptions;
11
11
  export function watchSCSS() {
12
12
  return gulp.watch([
13
- 'typescript/styles/**/*.scss',
14
- 'lib/styles/**/*.scss'
13
+ '*/styles/**/*.scss'
15
14
  ], gulp.parallel('scss'));
16
15
  }
17
16
  export function watchBackend() {
18
17
  return gulp.watch([
19
- 'typescript/backend/**/*.ts',
20
- 'typescript/backend/**/*.tsx',
21
- '!typescript/backend/**/*.spec.ts',
22
- '!typescript/backend/**/*.jsw.ts',
23
- ], gulp.parallel(test(), checkTs(), buildBackend(taskOptions)));
24
- }
25
- export function watchBackendLib() {
26
- return gulp.watch([
27
- 'lib/backend/**/*.ts',
28
- 'lib/backend/**/*.tsx',
29
- '!lib/backend/**/*.spec.ts',
30
- '!lib/backend/**/*.jsw.ts',
31
- ], gulp.parallel(testLib(), checkTsLib(), buildBackendLib(taskOptions)));
32
- }
33
- export function watchJSW() {
34
- return gulp.watch(['typescript/backend/**/*.jsw.ts'], gulp.parallel(test(), checkTs(), buildBackendJSW(taskOptions)));
35
- }
36
- export function watchJSWLib() {
37
- return gulp.watch(['lib/backend/**/*.jsw.ts'], gulp.parallel(testLib(), checkTsLib(), buildBackendJSWLib(taskOptions)));
18
+ '*/backend/**/*.ts',
19
+ '*/backend/**/*.tsx',
20
+ '!*/backend/**/*.spec.ts',
21
+ '!*/backend/**/*.jsw.ts',
22
+ '!src/**/**',
23
+ ], gulp.parallel(test(taskOptions), checkTs(taskOptions), buildBackend(taskOptions)));
38
24
  }
39
25
  export function watchPublic() {
40
26
  return gulp.watch([
41
- 'typescript/public/**/*.ts',
42
- 'typescript/public/**/*.tsx',
43
- ], gulp.parallel(test(), checkTs(), buildPublic(taskOptions)));
44
- }
45
- export function watchPublicLib() {
46
- return gulp.watch([
47
- 'lib/public/**/*.ts',
48
- 'lib/public/**/*.tsx',
49
- ], gulp.parallel(testLib(), checkTsLib(), buildPublicLib(taskOptions)));
27
+ '*/public/**/*.ts',
28
+ '*/public/**/*.tsx',
29
+ ], gulp.parallel(test(taskOptions), checkTs(taskOptions), buildPublic(taskOptions)));
50
30
  }
51
31
  export function watchPages() {
52
- return gulp.watch('typescript/pages/**/*.ts', gulp.parallel(checkTs(), buildPages(taskOptions)));
32
+ return gulp.watch('typescript/pages/**/*.ts', gulp.parallel(checkTs(taskOptions), buildPages(taskOptions)));
53
33
  }
54
34
  export function watchFiles() {
55
35
  return gulp.watch([
56
- 'typescript/backend/**/*',
57
- 'typescript/public/**/*',
58
- 'typescript/pages/**/*',
59
- '!typescript/**/*.ts',
36
+ '*/backend/**/*',
37
+ '*/public/**/*',
38
+ '*/pages/**/*',
39
+ '!*/**/*.ts',
40
+ '!*/**/*.tsx',
60
41
  ], gulp.parallel(copyFiles(taskOptions)));
61
42
  }
62
- export function watchFilesLib() {
63
- return gulp.watch([
64
- 'lib/backend/**/*',
65
- 'lib/public/**/*',
66
- 'lib/pages/**/*',
67
- '!lib/**/*.ts',
68
- ], gulp.parallel(copyFilesLib(taskOptions)));
69
- }
70
43
  export function watchTemplates() {
71
44
  return gulp.watch([
72
- 'typescript/backend/templates/**/*.tsx',
73
- 'typescript/backend/templates/data/*.json',
74
- '!typescript/backend/templates/render.ts',
75
- ], gulp.parallel(previewTemplates(), test()));
76
- }
77
- export function watchTemplatesLib() {
78
- return gulp.watch([
79
- 'lib/backend/templates/**/*.tsx',
80
- 'lib/backend/templates/data/*.json',
81
- '!lib/backend/templates/render.ts',
82
- ], gulp.parallel(previewTemplatesLib(), testLib()));
45
+ '*/backend/templates/**/*.tsx',
46
+ '*/backend/templates/data/*.json',
47
+ '!*/backend/templates/render.ts',
48
+ ], gulp.parallel(previewTemplates(taskOptions), test(taskOptions), checkTs(taskOptions)));
83
49
  }
84
50
  export function watchTypes() {
85
51
  return gulp.watch([
@@ -90,5 +56,5 @@ export function watchTypes() {
90
56
  export function watchAll(options) {
91
57
  taskOptions = options;
92
58
  console.log("🐕" + green.underline.bold(' => Adding watchers...'));
93
- return gulp.parallel(watchSCSS, watchBackend, watchBackendLib, watchJSW, watchJSWLib, watchPublic, watchPublicLib, watchPages, watchFilesLib, watchFiles, watchTemplates, watchTemplatesLib, watchTypes);
59
+ return gulp.parallel(watchSCSS, watchBackend, watchPublic, watchPages, watchFiles, watchTemplates, watchTypes);
94
60
  }
package/dist/helpers.d.ts CHANGED
@@ -2,3 +2,7 @@ import { ModuleSettings, ProjectSettings } from '.';
2
2
  export declare function installPackages(wixPackages: Record<string, string>, devPackages: Record<string, string>, cwd: string, locked: boolean): Promise<void>;
3
3
  export declare function gitInit(cwd: string, modules: Record<string, string>): Promise<void>;
4
4
  export declare function runGulp(moduleSettings: ModuleSettings, projectSettings: ProjectSettings, task: string): Promise<void>;
5
+ /**
6
+ * Clean up and run a command before exiting the process.
7
+ */
8
+ export declare function handleExit(): void;
package/dist/helpers.js CHANGED
@@ -4,6 +4,7 @@ import { spawnSync } from 'child_process';
4
4
  // https://www.sergevandenoever.nl/run-gulp4-tasks-programatically-from-node/
5
5
  import path from 'path';
6
6
  import { fileURLToPath } from 'url';
7
+ import { exec } from 'child_process';
7
8
  import { blue, green, orange, red } from './index.js';
8
9
  export async function installPackages(wixPackages, devPackages, cwd, locked) {
9
10
  if (locked)
@@ -67,3 +68,21 @@ export async function runGulp(moduleSettings, projectSettings, task) {
67
68
  // Check if 'dev' task exists
68
69
  gulpfile.runTask(task, moduleSettings, projectSettings);
69
70
  }
71
+ /**
72
+ * Clean up and run a command before exiting the process.
73
+ */
74
+ export function handleExit() {
75
+ const cwd = process.cwd();
76
+ const command = `watchman watch-del '${cwd}'`;
77
+ console.log("🐕" + blue.underline(' => Cleaning up...'));
78
+ exec(command, (error, stdout, stderr) => {
79
+ if (error) {
80
+ console.error(`💩 Failed to run cleanup: ${error.message}`);
81
+ return;
82
+ }
83
+ if (stderr) {
84
+ console.error(`⚠️ Watchman stderr: ${stderr}`);
85
+ }
86
+ console.log(`✅ Watchman cleanup success: ${stdout}`);
87
+ });
88
+ }
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 } from './helpers.js';
12
+ import { runGulp, installPackages, handleExit } from './helpers.js';
13
13
  import { prepare } from './prepare.js';
14
14
  export const orange = chalk.hex('#FFA500');
15
15
  export const blue = chalk.blueBright;
@@ -21,6 +21,11 @@ export const magenta = chalk.magentaBright;
21
21
  const __filename = fileURLToPath(import.meta.url);
22
22
  // eslint-disable-next-line @typescript-eslint/naming-convention
23
23
  const __dirname = dirname(__filename);
24
+ process.on('SIGINT', () => {
25
+ console.log("🐕 Received Ctrl+C, cleaning up...");
26
+ handleExit();
27
+ process.exit(); // Exit the process explicitly
28
+ });
24
29
  /**
25
30
  * Main function
26
31
  * @returns {Promise<void>}
@@ -114,6 +119,7 @@ async function main() {
114
119
  }
115
120
  if (moduleSettings.args.includes('-l'))
116
121
  moduleSettings.lockVersion = true;
122
+ console.log("🐕" + magenta.underline(' => Lucy CLI => RUNNING: ' + orange('Press Ctrl+C to stop.')));
117
123
  // INFO: Run commands
118
124
  if (moduleSettings.args.includes('init')) {
119
125
  if (projectSettings.lucySettings?.initialized && !moduleSettings.force) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "lucy-cli",
4
- "version": "0.7.14",
4
+ "version": "0.8.0",
5
5
  "description": "Lucy Framework for WIX Studio Editor",
6
6
  "main": ".dist/index.js",
7
7
  "scripts": {
@@ -6,7 +6,6 @@
6
6
  "jsx": "react-jsx",
7
7
  "noEmit": false,
8
8
  "noUncheckedIndexedAccess": true,
9
- "lib": ["DOM", "ESNext"],
10
9
  "paths": {
11
10
  "backend/*.web.js": [],
12
11
  "backend/*.web": [],
@@ -7,7 +7,6 @@
7
7
  "jsx": "react-jsx",
8
8
  "noEmit": false,
9
9
  "noUncheckedIndexedAccess": true,
10
- "lib": ["DOM", "ESNext"],
11
10
  "paths": {
12
11
  "backend/*.web.js": [],
13
12
  "backend/*.web": [],
@@ -6,7 +6,6 @@
6
6
  "strict": true,
7
7
  "jsx": "react-jsx",
8
8
  "strictNullChecks": true,
9
- "lib": ["DOM", "ESNext"],
10
9
  "paths": {
11
10
  "backend/*.web.js": [],
12
11
  "backend/*.web": [],
package/src/Gulpfile.ts CHANGED
@@ -9,19 +9,20 @@ import masterSettings from '../settings/master-settings.json' assert { type: 'js
9
9
  import pageSettings from '../settings/page-settings.json' assert { type: 'json' };
10
10
  import publicSettings from '../settings/public-settings.json' assert { type: 'json' };
11
11
 
12
- import { buildPublic, buildPublicLib } from './gulp/public.js';
13
- import { buildBackend, buildBackendHTTP, buildBackendJSW, buildBackendJSWLib, buildBackendLib } from './gulp/backend.js';
14
- import { checkPages, checkTs, checkTsLib } from './gulp/checks.js';
12
+ import { buildPublic } from './gulp/public.js';
13
+ import { buildBackend, buildBackendJSW } from './gulp/backend.js';
14
+ import { checkPages, checkTs } from './gulp/checks.js';
15
15
  import { compileScss } from './gulp/styles.js';
16
16
  import { buildPages } from './gulp/pages.js';
17
- import { previewTemplates, previewTemplatesLib } from './gulp/templates.js';
18
- import { copyFiles, copyFilesLib } from './gulp/copy.js';
17
+ import { previewTemplates } from './gulp/templates.js';
18
+ import { copyFiles } from './gulp/copy.js';
19
19
  import { cleanSrc, cleanWix } from './gulp/clean.js';
20
20
  import { addTypes, updateWixTypes } from './gulp/types.js';
21
21
  import { setProdConfig } from './gulp/pipeline.js';
22
22
  import { watchAll } from './gulp/watchers.js';
23
23
  import { ModuleSettings, ProjectSettings, green, magenta, orange, red } from './index.js';
24
- import { testLib, test } from './gulp/test.js';
24
+ import { test } from './gulp/test.js';
25
+ import { getModulesSync } from './gulp/helpers.js';
25
26
 
26
27
  const sass = gulpSass(dartSass);
27
28
 
@@ -37,6 +38,7 @@ export type TaskOptions = {
37
38
  masterSettings: typeof masterSettings,
38
39
  pageSettings: typeof pageSettings,
39
40
  publicSettings: typeof publicSettings,
41
+ modulesSync: Record<string, string> | undefined;
40
42
  cwd: string;
41
43
  }
42
44
 
@@ -64,11 +66,11 @@ const taskOptions: TaskOptions = {
64
66
  masterSettings,
65
67
  replaceOptions,
66
68
  cwd: process.cwd(),
69
+ modulesSync: getModulesSync(),
67
70
  }
68
71
 
69
72
  gulp.task('check-ts', gulp.parallel(
70
- checkTs(),
71
- checkTsLib(),
73
+ checkTs(taskOptions),
72
74
  ));
73
75
 
74
76
  gulp.task('scss', gulp.parallel(
@@ -77,30 +79,24 @@ gulp.task('scss', gulp.parallel(
77
79
 
78
80
  gulp.task('build-backend', gulp.parallel(
79
81
  buildBackend(taskOptions),
80
- buildBackendLib(taskOptions),
81
82
  buildBackendJSW(taskOptions),
82
- buildBackendJSWLib(taskOptions),
83
83
  // buildBackendHTTP(taskOptions),
84
84
  ));
85
85
 
86
86
  gulp.task('build-public', gulp.parallel(
87
87
  buildPublic(taskOptions),
88
- buildPublicLib(taskOptions),
89
88
  ));
90
89
 
91
90
  gulp.task('preview-templates', gulp.parallel(
92
- previewTemplates(),
93
- previewTemplatesLib()
91
+ previewTemplates(taskOptions),
94
92
  ));
95
93
 
96
94
  gulp.task('copy-files', gulp.parallel(
97
95
  copyFiles(taskOptions),
98
- copyFilesLib(taskOptions)
99
96
  ));
100
97
 
101
98
  gulp.task('test', gulp.parallel(
102
- test(),
103
- testLib(),
99
+ test(taskOptions),
104
100
  ));
105
101
 
106
102
  gulp.task('sync-types', shell.task([
@@ -196,7 +192,7 @@ async function gulpTaskRunner(task: string) {
196
192
  }
197
193
 
198
194
  export async function runTask(task: string, moduleSettings: ModuleSettings, projectSettings: ProjectSettings) {
199
- taskOptions.cwd = moduleSettings.targetFolder;
195
+ taskOptions.cwd = moduleSettings.targetFolder;
200
196
  taskOptions.moduleSettings = moduleSettings;
201
197
  taskOptions.projectSettings = projectSettings;
202
198
  console.log("🐕" + magenta.underline(' => Starting Task => ' + orange(task)));