lucy-cli 1.2.2 → 1.2.3
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/helpers.d.ts +1 -1
- package/dist/helpers.js +38 -15
- package/dist/init.js +1 -1
- package/dist/prepare.js +1 -1
- package/files/.gitmodules +0 -0
- package/package.json +1 -1
- package/src/helpers.ts +44 -17
- package/src/init.ts +1 -1
- package/src/prepare.ts +1 -1
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,52 @@ export async function installPackages(wixPackages, devPackages, cwd, locked) {
|
|
69
69
|
console.log("🐕" + red.underline(` => Some packages failed to install!`));
|
70
70
|
}
|
71
71
|
}
|
72
|
-
|
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(`
|
75
|
-
const git = simpleGit({ baseDir: cwd });
|
94
|
+
console.log(chalk.green.underline.bold(`Processing submodule ${name}`));
|
76
95
|
try {
|
77
|
-
const
|
78
|
-
|
79
|
-
|
96
|
+
const isRegistered = await isSubmoduleRegistered(git, name);
|
97
|
+
// Check that .gitmodules exists AND contains the entry for this specific submodule.
|
98
|
+
const isConfiguredInFile = fs.existsSync(dotGitmodulesPath) &&
|
99
|
+
fs.readFileSync(dotGitmodulesPath, 'utf-8').includes(`[submodule "${name}"]`);
|
100
|
+
// Add/repair if not configured in .gitmodules, or if forced by the user.
|
101
|
+
if (!isConfiguredInFile || force) {
|
102
|
+
console.log(`🐕 ${blue.underline(`Adding/updating submodule ${name}...`)}`);
|
103
|
+
// If git already has a config entry, we must use --force to repair it.
|
104
|
+
const submoduleArgs = ['add', ...(force || isRegistered ? ['--force'] : []), repo.url, name];
|
105
|
+
await git.subModule(submoduleArgs);
|
80
106
|
}
|
81
|
-
|
82
|
-
console.log(`🐕 ${blue.underline(
|
107
|
+
else {
|
108
|
+
console.log(`🐕 ${blue.underline(`Submodule ${name} already registered. Skipping add.`)}`);
|
83
109
|
}
|
84
|
-
|
85
|
-
await
|
110
|
+
await git.submoduleUpdate(['--init', '--recursive', name]);
|
111
|
+
await simpleGit({ baseDir: path.join(cwd, name) }).checkout(repo.branch);
|
86
112
|
}
|
87
113
|
catch (err) {
|
88
|
-
console.log((`💩 ${red.underline.bold(
|
89
|
-
}
|
90
|
-
finally {
|
91
|
-
console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
|
114
|
+
console.log((`💩 ${red.underline.bold(`=> Command failed for submodule ${name} =>`)} ${orange(err)}`));
|
92
115
|
}
|
93
116
|
}
|
94
|
-
console.log("🐶" + green.underline(' => All
|
117
|
+
console.log("🐶" + green.underline(' => All modules processed!'));
|
95
118
|
}
|
96
119
|
export async function runGulp(moduleSettings, projectSettings, task) {
|
97
120
|
// Get the directory name of the current module
|
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
|
package/package.json
CHANGED
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,57 @@ export async function installPackages(wixPackages: Record<string, string>, devPa
|
|
75
75
|
}
|
76
76
|
}
|
77
77
|
|
78
|
-
|
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(`
|
81
|
-
const git = simpleGit({ baseDir: cwd });
|
104
|
+
console.log(chalk.green.underline.bold(`Processing submodule ${name}`));
|
82
105
|
|
83
106
|
try {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if
|
90
|
-
|
107
|
+
const isRegistered = await isSubmoduleRegistered(git, name);
|
108
|
+
// Check that .gitmodules exists AND contains the entry for this specific submodule.
|
109
|
+
const isConfiguredInFile = fs.existsSync(dotGitmodulesPath) &&
|
110
|
+
fs.readFileSync(dotGitmodulesPath, 'utf-8').includes(`[submodule "${name}"]`);
|
111
|
+
|
112
|
+
// Add/repair if not configured in .gitmodules, or if forced by the user.
|
113
|
+
if (!isConfiguredInFile || force) {
|
114
|
+
console.log(`🐕 ${blue.underline(`Adding/updating submodule ${name}...`)}`);
|
115
|
+
// If git already has a config entry, we must use --force to repair it.
|
116
|
+
const submoduleArgs = ['add', ...(force || isRegistered ? ['--force'] : []), repo.url, name];
|
117
|
+
await git.subModule(submoduleArgs);
|
118
|
+
} else {
|
119
|
+
console.log(`🐕 ${blue.underline(`Submodule ${name} already registered. Skipping add.`)}`);
|
91
120
|
}
|
92
121
|
|
93
|
-
|
94
|
-
await
|
122
|
+
await git.submoduleUpdate(['--init', '--recursive', name]);
|
123
|
+
await simpleGit({ baseDir: path.join(cwd, name) }).checkout(repo.branch);
|
95
124
|
} catch (err) {
|
96
|
-
console.log((`💩 ${red.underline.bold(
|
97
|
-
} finally {
|
98
|
-
console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
|
125
|
+
console.log((`💩 ${red.underline.bold(`=> Command failed for submodule ${name} =>`)} ${orange(err)}`));
|
99
126
|
}
|
100
127
|
}
|
101
|
-
console.log("🐶" + green.underline(' => All
|
128
|
+
console.log("🐶" + green.underline(' => All modules processed!'));
|
102
129
|
}
|
103
130
|
|
104
131
|
|
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
|
}
|