lucy-cli 1.2.2 → 1.2.4

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/README.md CHANGED
@@ -59,7 +59,8 @@ Lucy-CLI is designed to streamline the setup and management of TypeScript within
59
59
  "modules": {
60
60
  "<repoName>": {
61
61
  "url": "String",
62
- "branch": "String"
62
+ "branch": "String",
63
+ "path": "String" // Optional, specifies the path where the submodule should be cloned
63
64
  }
64
65
  }
65
66
  ```
@@ -8,29 +8,37 @@ export function compileScss(options) {
8
8
  // }
9
9
  // }
10
10
  const { sass, outputDir } = options;
11
- // Create tasks for each folder
12
- const tasks = folders.map((folder) => {
13
- const taskName = `compile_sass-${folder}`; // Create a unique name for each task
14
- const task = () => gulp.src(['typescript/styles/global.scss'])
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
- })
21
- .pipe(gulp.dest(`${outputDir}/styles`))
22
- .on('error', function (e) {
23
- console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange(folder)} failed!`));
24
- console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
25
- this.emit('end');
26
- })
27
- .on('end', function () {
28
- console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange(folder)} succeeded!`));
29
- });
30
- // Register the task with Gulp
31
- Object.defineProperty(task, 'name', { value: taskName }); // Set a unique name for debugging
32
- return task;
11
+ const buildWixScss = () => gulp.src(['typescript/styles/global.scss'])
12
+ .pipe(sass().on('error', sass.logError))
13
+ .on('error', function (e) {
14
+ console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange('global.scs')} failed!`));
15
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
16
+ this.emit('end');
17
+ })
18
+ .pipe(gulp.dest(`${outputDir}/styles`))
19
+ .on('error', function (e) {
20
+ console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange('global.scs')} failed!`));
21
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
22
+ this.emit('end');
23
+ })
24
+ .on('end', function () {
25
+ console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange('global.scs')} succeeded!`));
33
26
  });
