lucy-cli 1.2.4 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/args.d.ts +7 -0
- package/dist/args.js +23 -0
- package/dist/commands.d.ts +3 -0
- package/dist/commands.js +18 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +39 -0
- package/dist/error.d.ts +17 -0
- package/dist/error.js +5 -0
- package/dist/helpers.d.ts +1 -32
- package/dist/helpers.js +6 -261
- package/dist/index.d.ts +2 -52
- package/dist/index.js +25 -282
- package/dist/init.d.ts +4 -8
- package/dist/init.js +245 -160
- package/dist/params.d.ts +7 -0
- package/dist/params.js +23 -0
- package/dist/policy.d.ts +3 -0
- package/dist/policy.js +5 -0
- package/dist/prepare.d.ts +0 -8
- package/dist/prepare.js +20 -19
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.js +11 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/types.js +1 -0
- package/dist/states.d.ts +10 -0
- package/dist/states.js +7 -0
- package/files/expo/.env +1 -0
- package/files/expo/.nvmrc +1 -0
- package/files/expo/.prettierignore +23 -0
- package/files/expo/.prettierrc.json +16 -0
- package/files/expo/.yarnrc +1 -0
- package/files/expo/.yarnrc.yml +3 -0
- package/files/expo/app/(tabs)/_layout.tsx +45 -0
- package/files/expo/app/_layout.tsx +45 -0
- package/files/expo/babel.config.js +9 -0
- package/files/expo/constants/Colors.ts +27 -0
- package/files/expo/constants/theme.ts +18 -0
- package/files/expo/eas.json +26 -0
- package/files/expo/eslint.config.js +185 -0
- package/files/expo/global.css +47 -0
- package/files/expo/hooks/useColorScheme.ts +11 -0
- package/files/expo/hooks/useColorScheme.web.ts +21 -0
- package/files/expo/hooks/useColorSchemeRN.ts +1 -0
- package/files/expo/hooks/useThemeColor.ts +21 -0
- package/files/expo/lib/data.ts +45 -0
- package/files/expo/lib/utils/index.ts +6 -0
- package/files/expo/lib/utils/polyfills.ts +29 -0
- package/files/expo/lib/wix/client.ts +14 -0
- package/files/expo/lib/wix/index.ts +1 -0
- package/files/expo/lucy.json +8 -0
- package/files/expo/readme.md +45 -0
- package/files/expo/tailwind.config.js +198 -0
- package/files/expo/tsconfig.json +40 -0
- package/files/expo/types/nativewind-env.d.ts +1 -0
- package/files/expo/types/reset.d.ts +1 -0
- package/files/velo/typescript/styles/global.scss +0 -0
- package/package.json +14 -11
- package/src/args.ts +36 -0
- package/src/commands.ts +21 -0
- package/src/config.ts +61 -0
- package/src/error.ts +4 -0
- package/src/helpers.ts +7 -305
- package/src/index.ts +29 -362
- package/src/init.ts +345 -177
- package/src/policy.ts +6 -0
- package/src/prepare.ts +19 -19
- package/src/runtime.ts +20 -0
- package/src/schemas/index.ts +3 -0
- package/src/schemas/types.ts +0 -0
- package/src/states.ts +15 -0
- package/{src/Gulpfile.ts → src copy/Gulpfile.ts } +3 -1
- package/{src/gulp/backend.ts → src copy/gulp/backend.ts } +3 -12
- package/{src/gulp/checks.ts → src copy/gulp/checks.ts } +2 -6
- package/{src/gulp/copy.ts → src copy/gulp/copy.ts } +1 -6
- package/src copy/gulp/helpers.ts +26 -0
- package/{src/gulp/public.ts → src copy/gulp/public.ts } +1 -6
- package/{src/gulp/styles.ts → src copy/gulp/styles.ts } +2 -7
- package/{src/gulp/templates.ts → src copy/gulp/templates.ts } +1 -6
- package/src copy/helpers.ts +307 -0
- package/src copy/index.ts +379 -0
- package/src copy/init.ts +183 -0
- package/src copy/models.ts +35 -0
- package/src copy/prepare.ts +24 -0
- package/src copy/schemas/index.ts +0 -0
- package/src copy/schemas/types.ts +0 -0
- package/src copy/settings.json +67 -0
- package/src copy/types.d.ts +8 -0
- package/dist/Gulpfile.d.ts +0 -33
- package/dist/Gulpfile.js +0 -114
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -44
- package/dist/dev.d.ts +0 -2
- package/dist/dev.js +0 -14
- package/dist/gulp/backend copy.d.ts +0 -4
- package/dist/gulp/backend copy.js +0 -50
- package/dist/gulp/backend.d.ts +0 -3
- package/dist/gulp/backend.js +0 -101
- package/dist/gulp/checks.d.ts +0 -3
- package/dist/gulp/checks.js +0 -209
- package/dist/gulp/clean copy.d.ts +0 -2
- package/dist/gulp/clean copy.js +0 -19
- package/dist/gulp/clean.d.ts +0 -3
- package/dist/gulp/clean.js +0 -28
- package/dist/gulp/copy.d.ts +0 -2
- package/dist/gulp/copy.js +0 -38
- package/dist/gulp/docs.d.ts +0 -2
- package/dist/gulp/docs.js +0 -27
- package/dist/gulp/helpers.d.ts +0 -1
- package/dist/gulp/helpers.js +0 -7
- package/dist/gulp/pages copy.d.ts +0 -3
- package/dist/gulp/pages copy.js +0 -22
- package/dist/gulp/pages.d.ts +0 -2
- package/dist/gulp/pages.js +0 -36
- package/dist/gulp/pipeline.d.ts +0 -1
- package/dist/gulp/pipeline.js +0 -28
- package/dist/gulp/public.d.ts +0 -2
- package/dist/gulp/public.js +0 -54
- package/dist/gulp/styles.d.ts +0 -2
- package/dist/gulp/styles.js +0 -44
- package/dist/gulp/templates.d.ts +0 -2
- package/dist/gulp/templates.js +0 -37
- package/dist/gulp/test.d.ts +0 -2
- package/dist/gulp/test.js +0 -26
- package/dist/gulp/types.d.ts +0 -4
- package/dist/gulp/types.js +0 -288
- package/dist/gulp/watchers.d.ts +0 -9
- package/dist/gulp/watchers.js +0 -58
- package/dist/init copy.d.ts +0 -8
- package/dist/init copy.js +0 -167
- package/dist/install.d.ts +0 -2
- package/dist/install.js +0 -53
- package/dist/settings.json +0 -67
- package/dist/start_gulp.d.ts +0 -2
- package/dist/start_gulp.js +0 -14
- package/dist/sync.d.ts +0 -2
- package/dist/sync.js +0 -87
- package/src/gulp/helpers.ts +0 -9
- /package/{files/.gitmodules → dist/schemas/types.d.ts} +0 -0
- /package/files/{typescript/__mocks__/.gitkeep → velo/.gitmodules} +0 -0
- /package/files/{.madgerc → velo/.madgerc} +0 -0
- /package/files/{.nvmrc → velo/.nvmrc} +0 -0
- /package/files/{.stylelintrc.js → velo/.stylelintrc.js} +0 -0
- /package/files/{.yarnrc.yml → velo/.yarnrc.yml} +0 -0
- /package/files/{currents.config.js → velo/currents.config.js} +0 -0
- /package/files/{cypress → velo/cypress}/e2e/base/base.cy.ts +0 -0
- /package/files/{cypress → velo/cypress}/fixtures/example.json +0 -0
- /package/files/{cypress → velo/cypress}/support/commands.ts +0 -0
- /package/files/{cypress → velo/cypress}/support/e2e.ts +0 -0
- /package/files/{cypress → velo/cypress}/tsconfig.json +0 -0
- /package/files/{cypress.config.mjs → velo/cypress.config.mjs} +0 -0
- /package/files/{eslint.config.mjs → velo/eslint.config.mjs} +0 -0
- /package/files/{local.tsconfig.json → velo/local.tsconfig.json} +0 -0
- /package/files/{typedoc.json → velo/typedoc.json} +0 -0
- /package/files/{typescript/pages → velo/typescript/__mocks__}/.gitkeep +0 -0
- /package/files/{typescript → velo/typescript}/backend/data.ts +0 -0
- /package/files/{typescript → velo/typescript}/backend/events.ts +0 -0
- /package/files/{typescript → velo/typescript}/backend/http-functions.ts +0 -0
- /package/files/{typescript → velo/typescript}/backend/lib/http-functions/sync.ts +0 -0
- /package/files/{typescript → velo/typescript}/backend/permissions.json +0 -0
- /package/files/{typescript/public → velo/typescript/pages}/.gitkeep +0 -0
- /package/files/{typescript/styles → velo/typescript/public}/.gitkeep +0 -0
- /package/files/{typescript → velo/typescript}/public/scss/app.scss +0 -0
- /package/files/{typescript/styles/global.scss → velo/typescript/styles/.gitkeep} +0 -0
- /package/files/{typescript → velo/typescript}/tsconfig.json +0 -0
- /package/files/{vitest.config.ts → velo/vitest.config.ts} +0 -0
- /package/{src → src copy}/gulp/clean.ts +0 -0
- /package/{src → src copy}/gulp/pages.ts +0 -0
- /package/{src → src copy}/gulp/pipeline.ts +0 -0
- /package/{src → src copy}/gulp/types.ts +0 -0
- /package/{src → src copy}/gulp/watchers.ts +0 -0
- /package/{src → src copy}/sync.ts +0 -0
package/src/helpers.ts
CHANGED
@@ -1,307 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
import os from 'os';
|
9
|
-
import fs, { mkdirSync } from 'fs';
|
10
|
-
import fse from 'fs-extra';
|
11
|
-
import { writeFile } from 'fs/promises';
|
12
|
-
|
13
|
-
import { blue, green, orange, red, yellow, magenta } from './index.js';
|
14
|
-
|
15
|
-
export async function installPackages(wixPackages: Record<string, string>, devPackages: Record<string, string>, cwd: string, locked: boolean ) {
|
16
|
-
if (locked) console.log("🐕" + blue.underline(` => Installing & version locked packages!`));
|
17
|
-
|
18
|
-
const wixPackageNames = Object.keys(wixPackages);
|
19
|
-
const wixPackageVersions = Object.values(wixPackages);
|
20
|
-
const wixPackageNamesAndVersions = wixPackageNames.map((name, index) => `${name}@${wixPackageVersions[index]}`);
|
21
|
-
|
22
|
-
const devPackageNames = Object.keys(devPackages);
|
23
|
-
const devPackageVersions = Object.values(devPackages);
|
24
|
-
const devPackageNamesAndVersions = devPackageNames.map((name, index) => `${name}@${devPackageVersions[index]}`);
|
25
|
-
|
26
|
-
let success = true;
|
27
|
-
|
28
|
-
// Dev packages are installed all at once with yarn.
|
29
|
-
if (devPackageNames.length > 0) {
|
30
|
-
console.log(`🐕 => Installing dev packages with yarn...`);
|
31
|
-
const packagesToInstall = locked ? devPackageNamesAndVersions.join(' ') : devPackageNames.join(' ');
|
32
|
-
const yarnAdd = `yarn add -D ${packagesToInstall}`;
|
33
|
-
const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
|
34
|
-
if (yarnRes.error) {
|
35
|
-
success = false;
|
36
|
-
console.log((`💩 ${red.underline.bold("=> Failed to install dev packages =>")} ${orange(yarnRes.error.message)}`));
|
37
|
-
} else {
|
38
|
-
console.log("🐕" + blue.underline(` => Dev packages installed!`));
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
// Packages are installed all at once with yarn.
|
43
|
-
if (wixPackageNames.length > 0) {
|
44
|
-
console.log(`🐕 => Installing packages with yarn...`);
|
45
|
-
const packagesToInstall = locked ? wixPackageNamesAndVersions.join(' ') : wixPackageNames.join(' ');
|
46
|
-
const yarnAdd = `yarn add ${packagesToInstall}`;
|
47
|
-
const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
|
48
|
-
if (yarnRes.error) {
|
49
|
-
success = false;
|
50
|
-
console.log((`💩 ${red.underline.bold("=> Failed to install packages =>")} ${orange(yarnRes.error.message)}`));
|
51
|
-
} else {
|
52
|
-
console.log("🐕" + blue.underline(` => Packages installed!`));
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
// Wix packages are installed one by one.
|
57
|
-
if (wixPackageNames.length > 0) {
|
58
|
-
wixPackageNames.forEach((name, index) => {
|
59
|
-
console.log(`🐕 => Installing wix package ${orange(name)}`);
|
60
|
-
const wixInstall = locked ? `wix install ${wixPackageNamesAndVersions[index]}`: `wix install ${name}`;
|
61
|
-
const wixres = spawnSync(wixInstall, { shell: true, stdio: 'inherit' });
|
62
|
-
if (wixres.error) {
|
63
|
-
console.log((`💩 ${red.underline.bold("=> Failed to install wix package =>")} ${orange(wixres.error.message)}`));
|
64
|
-
success = false;
|
65
|
-
} else {
|
66
|
-
console.log("🐕" + blue.underline(` => Wix package ${orange(name)} installed!`));
|
67
|
-
}
|
68
|
-
});
|
69
|
-
}
|
70
|
-
|
71
|
-
if(success) {
|
72
|
-
console.log("🐕" + blue.underline(` => All Packages installed!`));
|
73
|
-
} else {
|
74
|
-
console.log("🐕" + red.underline(` => Some packages failed to install!`));
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
async function isSubmoduleRegistered(git: SimpleGit, submoduleName: string): Promise<boolean> {
|
79
|
-
try {
|
80
|
-
const urlConfig = await git.getConfig(`submodule.${submoduleName}.url`);
|
81
|
-
return !!urlConfig.value;
|
82
|
-
} catch (e) {
|
83
|
-
// simple-git throws an error if the config key doesn't exist
|
84
|
-
return false;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
export async function gitInit(cwd: string, modules: LucySettings['modules'] | undefined, force: boolean) {
|
89
|
-
const git = simpleGit({ baseDir: cwd });
|
90
|
-
|
91
|
-
if (!(await git.checkIsRepo())) {
|
92
|
-
console.log(chalk.yellow('Project is not a git repository. Initializing...'));
|
93
|
-
await git.init();
|
94
|
-
}
|
95
|
-
|
96
|
-
if (!modules) {
|
97
|
-
console.log(chalk.yellow('No submodules defined in settings, skipping.'));
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
|
101
|
-
const dotGitmodulesPath = path.join(cwd, '.gitmodules');
|
102
|
-
|
103
|
-
for (const [name, repo] of Object.entries(modules)) {
|
104
|
-
console.log(chalk.green.underline.bold(`Processing submodule ${name}`));
|
105
|
-
const clonePath = repo.path || name;
|
106
|
-
|
107
|
-
try {
|
108
|
-
const isRegistered = await isSubmoduleRegistered(git, clonePath);
|
109
|
-
// Check that .gitmodules exists AND contains the entry for this specific submodule.
|
110
|
-
const isConfiguredInFile = fs.existsSync(dotGitmodulesPath) &&
|
111
|
-
fs.readFileSync(dotGitmodulesPath, 'utf-8').includes(`[submodule "${clonePath}"]`);
|
112
|
-
|
113
|
-
// Add/repair if not configured in .gitmodules, or if forced by the user.
|
114
|
-
if (!isConfiguredInFile || force) {
|
115
|
-
console.log(`🐕 ${blue.underline(`Adding/updating submodule ${name} at ${clonePath}...`)}`);
|
116
|
-
// If git already has a config entry, we must use --force to repair it.
|
117
|
-
const submoduleArgs = ['add', ...(force || isRegistered ? ['--force'] : []), repo.url, clonePath];
|
118
|
-
await git.subModule(submoduleArgs);
|
119
|
-
} else {
|
120
|
-
console.log(`🐕 ${blue.underline(`Submodule ${name} at ${clonePath} already registered. Skipping add.`)}`);
|
121
|
-
}
|
122
|
-
|
123
|
-
await git.submoduleUpdate(['--init', '--recursive', clonePath]);
|
124
|
-
await simpleGit({ baseDir: path.join(cwd, clonePath) }).checkout(repo.branch);
|
125
|
-
} catch (err) {
|
126
|
-
console.log((`💩 ${red.underline.bold(`=> Command failed for submodule ${name} =>`)} ${orange(err)}`));
|
127
|
-
}
|
128
|
-
}
|
129
|
-
console.log("🐶" + green.underline(' => All modules processed!'));
|
130
|
-
}
|
131
|
-
|
132
|
-
|
133
|
-
export async function runGulp(moduleSettings: ModuleSettings, projectSettings: ProjectSettings, task: string) {
|
134
|
-
// Get the directory name of the current module
|
135
|
-
const __filename = fileURLToPath(import.meta.url);
|
136
|
-
const __dirname = path.dirname(__filename);
|
137
|
-
|
138
|
-
// Resolve the path to the Gulpfile
|
139
|
-
const gulpfilePath = path.resolve(__dirname, 'Gulpfile.js');
|
140
|
-
|
141
|
-
// Dynamically import the Gulpfile
|
142
|
-
const gulpfile = await import(`file://${gulpfilePath}`);
|
143
|
-
|
144
|
-
// Check if 'dev' task exists
|
145
|
-
gulpfile.runTask(task, moduleSettings, projectSettings)
|
146
|
-
}
|
147
|
-
|
148
|
-
|
149
|
-
/**
|
150
|
-
* Clean up and run a command before exiting the process.
|
151
|
-
*/
|
152
|
-
export function cleanupWatchers() {
|
153
|
-
console.log(`🧹 ${magenta.underline('Cleaning up Watchman watchers...')}`);
|
154
|
-
const cwd = process.cwd();
|
155
|
-
const command = `watchman watch-del "${cwd}"`; // Adjust for Windows paths
|
156
|
-
exec(command, (error, stdout, stderr) => {
|
157
|
-
if (error) {
|
158
|
-
console.error(`💩 ${red.underline('Failed to run cleanup:')} ${orange(error.message)}`);
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
if (stderr) {
|
162
|
-
console.error(`⚠️ ${yellow.underline('Watchman stderr:')} ${stderr}`);
|
163
|
-
}
|
164
|
-
console.log(`✅ ${green.underline('Watchman cleanup success:')} ${stdout}`);
|
165
|
-
});
|
166
|
-
}
|
167
|
-
|
168
|
-
/**
|
169
|
-
* Kill all processes matching a specific substring in their command, with a fallback for Windows.
|
170
|
-
* @param {string} processPattern - The substring to match (e.g., "wix:dev" or "@wix/cli/bin/wix.cjs").
|
171
|
-
*/
|
172
|
-
export function killAllProcesses(processPattern: string) {
|
173
|
-
const isWindows = os.platform() === 'win32';
|
174
|
-
const command = isWindows
|
175
|
-
? `tasklist /FI "IMAGENAME eq node.exe" /FO CSV | findstr "${processPattern}"` // Adjust for Node.js processes
|
176
|
-
: `ps -eo pid,command | grep "${processPattern}" | grep -v grep`;
|
177
|
-
|
178
|
-
exec(command, (error, stdout, stderr) => {
|
179
|
-
if (error) {
|
180
|
-
console.error(`💩 ${red.underline('Failed to find processes:')} ${orange(error.message)}`);
|
181
|
-
return;
|
182
|
-
}
|
183
|
-
if (stderr) {
|
184
|
-
console.error(`⚠️ ${yellow.underline('Error output:')} ${stderr}`);
|
185
|
-
}
|
186
|
-
if (!stdout.trim()) {
|
187
|
-
console.log(`ℹ️ ${blue.underline(`No processes found matching pattern:`)} ${orange(processPattern)}`);
|
188
|
-
return;
|
189
|
-
}
|
190
|
-
|
191
|
-
console.log(`📝 ${magenta.underline('Found matching processes:')}\n${stdout}`);
|
192
|
-
const lines = stdout.trim().split('\n');
|
193
|
-
const pids = isWindows
|
194
|
-
? lines.map(line => line.match(/"(\d+)"/)?.[1]) // Extract PID from Windows tasklist output
|
195
|
-
: lines.map(line => line.trim().split(/\s+/)[0]).filter(pid => !isNaN(Number(pid)));
|
196
|
-
|
197
|
-
pids.forEach(pid => {
|
198
|
-
if (!pid) return;
|
199
|
-
try {
|
200
|
-
const killCommand = isWindows
|
201
|
-
? `taskkill /PID ${pid} /T /F` // Forcefully terminate the process on Windows
|
202
|
-
: `kill -SIGTERM ${pid}`;
|
203
|
-
|
204
|
-
exec(killCommand, (killError) => {
|
205
|
-
if (killError) {
|
206
|
-
console.error(`⚠️ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(killError.message)}`);
|
207
|
-
} else {
|
208
|
-
console.log(`✅ ${green.underline('Killed process with PID:')} ${orange(pid)}`);
|
209
|
-
}
|
210
|
-
});
|
211
|
-
|
212
|
-
// Schedule SIGKILL fallback for non-Windows platforms
|
213
|
-
if (!isWindows) {
|
214
|
-
setTimeout(() => {
|
215
|
-
try {
|
216
|
-
process.kill(parseInt(pid, 10), 'SIGKILL');
|
217
|
-
console.log(`🔪 ${red.underline('Sent SIGKILL to process with PID:')} ${orange(pid)} (fallback).`);
|
218
|
-
} catch (killError: any) {
|
219
|
-
if (killError.code === 'ESRCH') {
|
220
|
-
console.log(`✅ ${green.underline('Process with PID')} ${orange(pid)} ${green.underline('already terminated.')}`);
|
221
|
-
} else {
|
222
|
-
console.error(`⚠️ ${yellow.underline('Failed to send SIGKILL to process with PID')} ${orange(pid)}: ${red(killError.message)}`);
|
223
|
-
}
|
224
|
-
}
|
225
|
-
}, 10000);
|
226
|
-
}
|
227
|
-
} catch (err: any) {
|
228
|
-
console.error(`⚠️ ${yellow.underline('Failed to kill process with PID')} ${orange(pid)}: ${red(err.message)}`);
|
229
|
-
}
|
230
|
-
});
|
231
|
-
});
|
232
|
-
}
|
233
|
-
|
234
|
-
export interface VeloSyncConfig {
|
235
|
-
siteUrl: string;
|
236
|
-
secret: string;
|
237
|
-
}
|
238
|
-
export async function saveConfig(config:VeloSyncConfig, file: string) {
|
239
|
-
await fs.promises.writeFile(file, JSON.stringify(config));
|
240
|
-
}
|
241
|
-
export async function readConfig(file: string): Promise<VeloSyncConfig> {
|
242
|
-
let content = await fs.promises.readFile(file, 'utf-8');
|
243
|
-
return JSON.parse(content);
|
244
|
-
}
|
245
|
-
|
246
|
-
export async function createTemplateFolder(moduleSettings: ModuleSettings) {
|
247
|
-
const templatesPath = join(os.homedir(), '.lucy-cli');
|
248
|
-
|
249
|
-
try {
|
250
|
-
mkdirSync(templatesPath);
|
251
|
-
|
252
|
-
const defaultTemplatePath = join(templatesPath, 'default');
|
253
|
-
mkdirSync(defaultTemplatePath);
|
254
|
-
|
255
|
-
const sourceFilesPath = join(moduleSettings.packageRoot, 'files');
|
256
|
-
const defaultTemplateFilesPath = join(defaultTemplatePath, 'files');
|
257
|
-
await fse.copy(sourceFilesPath, defaultTemplateFilesPath);
|
258
|
-
|
259
|
-
const defaultTemplateSettingsPath = join(defaultTemplatePath, 'settings.json');
|
260
|
-
await writeFile(defaultTemplateSettingsPath, JSON.stringify(moduleSettings.settings, null, 2));
|
261
|
-
|
262
|
-
console.log(green('✅ Default template created successfully!'));
|
263
|
-
} catch (e) {
|
264
|
-
console.log((`💩 ${red.underline.bold("=> Error creating default template =>")} ${orange(e)}`));
|
265
|
-
return;
|
266
|
-
}
|
267
|
-
}
|
268
|
-
|
269
|
-
export type PackageJson = {
|
270
|
-
dependencies?: Record<string, string>;
|
271
|
-
devDependencies?: Record<string, string>;
|
272
|
-
[key: string]: any;
|
273
|
-
}
|
274
|
-
|
275
|
-
/**
|
276
|
-
* Updates a lucy.json file with dependencies from a package.json file.
|
277
|
-
* It replaces 'wixPackages' with 'dependencies' and 'devPackages' with 'devDependencies'.
|
278
|
-
* @param {string} packageJsonPath - Path to the package.json file.
|
279
|
-
* @param {string} lucyConfigPath - Path to the lucy.json file.
|
280
|
-
*/
|
281
|
-
export async function updateLucyConfigFromPackageJson(packageJsonPath: string, lucyConfigPath: string): Promise<void> {
|
282
|
-
try {
|
283
|
-
console.log(`🐕 Reading package definitions from ${orange(packageJsonPath)}...`);
|
284
|
-
const pkgJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
|
285
|
-
const packageJson: PackageJson = JSON.parse(pkgJsonContent);
|
286
|
-
|
287
|
-
console.log(`🐕 Reading Lucy configuration from ${orange(lucyConfigPath)}...`);
|
288
|
-
const lucyConfigContent = await fs.promises.readFile(lucyConfigPath, 'utf-8');
|
289
|
-
const lucyConfig: LucySettings = JSON.parse(lucyConfigContent);
|
290
|
-
|
291
|
-
const { dependencies = {}, devDependencies = {} } = packageJson;
|
292
|
-
|
293
|
-
// Note: `wixPackages` are installed using `wix install`. If your `dependencies`
|
294
|
-
// contain packages that are not Wix packages, `lucy-cli install` might fail.
|
295
|
-
lucyConfig.wixPackages = dependencies;
|
296
|
-
lucyConfig.devPackages = devDependencies;
|
297
|
-
|
298
|
-
console.log(`🐕 Writing updated configuration to ${orange(lucyConfigPath)}...`);
|
299
|
-
await fs.promises.writeFile(lucyConfigPath, JSON.stringify(lucyConfig, null, 2));
|
300
|
-
|
301
|
-
console.log(green.underline('✅ Lucy configuration updated successfully!'));
|
302
|
-
|
303
|
-
} catch (error: any) {
|
304
|
-
console.error(`💩 ${red.underline.bold('=> Error updating lucy.json from package.json:')} ${orange(error.message)}`);
|
305
|
-
throw error; // re-throw to allow caller to handle
|
1
|
+
export function parse_error(error: unknown): Error {
|
2
|
+
if (error instanceof Error) {
|
3
|
+
return error;
|
4
|
+
} else if (typeof error === 'string') {
|
5
|
+
return new Error(error);
|
6
|
+
} else {
|
7
|
+
return new Error('Unknown error');
|
306
8
|
}
|
307
9
|
}
|