lucy-cli 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +1 -1
- package/LICENSE.md +22 -0
- package/README.md +103 -1
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +69 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +49 -32
- package/dist/init copy.d.ts +8 -0
- package/dist/init copy.js +167 -0
- package/dist/init.js +4 -53
- package/dist/install.d.ts +2 -0
- package/dist/install.js +53 -0
- package/dist/prepare.d.ts +8 -0
- package/dist/prepare.js +18 -0
- package/dist/settings.json +10 -78
- package/dist/start_gulp.d.ts +2 -0
- package/{src/dev.ts → dist/start_gulp.js} +3 -9
- package/files/.eslintrc.cjs +3 -0
- package/files/.yarnrc.yml +0 -2
- package/files/currents.config.js +1 -1
- package/files/docs.tsconfig.json +6 -5
- package/files/lucy.json +26 -2
- package/lucy.jpg +0 -0
- package/package.json +1 -1
- package/src/helpers.ts +79 -0
- package/src/index.ts +88 -34
- package/src/init.ts +3 -53
- package/src/prepare.ts +23 -0
- package/src/settings.json +10 -78
- package/.drone/.drone.yml +0 -156
- package/.drone/mail_prod_build.hbs +0 -319
- package/.drone/mail_prod_deploy.hbs +0 -309
- package/.drone/mail_satges.hbs +0 -309
- package/.drone/telegram_prod_build.tpl +0 -23
- package/.drone/telegram_prod_deploy.tpl +0 -20
- package/.drone/telegram_stages.tpl +0 -20
- package/files/.eslintrc.json +0 -3
- package/files/typescript/.eslintrc.json +0 -35
package/.eslintrc.cjs
CHANGED
@@ -2,7 +2,7 @@ module.exports = {
|
|
2
2
|
extends: ['eslint:recommended', 'plugin:import/recommended', 'plugin:jsdoc/recommended', 'plugin:@typescript-eslint/recommended'],
|
3
3
|
plugins: ['simple-import-sort', 'eslint-plugin-named-import-spacing', '@typescript-eslint'],
|
4
4
|
parser: '@typescript-eslint/parser',
|
5
|
-
ignorePatterns: ['src/**/*', '
|
5
|
+
ignorePatterns: ['src/**/*', '**/types/backend/**/*', '**/types/pages/**/*', '**/types/public/**/*', '**/types/node/**/*', '.wix/**/*', 'coverage/**/*', 'docs/**/*'],
|
6
6
|
rules: {
|
7
7
|
quotes: [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }],
|
8
8
|
curly: ['error', 'multi-line'],
|
package/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
The MIT License (MIT)
|
3
|
+
|
4
|
+
Copyright (c) 2024 Gradlon von Känel
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -1 +1,103 @@
|
|
1
|
-
#
|
1
|
+
# Lucy-CLI
|
2
|
+
|
3
|
+
![Lucy-CLI](lucy.jpg)
|
4
|
+
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Lucy-CLI was developed out of a personal need to gain full TypeScript support for Wix Velo projects. Typically, using Wix’s GitHub integration provides JSON docs and basic type support, but I aimed for a more integrated TypeScript experience, especially for larger projects that benefit from enhanced type safety.
|
8
|
+
|
9
|
+
Lucy, my loyal dog, accompanied me during long nights working on a major project where I developed this CLI. Her companionship and resilience inspired the name "Lucy-CLI."
|
10
|
+
|
11
|
+
## What It Does
|
12
|
+
|
13
|
+
Lucy-CLI is designed to streamline the setup and management of TypeScript within Wix Velo projects, providing tools to enhance code quality and reduce development time. Here’s what it offers:
|
14
|
+
|
15
|
+
1. **ESLint Configuration**
|
16
|
+
- Adds ESLint with a default configuration (customizable post-init) to maintain consistent code style and prevent common errors.
|
17
|
+
|
18
|
+
2. **Wix Type Definitions**
|
19
|
+
- Exposes Wix type definitions located in `.wix/types/wix-code-types`, allowing direct import and access to the types for comprehensive TypeScript support.
|
20
|
+
|
21
|
+
3. **Autocomplete and Type Mapping for Page Elements**
|
22
|
+
- Maps Wix page elements to their respective types, so `$w('element')` calls have full TypeScript support, including autocomplete for properties and methods.
|
23
|
+
|
24
|
+
4. **Git Submodule Support**
|
25
|
+
- Includes support for git submodules, providing full type support within submodules and enabling the use of libraries and types across projects.
|
26
|
+
|
27
|
+
5. **Configurable Setup**
|
28
|
+
- After initialization, Lucy-CLI creates a `lucy-config.json` configuration file where you can modify settings, add dev packages, specify Wix packages, and configure git submodules.
|
29
|
+
|
30
|
+
---
|
31
|
+
|
32
|
+
## Commands & Options
|
33
|
+
|
34
|
+
Lucy-CLI comes with a range of commands and options to help manage your Wix Velo project. Here’s an overview:
|
35
|
+
|
36
|
+
### Commands
|
37
|
+
|
38
|
+
- **`init`**: Initializes the current folder as a Wix project, creating essential configuration files.
|
39
|
+
- **`dev`**: Starts the development environment, including setting up any required services for local development.
|
40
|
+
- **`build-prod`**: Builds the project in production mode, optimizing files for deployment.
|
41
|
+
- **`prepare`**: Re-runs initialization commands, useful for setting up a pre-configured environment.
|
42
|
+
- **`sync`**: Synchronizes the database and any dependencies or configurations necessary for the project.
|
43
|
+
- **`install`**: Installs all Wix npm packages listed in the `wixpkgs.json` file in the project directory.
|
44
|
+
- **`fix`**: Runs a fix command to resolve common issues in development or production settings.
|
45
|
+
|
46
|
+
### Options
|
47
|
+
|
48
|
+
- **`-h, help`**: Displays the help message with command descriptions.
|
49
|
+
- **`-v, version`**: Shows the current version of Lucy-CLI as defined in the project’s `package.json`.
|
50
|
+
- **`-f, force`**: Forces specific commands to execute, useful for deleting obsolete pages or initializing missing components.
|
51
|
+
- **`-l`**: Locks package versions to those specified in the configuration file during installation.
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
## Examples
|
56
|
+
|
57
|
+
Here are some example commands to get started with Lucy-CLI:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
# Initialize a new Wix project
|
61
|
+
lucy-cli init
|
62
|
+
|
63
|
+
# Start the development environment
|
64
|
+
lucy-cli dev
|
65
|
+
|
66
|
+
# Synchronize database and settings
|
67
|
+
lucy-cli sync
|
68
|
+
|
69
|
+
# Install Wix npm packages from 'wixpkgs.json' with locked versions
|
70
|
+
lucy-cli install -l
|
71
|
+
|
72
|
+
# Force start the dev environment
|
73
|
+
lucy-cli dev -f
|
74
|
+
|
75
|
+
# get help
|
76
|
+
lucy-cli help
|
77
|
+
|
78
|
+
🦮 Lucy CLI Help
|
79
|
+
Usage: lucy-cli <command> [options]
|
80
|
+
|
81
|
+
Commands:
|
82
|
+
🦮 init : Initializes the current folder as a Wix project by creating the necessary configuration files.
|
83
|
+
🦮 dev : Starts the development environment. This includes setting up any required services for local development.
|
84
|
+
🦮 build-prod : Builds the project in production mode, optimizing files for deployment.
|
85
|
+
🦮 prepare : Prepares the project by re-running initialization commands. Useful for setting up a pre-configured environment.
|
86
|
+
🦮 sync : Synchronizes the database and any dependencies or configurations necessary for the project.
|
87
|
+
🦮 install : Installs all Wix npm packages listed in the 'wixpkgs.json' file in the project directory.
|
88
|
+
🦮 fix : Runs a fix command to resolve common issues in development or production settings.
|
89
|
+
|
90
|
+
Options:
|
91
|
+
🦮 -h, help : Displays this help message.
|
92
|
+
🦮 -v, version : Displays the current version of Lucy CLI as defined in the project’s package.json.
|
93
|
+
🦮 -f, force : Forces specific commands to execute even if they may lead to potential issues.
|
94
|
+
Used for functions like deleting obsolete pages or initializing missing components.
|
95
|
+
🦮 -l : Locks package versions to those specified in the configuration file during installation.
|
96
|
+
|
97
|
+
Examples:
|
98
|
+
🦮 lucy-cli init : Initializes a new Wix project.
|
99
|
+
🦮 lucy-cli dev : Starts the development environment.
|
100
|
+
🦮 lucy-cli sync : Synchronizes database and settings.
|
101
|
+
🦮 lucy-cli install : Installs all Wix npm packages from 'wixpkgs.json'.
|
102
|
+
🦮 lucy-cli dev -f : Starts the dev environment with forced settings.
|
103
|
+
🦮 lucy-cli install -l : Installs Wix npm packages, respecting locked versions specified in the configuration.
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { ModuleSettings, ProjectSettings } from '.';
|
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: Record<string, string>): Promise<void>;
|
4
|
+
export declare function dev(moduleSettings: ModuleSettings, projectSettings: ProjectSettings, task: string): Promise<void>;
|
package/dist/helpers.js
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
import chalk from 'chalk';
|
2
|
+
import { simpleGit } from 'simple-git';
|
3
|
+
import { spawnSync } from 'child_process';
|
4
|
+
// https://www.sergevandenoever.nl/run-gulp4-tasks-programatically-from-node/
|
5
|
+
import path from 'path';
|
6
|
+
import { fileURLToPath } from 'url';
|
7
|
+
import { blue, green, orange, red } from './index.js';
|
8
|
+
export async function installPackages(wixPackages, devPackages, cwd, locked) {
|
9
|
+
if (locked)
|
10
|
+
console.log("🐕" + blue.underline(` => Installing & version locked packages!`));
|
11
|
+
const wixPackageNames = Object.keys(wixPackages);
|
12
|
+
const wixPackageVersions = Object.values(wixPackages);
|
13
|
+
const wixPackageNamesAndVersions = wixPackageNames.map((name, index) => `${name}@${wixPackageVersions[index]}`);
|
14
|
+
const devPackageNames = Object.keys(devPackages);
|
15
|
+
const devPackageVersions = Object.values(devPackages);
|
16
|
+
const devPackageNamesAndVersions = devPackageNames.map((name, index) => `${name}@${devPackageVersions[index]}`);
|
17
|
+
let success = true;
|
18
|
+
wixPackageNames.forEach((name, index) => {
|
19
|
+
console.log(`🐕 => Installing ${orange(name)}`);
|
20
|
+
const wixInstall = locked ? `wix install ${wixPackageNamesAndVersions}` : `wix install ${name}`;
|
21
|
+
const wixres = spawnSync(wixInstall, { shell: true, stdio: 'inherit' });
|
22
|
+
if (wixres.error) {
|
23
|
+
console.log((`💩 ${red.underline.bold("=> Failed to install package =>")} ${orange(wixres.error.message)}`));
|
24
|
+
success = false;
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
console.log("🐕" + blue.underline(` => Package installed!`));
|
28
|
+
}
|
29
|
+
});
|
30
|
+
const yarnAdd = locked ? `yarn add -D ${devPackageNamesAndVersions.join(' ')}` : `yarn add -D ${devPackageNames.join(' ')}`;
|
31
|
+
const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
|
32
|
+
if (yarnRes.error) {
|
33
|
+
success = false;
|
34
|
+
console.log((`💩 ${red.underline.bold("=> Failed to install dev packages =>")} ${orange(yarnRes.error.message)}`));
|
35
|
+
}
|
36
|
+
if (success) {
|
37
|
+
console.log("🐕" + blue.underline(` => All Packages installed!`));
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
console.log("🐕" + red.underline(` => Some packages failed to install!`));
|
41
|
+
}
|
42
|
+
}
|
43
|
+
export async function gitInit(cwd, modules) {
|
44
|
+
const git = simpleGit({ baseDir: cwd });
|
45
|
+
for (const [name, url] of Object.entries(modules)) {
|
46
|
+
console.log(chalk.green.underline.bold(`Cloning ${name}`));
|
47
|
+
try {
|
48
|
+
await git.submoduleAdd(url, name);
|
49
|
+
}
|
50
|
+
catch (err) {
|
51
|
+
console.log((`💩 ${red.underline.bold("=> Command failed =>")} ${orange(err)}`));
|
52
|
+
}
|
53
|
+
finally {
|
54
|
+
console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
|
55
|
+
}
|
56
|
+
}
|
57
|
+
console.log("🐶" + green.underline(' => All Modules cloned!'));
|
58
|
+
}
|
59
|
+
export async function dev(moduleSettings, projectSettings, task) {
|
60
|
+
// Get the directory name of the current module
|
61
|
+
const __filename = fileURLToPath(import.meta.url);
|
62
|
+
const __dirname = path.dirname(__filename);
|
63
|
+
// Resolve the path to the Gulpfile
|
64
|
+
const gulpfilePath = path.resolve(__dirname, 'Gulpfile.js');
|
65
|
+
// Dynamically import the Gulpfile
|
66
|
+
const gulpfile = await import(`file://${gulpfilePath}`);
|
67
|
+
// Check if 'dev' task exists
|
68
|
+
gulpfile.runTask(task, moduleSettings, projectSettings);
|
69
|
+
}
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
#!/usr/bin/env node --no-warnings
|
2
2
|
import settings from './settings.json';
|
3
3
|
import lucyJSON from '../files/lucy.json';
|
4
|
+
export type LucySettings = {
|
5
|
+
modules: {
|
6
|
+
[llibName: string]: string;
|
7
|
+
};
|
8
|
+
wixSettings: {
|
9
|
+
compilerOptions: {
|
10
|
+
composite: boolean;
|
11
|
+
noEmit: boolean;
|
12
|
+
lib: string[];
|
13
|
+
jsx: string;
|
14
|
+
};
|
15
|
+
exclude: string[];
|
16
|
+
};
|
17
|
+
initialized: boolean;
|
18
|
+
wixPackages: {
|
19
|
+
[packageName: string]: string;
|
20
|
+
};
|
21
|
+
devPackages: {
|
22
|
+
[packageName: string]: string;
|
23
|
+
};
|
24
|
+
scripts: {
|
25
|
+
[commandName: string]: string;
|
26
|
+
};
|
27
|
+
};
|
4
28
|
export type ModuleSettings = {
|
5
29
|
packageRoot: string;
|
6
30
|
targetFolder: string;
|
@@ -10,10 +34,11 @@ export type ModuleSettings = {
|
|
10
34
|
packageJsonPath: string;
|
11
35
|
settings: typeof settings;
|
12
36
|
lucyJSON: typeof lucyJSON;
|
37
|
+
lockVersion: boolean;
|
13
38
|
};
|
14
39
|
export type ProjectSettings = {
|
15
40
|
modules?: Record<string, string>;
|
16
|
-
lucySettings?:
|
41
|
+
lucySettings?: LucySettings;
|
17
42
|
packageJSON?: Record<string, any>;
|
18
43
|
lucyJSON?: Record<string, any>;
|
19
44
|
force: boolean;
|
package/dist/index.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
import { dirname } from 'path';
|
3
3
|
import { fileURLToPath } from 'url';
|
4
4
|
import { existsSync } from 'fs';
|
5
|
-
import { spawnSync } from 'child_process';
|
6
5
|
import chalk from 'chalk';
|
7
6
|
import settings from './settings.json' assert { type: 'json' };
|
8
7
|
import projectPackageJSON from '../package.json' assert { type: 'json' };
|
@@ -10,8 +9,9 @@ import lucyJSON from '../files/lucy.json' assert { type: 'json' };
|
|
10
9
|
import { join } from 'path';
|
11
10
|
import fs from 'fs/promises';
|
12
11
|
import { init } from './init.js';
|
13
|
-
import { dev } from './dev.js';
|
14
12
|
import { sync } from './sync.js';
|
13
|
+
import { dev, installPackages } from './helpers.js';
|
14
|
+
import { prepare } from './prepare.js';
|
15
15
|
export const orange = chalk.hex('#FFA500');
|
16
16
|
export const blue = chalk.blueBright;
|
17
17
|
export const green = chalk.greenBright;
|
@@ -36,6 +36,7 @@ async function main() {
|
|
36
36
|
lucyConfigPath: join(process.cwd(), 'lucy.json'),
|
37
37
|
packageJsonPath: join(process.cwd(), 'package.json'),
|
38
38
|
lucyJSON,
|
39
|
+
lockVersion: false
|
39
40
|
};
|
40
41
|
let projectSettings = {
|
41
42
|
force: false
|
@@ -45,12 +46,29 @@ async function main() {
|
|
45
46
|
return;
|
46
47
|
}
|
47
48
|
if (moduleSettings.args.includes('help') || moduleSettings.args.includes('-h')) {
|
48
|
-
console.log("🦮" + green.underline.bold(' => Lucy CLI Help'));
|
49
|
-
console.log("
|
50
|
-
console.log("
|
51
|
-
console.log("🦮" + magenta.
|
52
|
-
console.log("🦮" + magenta.
|
53
|
-
console.log("🦮" + magenta.
|
49
|
+
console.log("🦮 " + green.underline.bold(' => Lucy CLI Help'));
|
50
|
+
console.log("Usage: lucy-cli <command> [options]");
|
51
|
+
console.log("\nCommands:");
|
52
|
+
console.log("🦮 " + magenta.bold('init') + " : Initializes caontaining a WIX project to enable full TS support");
|
53
|
+
console.log("🦮 " + magenta.bold('dev') + " : Starts the development environment. This includes setting up any required services for local development.");
|
54
|
+
console.log("🦮 " + magenta.bold('build-prod') + " : Builds the project in production mode, optimizing files for deployment.");
|
55
|
+
console.log("🦮 " + magenta.bold('prepare') + " : Prepares the project by installing packages & initializing git modules, configured in lucy.json");
|
56
|
+
console.log("🦮 " + magenta.bold('sync') + " : Synchronizes the database (not Implemented)");
|
57
|
+
console.log("🦮 " + magenta.bold('install') + " : Installs all Wix npm packages listed in the 'lucy.json' file in the project directory.");
|
58
|
+
console.log("🦮 " + magenta.bold('fix') + " : Runs a fix command to resolve common issues in development or production settings.");
|
59
|
+
console.log("\nOptions:");
|
60
|
+
console.log("🦮 " + magenta.bold('-h, help') + " : Displays this help message.");
|
61
|
+
console.log("🦮 " + magenta.bold('-v, version') + " : Displays the current version of Lucy CLI as defined in the project’s package.json.");
|
62
|
+
console.log("🦮 " + magenta.bold('-f, force') + " : Forces specific commands to execute even if they may lead to potential issues.");
|
63
|
+
console.log(" Used for functions like deleting obsolete pages or initializing missing components.");
|
64
|
+
console.log("🦮 " + magenta.bold('-l') + " : Locks package versions to those specified in the configuration file lucy.json");
|
65
|
+
console.log("\nExamples:");
|
66
|
+
console.log("🦮 " + magenta.bold('lucy-cli init') + " : Initializes a new Wix project.");
|
67
|
+
console.log("🦮 " + magenta.bold('lucy-cli dev') + " : Starts the development environment.");
|
68
|
+
console.log("🦮 " + magenta.bold('lucy-cli sync') + " : Synchronizes database and settings.");
|
69
|
+
console.log("🦮 " + magenta.bold('lucy-cli install') + " : Installs all Wix npm packages from 'lucy.json'.");
|
70
|
+
console.log("🦮 " + magenta.bold('lucy-cli dev -f') + " : Starts the dev environment with forced settings.");
|
71
|
+
console.log("🦮 " + magenta.bold('lucy-cli install -l') + " : Installs Wix npm packages, respecting locked versions specified in the configuration.");
|
54
72
|
return;
|
55
73
|
}
|
56
74
|
if (!existsSync(moduleSettings.wixConfigPath)) {
|
@@ -86,44 +104,43 @@ async function main() {
|
|
86
104
|
}
|
87
105
|
;
|
88
106
|
}
|
107
|
+
if (moduleSettings.args.includes('-l'))
|
108
|
+
moduleSettings.lockVersion = true;
|
89
109
|
if (moduleSettings.args.includes('init')) {
|
90
110
|
console.log("🐕" + magenta.underline(' => Initializing project'));
|
91
111
|
init(moduleSettings, projectSettings);
|
92
112
|
return;
|
93
113
|
}
|
114
|
+
if (moduleSettings.args.includes('prepare')) {
|
115
|
+
console.log("🐕" + magenta.underline(' => Preparing project'));
|
116
|
+
init(moduleSettings, projectSettings);
|
117
|
+
return;
|
118
|
+
}
|
94
119
|
if (moduleSettings.args.includes('install')) {
|
95
|
-
|
96
|
-
const data = await fs.readFile(join(process.cwd(), 'wixpkgs.json'), 'utf8');
|
97
|
-
const jsonData = JSON.parse(data);
|
98
|
-
console.log("🐕" + magenta.underline(' => Installing wix npm packages'));
|
99
|
-
const wixPackageVersions = Object.values(jsonData);
|
100
|
-
const wixPackageNamesAndVersions = wixPackageVersions.map((name, index) => `${name}@${wixPackageVersions[index]}`);
|
101
|
-
wixPackageNamesAndVersions.forEach((name, index) => {
|
102
|
-
console.log(`🐕 => Installing ${orange(name)}`);
|
103
|
-
const wixInstall = `wix install ${name}`;
|
104
|
-
const wixres = spawnSync(wixInstall, { shell: true, stdio: 'inherit' });
|
105
|
-
if (wixres.error) {
|
106
|
-
console.log((`💩 ${red.underline.bold("=> Failed to install package =>")} ${orange(wixres.error.message)}`));
|
107
|
-
}
|
108
|
-
else {
|
109
|
-
console.log("🐕" + blue.underline(` => Package installed!`));
|
110
|
-
}
|
111
|
-
});
|
112
|
-
}
|
113
|
-
catch (e) {
|
114
|
-
console.log((`💩 ${red.underline.bold("=> Error parsing installing wix npm packages =>")} ${orange(e)}`));
|
115
|
-
}
|
120
|
+
await installPackages(moduleSettings.settings.wixPackages, moduleSettings.settings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
|
116
121
|
return;
|
117
122
|
}
|
118
|
-
if (moduleSettings.args.includes('
|
119
|
-
|
123
|
+
if (moduleSettings.args.includes('prepare')) {
|
124
|
+
await prepare(moduleSettings, projectSettings);
|
120
125
|
return;
|
121
126
|
}
|
122
127
|
if (moduleSettings.args.includes('sync')) {
|
123
128
|
sync(moduleSettings, projectSettings);
|
124
129
|
return;
|
125
130
|
}
|
131
|
+
if (moduleSettings.args.includes('dev')) {
|
132
|
+
dev(moduleSettings, projectSettings, 'dev');
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
if (moduleSettings.args.includes('build-prod')) {
|
136
|
+
dev(moduleSettings, projectSettings, 'build-prod');
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
if (moduleSettings.args.includes('fix')) {
|
140
|
+
dev(moduleSettings, projectSettings, 'fix');
|
141
|
+
return;
|
142
|
+
}
|
126
143
|
console.log("🐕" + blue.underline.bold(' => Running dev'));
|
127
|
-
dev(moduleSettings, projectSettings);
|
144
|
+
dev(moduleSettings, projectSettings, 'dev');
|
128
145
|
}
|
129
146
|
main();
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { ModuleSettings, ProjectSettings } from './index.js';
|
2
|
+
/**
|
3
|
+
* Init Lucy project
|
4
|
+
* @param {string} cwd Current working directory
|
5
|
+
* @param {string} packageRoot Package root directory
|
6
|
+
* @returns {void}
|
7
|
+
*/
|
8
|
+
export declare function init(moduleSettings: ModuleSettings, projectSettings: ProjectSettings): Promise<void>;
|
@@ -0,0 +1,167 @@
|
|
1
|
+
import chalk from 'chalk';
|
2
|
+
import { existsSync, mkdirSync, promises as fsPromises } from 'fs';
|
3
|
+
import fse from 'fs-extra';
|
4
|
+
import { join } from 'path';
|
5
|
+
import { simpleGit } from 'simple-git';
|
6
|
+
import fs from 'fs/promises';
|
7
|
+
import { spawnSync } from 'child_process';
|
8
|
+
import path from 'path';
|
9
|
+
import { blue, green, orange, red } from './index.js';
|
10
|
+
/**
|
11
|
+
* Init Lucy project
|
12
|
+
* @param {string} cwd Current working directory
|
13
|
+
* @param {string} packageRoot Package root directory
|
14
|
+
* @returns {void}
|
15
|
+
*/
|
16
|
+
export async function init(moduleSettings, projectSettings) {
|
17
|
+
if (projectSettings.packageJSON && projectSettings.packageJSON.wixLucy?.initialized && !moduleSettings.args.includes('-f')) {
|
18
|
+
console.log((`💩 ${red.underline.bold("=> This project is already initialized =>")} ${orange(moduleSettings.targetFolder)}`));
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
await copyFolder(join(moduleSettings.packageRoot, 'files'), moduleSettings.targetFolder);
|
22
|
+
await editJson(moduleSettings.packageJsonPath, ['type', 'scripts', 'wixLucy'], ['module', moduleSettings.settings.scripts, moduleSettings.settings.lucySettings]);
|
23
|
+
await stringReplace(join(moduleSettings.targetFolder, 'currents.config.js'), ['__ProjectName__'], [path.basename(moduleSettings.targetFolder)]);
|
24
|
+
await installPackages(moduleSettings.settings.wixPackages, moduleSettings.settings.devPackages, moduleSettings.targetFolder);
|
25
|
+
await editJson(join(moduleSettings.targetFolder, 'jsconfig.json'), ['compilerOptions', 'exclude'], [moduleSettings.settings.wixSettings.compilerOptions, moduleSettings.settings.wixSettings.exclude]);
|
26
|
+
await editJson(join(moduleSettings.targetFolder, 'typedoc.json'), ['name'], [path.basename(moduleSettings.targetFolder)]);
|
27
|
+
await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules ? projectSettings?.lucySettings?.modules : moduleSettings.settings.modules);
|
28
|
+
console.log(chalk.greenBright.underline('🐶 => Initialization done!'));
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Copy files from source to target
|
32
|
+
* @param {string} source Source folder
|
33
|
+
* @param {string} target Target folder
|
34
|
+
* @returns {Promise<void>}
|
35
|
+
*/
|
36
|
+
async function copyFolder(source, target) {
|
37
|
+
if (!existsSync(target)) {
|
38
|
+
console.log((`💩 ${red.underline.bold("=> Target folder doesn't exist =>")} ${orange(target)}`));
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
try {
|
42
|
+
const files = await fsPromises.readdir(source);
|
43
|
+
for (const file of files) {
|
44
|
+
const sourcePath = join(source, file);
|
45
|
+
const targetPath = join(target, file);
|
46
|
+
if (file === 'lucy.json' && existsSync(targetPath)) {
|
47
|
+
continue;
|
48
|
+
}
|
49
|
+
const stats = await fsPromises.stat(sourcePath);
|
50
|
+
if (stats.isDirectory()) {
|
51
|
+
if (!existsSync(file)) {
|
52
|
+
mkdirSync(file);
|
53
|
+
}
|
54
|
+
await fse.copySync(sourcePath, targetPath, { overwrite: true });
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
fse.copySync(sourcePath, targetPath, { overwrite: true });
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
catch (err) {
|
62
|
+
console.log((`💩 ${red.underline.bold("=> There was an error while copying files =>")} ${orange(err)}`));
|
63
|
+
}
|
64
|
+
finally {
|
65
|
+
console.log("🐕" + blue.underline.bold(' => Copy files completed!'));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* Edit Json files
|
70
|
+
* @param {string} filePath File path
|
71
|
+
* @param {string[]} keys Keys to edit
|
72
|
+
* @param {string[]} values Values to edit
|
73
|
+
* @returns {void}
|
74
|
+
*/
|
75
|
+
async function editJson(filePath, keys, values) {
|
76
|
+
try {
|
77
|
+
const data = await fs.readFile(filePath, 'utf8');
|
78
|
+
let jsonData;
|
79
|
+
try {
|
80
|
+
jsonData = JSON.parse(data);
|
81
|
+
}
|
82
|
+
catch (parseError) {
|
83
|
+
console.log((`💩 ${red.underline.bold("=> Error parsing JSON =>")} ${orange(parseError)}`));
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
for (const key of keys) {
|
87
|
+
const index = keys.indexOf(key);
|
88
|
+
const value = values[index];
|
89
|
+
jsonData[key] = value;
|
90
|
+
}
|
91
|
+
const updatedJsonData = JSON.stringify(jsonData, null, 2);
|
92
|
+
await fs.writeFile(filePath, updatedJsonData, 'utf8');
|
93
|
+
}
|
94
|
+
catch (err) {
|
95
|
+
console.log((`💩 ${red.underline.bold("=> Error editing JSON Data =>")} ${orange(err)}`));
|
96
|
+
}
|
97
|
+
finally {
|
98
|
+
console.log("🐕" + blue.underline(` => Updated file ${orange(filePath)}`));
|
99
|
+
}
|
100
|
+
}
|
101
|
+
async function stringReplace(filePath, keys, values) {
|
102
|
+
try {
|
103
|
+
let modifiedContent = '';
|
104
|
+
const data = await fs.readFile(filePath, 'utf8');
|
105
|
+
for (const key of keys) {
|
106
|
+
const index = keys.indexOf(key);
|
107
|
+
const value = values[index];
|
108
|
+
const regex = new RegExp(`${key}`, 'g');
|
109
|
+
modifiedContent = data.replace(regex, `${value}`);
|
110
|
+
}
|
111
|
+
await fs.writeFile(filePath, modifiedContent, 'utf8');
|
112
|
+
}
|
113
|
+
catch (err) {
|
114
|
+
console.log((`💩 ${red.underline.bold("=> During string replace =>")} ${orange(err)}`));
|
115
|
+
}
|
116
|
+
finally {
|
117
|
+
console.log(blue.underline(`🐕 => Updated file ${orange(filePath)}`));
|
118
|
+
}
|
119
|
+
}
|
120
|
+
async function installPackages(wixPackages, devPackages, cwd) {
|
121
|
+
const wixPackageNames = Object.keys(wixPackages);
|
122
|
+
const devPackageNames = Object.keys(devPackages);
|
123
|
+
const devPackageVersions = Object.values(devPackages);
|
124
|
+
const devPackageNamesAndVersions = devPackageNames.map((name, index) => `${name}@${devPackageVersions[index]}`);
|
125
|
+
let success = true;
|
126
|
+
wixPackageNames.forEach((name, index) => {
|
127
|
+
console.log(`🐕 => Installing ${orange(name)}`);
|
128
|
+
const wixInstall = `wix install ${name}`;
|
129
|
+
const wixres = spawnSync(wixInstall, { shell: true, stdio: 'inherit' });
|
130
|
+
if (wixres.error) {
|
131
|
+
console.log((`💩 ${red.underline.bold("=> Failed to install package =>")} ${orange(wixres.error.message)}`));
|
132
|
+
success = false;
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
console.log("🐕" + blue.underline(` => Package installed!`));
|
136
|
+
}
|
137
|
+
});
|
138
|
+
const yarnAdd = `yarn add -D ${devPackageNamesAndVersions.join(' ')}`;
|
139
|
+
const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
|
140
|
+
if (yarnRes.error) {
|
141
|
+
success = false;
|
142
|
+
console.log((`💩 ${red.underline.bold("=> Failed to install dev packages =>")} ${orange(yarnRes.error.message)}`));
|
143
|
+
}
|
144
|
+
if (success) {
|
145
|
+
await fs.writeFile(join(cwd, 'wixpkgs.json'), JSON.stringify(wixPackages, null, 2), 'utf8');
|
146
|
+
console.log("🐕" + blue.underline(` => All Packages installed!`));
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
console.log("🐕" + red.underline(` => Some packages failed to install!`));
|
150
|
+
}
|
151
|
+
}
|
152
|
+
async function gitInit(cwd, modules) {
|
153
|
+
const git = simpleGit({ baseDir: cwd });
|
154
|
+
for (const [name, url] of Object.entries(modules)) {
|
155
|
+
console.log(chalk.green.underline.bold(`Cloning ${name}`));
|
156
|
+
try {
|
157
|
+
await git.submoduleAdd(url, name);
|
158
|
+
}
|
159
|
+
catch (err) {
|
160
|
+
console.log((`💩 ${red.underline.bold("=> Command failed =>")} ${orange(err)}`));
|
161
|
+
}
|
162
|
+
finally {
|
163
|
+
console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
|
164
|
+
}
|
165
|
+
}
|
166
|
+
console.log("🐶" + green.underline(' => All Modules cloned!'));
|
167
|
+
}
|
package/dist/init.js
CHANGED
@@ -2,11 +2,10 @@ import chalk from 'chalk';
|
|
2
2
|
import { existsSync, mkdirSync, promises as fsPromises } from 'fs';
|
3
3
|
import fse from 'fs-extra';
|
4
4
|
import { join } from 'path';
|
5
|
-
import { simpleGit } from 'simple-git';
|
6
5
|
import fs from 'fs/promises';
|
7
|
-
import { spawnSync } from 'child_process';
|
8
6
|
import path from 'path';
|
9
|
-
import { blue,
|
7
|
+
import { blue, orange, red } from './index.js';
|
8
|
+
import { gitInit, installPackages } from './helpers.js';
|
10
9
|
/**
|
11
10
|
* Init Lucy project
|
12
11
|
* @param {string} cwd Current working directory
|
@@ -19,9 +18,9 @@ export async function init(moduleSettings, projectSettings) {
|
|
19
18
|
return;
|
20
19
|
}
|
21
20
|
await copyFolder(join(moduleSettings.packageRoot, 'files'), moduleSettings.targetFolder);
|
22
|
-
await editJson(moduleSettings.packageJsonPath, ['type', 'scripts'
|
21
|
+
await editJson(moduleSettings.packageJsonPath, ['type', 'scripts'], ['module', moduleSettings.settings.scripts]);
|
23
22
|
await stringReplace(join(moduleSettings.targetFolder, 'currents.config.js'), ['__ProjectName__'], [path.basename(moduleSettings.targetFolder)]);
|
24
|
-
await installPackages(moduleSettings.settings.wixPackages, moduleSettings.settings.devPackages, moduleSettings.targetFolder);
|
23
|
+
await installPackages(moduleSettings.settings.wixPackages, moduleSettings.settings.devPackages, moduleSettings.targetFolder, moduleSettings.lockVersion);
|
25
24
|
await editJson(join(moduleSettings.targetFolder, 'jsconfig.json'), ['compilerOptions', 'exclude'], [moduleSettings.settings.wixSettings.compilerOptions, moduleSettings.settings.wixSettings.exclude]);
|
26
25
|
await editJson(join(moduleSettings.targetFolder, 'typedoc.json'), ['name'], [path.basename(moduleSettings.targetFolder)]);
|
27
26
|
await gitInit(moduleSettings.targetFolder, projectSettings?.lucySettings?.modules ? projectSettings?.lucySettings?.modules : moduleSettings.settings.modules);
|
@@ -117,51 +116,3 @@ async function stringReplace(filePath, keys, values) {
|
|
117
116
|
console.log(blue.underline(`🐕 => Updated file ${orange(filePath)}`));
|
118
117
|
}
|
119
118
|
}
|
120
|
-
async function installPackages(wixPackages, devPackages, cwd) {
|
121
|
-
const wixPackageNames = Object.keys(wixPackages);
|
122
|
-
const devPackageNames = Object.keys(devPackages);
|
123
|
-
const devPackageVersions = Object.values(devPackages);
|
124
|
-
const devPackageNamesAndVersions = devPackageNames.map((name, index) => `${name}@${devPackageVersions[index]}`);
|
125
|
-
let success = true;
|
126
|
-
wixPackageNames.forEach((name, index) => {
|
127
|
-
console.log(`🐕 => Installing ${orange(name)}`);
|
128
|
-
const wixInstall = `wix install ${name}`;
|
129
|
-
const wixres = spawnSync(wixInstall, { shell: true, stdio: 'inherit' });
|
130
|
-
if (wixres.error) {
|
131
|
-
console.log((`💩 ${red.underline.bold("=> Failed to install package =>")} ${orange(wixres.error.message)}`));
|
132
|
-
success = false;
|
133
|
-
}
|
134
|
-
else {
|
135
|
-
console.log("🐕" + blue.underline(` => Package installed!`));
|
136
|
-
}
|
137
|
-
});
|
138
|
-
const yarnAdd = `yarn add -D ${devPackageNamesAndVersions.join(' ')}`;
|
139
|
-
const yarnRes = spawnSync(yarnAdd, { shell: true, stdio: 'inherit' });
|
140
|
-
if (yarnRes.error) {
|
141
|
-
success = false;
|
142
|
-
console.log((`💩 ${red.underline.bold("=> Failed to install dev packages =>")} ${orange(yarnRes.error.message)}`));
|
143
|
-
}
|
144
|
-
if (success) {
|
145
|
-
await fs.writeFile(join(cwd, 'wixpkgs.json'), JSON.stringify(wixPackages, null, 2), 'utf8');
|
146
|
-
console.log("🐕" + blue.underline(` => All Packages installed!`));
|
147
|
-
}
|
148
|
-
else {
|
149
|
-
console.log("🐕" + red.underline(` => Some packages failed to install!`));
|
150
|
-
}
|
151
|
-
}
|
152
|
-
async function gitInit(cwd, modules) {
|
153
|
-
const git = simpleGit({ baseDir: cwd });
|
154
|
-
for (const [name, url] of Object.entries(modules)) {
|
155
|
-
console.log(chalk.green.underline.bold(`Cloning ${name}`));
|
156
|
-
try {
|
157
|
-
await git.submoduleAdd(url, name);
|
158
|
-
}
|
159
|
-
catch (err) {
|
160
|
-
console.log((`💩 ${red.underline.bold("=> Command failed =>")} ${orange(err)}`));
|
161
|
-
}
|
162
|
-
finally {
|
163
|
-
console.log("🐕" + blue.underline(` => Cloned ${orange(name)}`));
|
164
|
-
}
|
165
|
-
}
|
166
|
-
console.log("🐶" + green.underline(' => All Modules cloned!'));
|
167
|
-
}
|