34
- // Run all tasks in parallel
35
- return gulp.parallel(...tasks);
27
+ const buildScss = () => gulp.src(['typescript/public/scss/app.scss'])
28
+ .pipe(sass().on('error', sass.logError))
29
+ .on('error', function (e) {
30
+ console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange('app.scss')} failed!`));
31
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
32
+ this.emit('end');
33
+ })
34
+ .pipe(gulp.dest(`${outputDir}/public/css`))
35
+ .on('error', function (e) {
36
+ console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange('app.scss')} failed!`));
37
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
38
+ this.emit('end');
39
+ })
40
+ .on('end', function () {
41
+ console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange('app.scss')} succeeded!`));
42
+ });
43
+ return gulp.parallel(buildWixScss, buildScss);
36
44
  }
package/dist/helpers.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LucySettings, ModuleSettings, ProjectSettings } from '.';
2
2
  export declare function installPackages(wixPackages: Record<string, string>, devPackages: Record<string, string>, cwd: string, locked: boolean): Promise<void>;
3
- export declare function gitInit(cwd: string, modules: LucySettings['modules']): Promise<void>;
3
+ export declare function gitInit(cwd: string, modules: LucySettings['modules'] | undefined, force: boolean): Promise<void>;
4
4
  export declare function runGulp(moduleSettings: ModuleSettings, projectSettings: ProjectSettings, task: string): Promise<void>;
5
5
  /**
6
6
  * Clean up and run a command before exiting the process.
package/dist/helpers.js CHANGED
@@ -69,29 +69,53 @@ export async function installPackages(wixPackages, devPackages, cwd, locked) {
69
69
  console.log("🐕" + red.underline(` => Some packages failed to install!`));
70
70
  }
71
71
  }
72
- export async function gitInit(cwd, modules) {
72
+ async function isSubmoduleRegistered(git, submoduleName) {
73
+ try {
74
+ const urlConfig = await git.getConfig(`submodule.${submoduleName}.url`);
75
+ return !!urlConfig.value;
76
+ }
77
+ catch (e) {
78
+ // simple-git throws an error if the config key doesn't exist
79
+ return false;
80
+ }
81
+ }
82
+ export async function gitInit(cwd, modules, force) {
83
+ const git = simpleGit({ baseDir: cwd });
84
+ if (!(await git.checkIsRepo())) {
85
+ console.log(chalk.yellow('Project is not a git repository. Initializing...'));
86
+ await git.init();
87
+ }
88
+ if (!modules) {
89
+ console.log(chalk.yellow('No submodules defined in settings, skipping.'));
90
+ return;
91
+ }
92
+ const dotGitmodulesPath = path.join(cwd, '.gitmodules');
73
93
  for (const [name, repo] of Object.entries(modules)) {
74
- console.log(chalk.green.underline.bold(`Cloning ${name}`));
75
- const git = simpleGit({ baseDir: cwd });
94
+ console.log(chalk.green.underline.bold(`Processing submodule ${name}`));
95
+ const clonePath = repo.path || name;
76
96
  try {
77
- const repoPath = path.resolve(cwd, name);
78
- if (!fs.existsSync(repoPath)) {
79
- await git.submoduleAdd(repo.url, name);
97
+ const isRegistered = await isSubmoduleRegistered(git, clonePath);
98
+ // Check that .gitmodules exists AND contains the entry for this specific submodule.
99
+ const isConfiguredInFile = fs.existsSync(dotGitmodulesPath) &&
100
+ fs.readFileSync(dotGitmodulesPath, 'utf-8').includes(`[submodule "${clonePath}"]`);
101
+ // Add/repair if not configured in .gitmodules, or if forced by the user.
102
+ if (!isConfiguredInFile || force) {
103
+ console.log(`🐕 ${blue.underline(`Adding/updating submodule ${name} at ${clonePath}...`)}`);
104
+ // If git already has a config entry, we must use --force to repair it.
105
+ const submoduleArgs = ['add', ...(force || isRegistered ? ['--force'] : []), repo.url, clonePath];
106
+ await git.subModule(submoduleArgs);
80
107
  }
81
- if (fs.existsSync(repoPath)) {
82
- console.log(`🐕 ${blue.underline(' => Module already cloned!')}`);
108
+ else {
109
+ console.log(`🐕 ${blue.underline(`Submodule ${name} at ${clonePath} already registered. Skipping add.`)}`);
83
110
  }
84
- const localGit = simpleGit({ baseDir: `${cwd}/${name}` });
85
- await localGit.checkout(repo.branch);
111
+ await git.submoduleUpdate(['--init', '--recursive', clonePath]);
112
+ await simpleGit({ baseDir: path.join(cwd, clonePath) }).checkout(repo.branch);
86
113
  }
87
114
  catch (err) {
88
- console.log((`💩 ${red.underline.bold("=> Command failed =>")} ${orange(err)}`));
89
- }
90
- finally {
91
- console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
115
+ console.log((`💩 ${red.underline.bold(`=> Command failed for submodule ${name} =>`)} ${orange(err)}`));
92
116
  }
93
117
  }
94
- console.log("🐶" + green.underline(' => All Modules cloned!'));
118
+ console.log("🐶" + green.underline(' => All modules processed!'));
95
119
  }
96
120
  export async function runGulp(moduleSettings, projectSettings, task) {
97
121
  // Get the directory name of the current module
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node --no-warnings
2
2
  export type LucySettings = {
3
3
  modules: {
4
- [llibName: string]: {
4
+ [libName: string]: {
5
5
  url: string;
6
6
  branch: string;
7
+ path?: string;
7
8
  };
8
9
  };
9
10
  wixSettings: {
package/dist/init.js CHANGED
@@ -59,7 +59,7 @@ export async function init(moduleSettings, projectSettings) {
59
59
  await installPackages(moduleSettings.settings.wixPackages, moduleSettings.settings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
60
60
  await editJson(join(moduleSettings.targetFolder, 'jsconfig.json'), ['compilerOptions', 'exclude'], [moduleSettings.settings.wixSettings.compilerOptions, moduleSettings.settings.wixSettings.exclude]);
61
61
  await editJson(join(moduleSettings.targetFolder, 'typedoc.json'), ['name'], [path.basename(moduleSettings.targetFolder)]);
62
- await gitInit(moduleSettings.targetFolder, moduleSettings.settings.modules);
62
+ await gitInit(moduleSettings.targetFolder, moduleSettings.settings.modules, moduleSettings.force);
63
63
  moduleSettings.settings.initialized = true;
64
64
  const eslintrcPath = join(moduleSettings.targetFolder, '.eslintrc.json');
65
65
  if (existsSync(eslintrcPath)) {
package/dist/prepare.js CHANGED
@@ -14,6 +14,6 @@ export async function prepare(moduleSettings, projectSettings) {
14
14
  return;
15
15
  }
16
16
  await installPackages(projectSettings.lucySettings.wixPackages, projectSettings.lucySettings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
17
- await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules);
17
+ await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules, moduleSettings.force);
18
18
  console.log(chalk.greenBright.underline('🐶 => Prepare done!'));
19
19
  }
File without changes
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "lucy-cli",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "description": "Lucy Framework for WIX Studio Editor",
6
6
  "main": ".dist/index.js",
7
7
  "scripts": {
@@ -13,34 +13,39 @@ export function compileScss(options: TaskOptions) {
13
13
 
14
14
  const { sass, outputDir} = options;
15
15
 
16
+ const buildWixScss = () => gulp.src(['typescript/styles/global.scss'])
17
+ .pipe(sass().on('error', sass.logError))
18
+ .on('error', function (e: Error) {
19
+ console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange('global.scs')} failed!`));
20
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
21
+ this.emit('end');
22
+ })
23
+ .pipe(gulp.dest(`${outputDir}/styles`))
24
+ .on('error', function (e: Error) {
25
+ console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange('global.scs')} failed!`));
26
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
27
+ this.emit('end');
28
+ })
29
+ .on('end', function () {
30
+ console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange('global.scs')} succeeded!`));
31
+ });
16
32
 
17
- // Create tasks for each folder
18
- const tasks = folders.map((folder) => {
19
- const taskName = `compile_sass-${folder}`; // Create a unique name for each task
20
-
21
- const task = () =>
22
- gulp.src(['typescript/styles/global.scss'])
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
- })
29
- .pipe(gulp.dest(`${outputDir}/styles`))
30
- .on('error', function (e: Error) {
31
- console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange(folder)} failed!`));
32
- console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
33
- this.emit('end');
34
- })
35
- .on('end', function () {
36
- console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange(folder)} succeeded!`));
37
- });
38
-
39
- // Register the task with Gulp
40
- Object.defineProperty(task, 'name', { value: taskName }); // Set a unique name for debugging
41
- return task;
42
- });
43
-
44
- // Run all tasks in parallel
45
- return gulp.parallel(...tasks);
33
+ const buildScss = () => gulp.src(['typescript/public/scss/app.scss'])
34
+ .pipe(sass().on('error', sass.logError))
35
+ .on('error', function (e: Error) {
36
+ console.log("💩" + red.underline.bold(` => Build of SCSS files for ${orange('app.scss')} failed!`));
37
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
38
+ this.emit('end');
39
+ })
40
+ .pipe(gulp.dest(`${outputDir}/public/css`))
41
+ .on('error', function (e: Error) {
42
+ console.log("💩" + red.underline.bold(` => Compiling of scss files for ${orange('app.scss')} failed!`));
43
+ console.log("💩" + red.underline.bold(` => Error: ${orange(e.message)}`));
44
+ this.emit('end');
45
+ })
46
+ .on('end', function () {
47
+ console.log("🐶" + blue.underline(` => Compiling of scss files for ${orange('app.scss')} succeeded!`));
48
+ });
49
+
50
+ return gulp.parallel(buildWixScss, buildScss);
46
51
  }
package/src/helpers.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { simpleGit } from 'simple-git';
2
+ import { simpleGit, SimpleGit } from 'simple-git';
3
3
  import { spawnSync, exec } from 'child_process';
4
4
  // https://www.sergevandenoever.nl/run-gulp4-tasks-programatically-from-node/
5
5
  import path, { join } from 'path';
@@ -75,30 +75,58 @@ export async function installPackages(wixPackages: Record<string, string>, devPa
75
75
  }
76
76
  }
77
77
 
78
- export async function gitInit(cwd: string, modules: LucySettings['modules']) {
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
+
79
103
  for (const [name, repo] of Object.entries(modules)) {
80
- console.log(chalk.green.underline.bold(`Cloning ${name}`));
81
- const git = simpleGit({ baseDir: cwd });
104
+ console.log(chalk.green.underline.bold(`Processing submodule ${name}`));
105
+ const clonePath = repo.path || name;
82
106
 
83
107
  try {
84
- const repoPath = path.resolve(cwd, name);
85
- if (!fs.existsSync(repoPath)) {
86
- await git.submoduleAdd(repo.url, name)
87
- }
88
-
89
- if (fs.existsSync(repoPath)) {
90
- console.log(`🐕 ${blue.underline(' => Module already cloned!')}`);
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.`)}`);
91
121
  }
92
122
 
93
- const localGit = simpleGit({ baseDir: `${cwd}/${name}` });
94
- await localGit.checkout(repo.branch);
123
+ await git.submoduleUpdate(['--init', '--recursive', clonePath]);
124
+ await simpleGit({ baseDir: path.join(cwd, clonePath) }).checkout(repo.branch);
95
125
  } catch (err) {
96
- console.log((`💩 ${red.underline.bold("=> Command failed =>")} ${orange(err)}`));
97
- } finally {
98
- console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
126
+ console.log((`💩 ${red.underline.bold(`=> Command failed for submodule ${name} =>`)} ${orange(err)}`));
99
127
  }
100
128
  }
101
- console.log("🐶" + green.underline(' => All Modules cloned!'));
129
+ console.log("🐶" + green.underline(' => All modules processed!'));
102
130
  }
103
131
 
104
132
 
package/src/index.ts CHANGED
@@ -18,9 +18,10 @@ import os from 'os';
18
18
 
19
19
  export type LucySettings = {
20
20
  modules: {
21
- [llibName: string]: {
21
+ [libName: string]: {
22
22
  url: string;
23
23
  branch: string;
24
+ path?: string;
24
25
  };
25
26
  };
26
27
  wixSettings: {
package/src/init.ts CHANGED
@@ -72,7 +72,7 @@ export async function init(moduleSettings: ModuleSettings, projectSettings: Proj
72
72
  await editJson(join(moduleSettings.targetFolder, 'jsconfig.json'), ['compilerOptions', 'exclude'], [moduleSettings.settings.wixSettings.compilerOptions, moduleSettings.settings.wixSettings.exclude]);
73
73
  await editJson(join(moduleSettings.targetFolder, 'typedoc.json'), ['name'], [path.basename(moduleSettings.targetFolder)]);
74
74
 
75
- await gitInit(moduleSettings.targetFolder, moduleSettings.settings.modules);
75
+ await gitInit(moduleSettings.targetFolder, moduleSettings.settings.modules, moduleSettings.force);
76
76
 
77
77
  moduleSettings.settings.initialized = true;
78
78
 
package/src/prepare.ts CHANGED
@@ -18,7 +18,7 @@ export async function prepare(moduleSettings: ModuleSettings, projectSettings: P
18
18
 
19
19
  await installPackages(projectSettings.lucySettings.wixPackages, projectSettings.lucySettings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
20
20
 
21
- await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules);
21
+ await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules, moduleSettings.force);
22
22
 
23
23
  console.log(chalk.greenBright.underline('🐶 => Prepare done!'));
24
24
  }