lucy-cli 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. package/.drone/.drone.yml +156 -0
  2. package/.drone/mail_prod_build.hbs +319 -0
  3. package/.drone/mail_prod_deploy.hbs +309 -0
  4. package/.drone/mail_satges.hbs +309 -0
  5. package/.drone/telegram_prod_build.tpl +23 -0
  6. package/.drone/telegram_prod_deploy.tpl +20 -0
  7. package/.drone/telegram_stages.tpl +20 -0
  8. package/.eslintrc.cjs +96 -0
  9. package/.eslintrc.json +3 -0
  10. package/.nvmrc +1 -0
  11. package/.yarnrc.yml +5 -0
  12. package/README.md +1 -0
  13. package/dist/Gulpfile.d.ts +28 -0
  14. package/dist/Gulpfile.js +179 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +44 -0
  17. package/dist/dev.d.ts +1 -0
  18. package/dist/dev.js +14 -0
  19. package/dist/gulp/backend copy.d.ts +4 -0
  20. package/dist/gulp/backend copy.js +50 -0
  21. package/dist/gulp/backend.d.ts +4 -0
  22. package/dist/gulp/backend.js +49 -0
  23. package/dist/gulp/checks.d.ts +3 -0
  24. package/dist/gulp/checks.js +119 -0
  25. package/dist/gulp/clean copy.d.ts +2 -0
  26. package/dist/gulp/clean copy.js +19 -0
  27. package/dist/gulp/clean.d.ts +1 -0
  28. package/dist/gulp/clean.js +14 -0
  29. package/dist/gulp/copy.d.ts +3 -0
  30. package/dist/gulp/copy.js +22 -0
  31. package/dist/gulp/pages copy.d.ts +3 -0
  32. package/dist/gulp/pages copy.js +22 -0
  33. package/dist/gulp/pages.d.ts +3 -0
  34. package/dist/gulp/pages.js +22 -0
  35. package/dist/gulp/public.d.ts +4 -0
  36. package/dist/gulp/public.js +50 -0
  37. package/dist/gulp/styles.d.ts +3 -0
  38. package/dist/gulp/styles.js +17 -0
  39. package/dist/gulp/templates.d.ts +1 -0
  40. package/dist/gulp/templates.js +21 -0
  41. package/dist/gulp/types.d.ts +5 -0
  42. package/dist/gulp/types.js +73 -0
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.js +88 -0
  45. package/dist/init.d.ts +7 -0
  46. package/dist/init.js +176 -0
  47. package/dist/settings.json +91 -0
  48. package/files/.drone/.drone.yml +156 -0
  49. package/files/.drone/mail_prod_build.hbs +319 -0
  50. package/files/.drone/mail_prod_deploy.hbs +309 -0
  51. package/files/.drone/mail_satges.hbs +309 -0
  52. package/files/.drone/telegram_prod_build.tpl +23 -0
  53. package/files/.drone/telegram_prod_deploy.tpl +20 -0
  54. package/files/.drone/telegram_stages.tpl +20 -0
  55. package/files/.eslintrc.cjs +96 -0
  56. package/files/.eslintrc.json +3 -0
  57. package/files/.nvmrc +1 -0
  58. package/files/.yarnrc.yml +5 -0
  59. package/files/currents.config.js +5 -0
  60. package/files/cypress.config.ts +12 -0
  61. package/files/docs.tsconfig.json +37 -0
  62. package/files/jest.config.ts +28 -0
  63. package/files/lucy.json +5 -0
  64. package/files/tsconfig.json +51 -0
  65. package/files/typedoc.json +19 -0
  66. package/files/typescript/.eslintrc.json +35 -0
  67. package/files/typescript/__mocks__/.gitkeep +0 -0
  68. package/files/typescript/backend/index.ts +0 -0
  69. package/files/typescript/backend/permissions.json +0 -0
  70. package/files/typescript/pages/.gitkeep +0 -0
  71. package/files/typescript/public/index.ts +0 -0
  72. package/files/typescript/styles/.gitkeep +0 -0
  73. package/files/typescript/styles/global.scss +0 -0
  74. package/files/typescript/tsconfig.json +45 -0
  75. package/files/typescript/types/.gitkeep +0 -0
  76. package/package.json +83 -0
  77. package/settings/backend-settings.json +19 -0
  78. package/settings/master-settings.json +17 -0
  79. package/settings/page-settings.json +18 -0
  80. package/settings/public-settings.json +21 -0
  81. package/src/Gulpfile.ts +271 -0
  82. package/src/dev.ts +20 -0
  83. package/src/gulp/backend.ts +52 -0
  84. package/src/gulp/checks.ts +127 -0
  85. package/src/gulp/clean.ts +21 -0
  86. package/src/gulp/copy.ts +26 -0
  87. package/src/gulp/pages.ts +25 -0
  88. package/src/gulp/public.ts +56 -0
  89. package/src/gulp/styles.ts +20 -0
  90. package/src/gulp/templates.ts +25 -0
  91. package/src/gulp/types.ts +87 -0
  92. package/src/index.ts +132 -0
  93. package/src/init.ts +191 -0
  94. package/src/settings.json +91 -0
  95. package/src/types.d.ts +5 -0
  96. package/tsconfig.json +34 -0
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { TaskOptions } from '../Gulpfile';
3
+ export declare function copyFiles(options: TaskOptions): () => NodeJS.ReadWriteStream;
@@ -0,0 +1,22 @@
1
+ import gulp from 'gulp';
2
+ import chalk from 'chalk';
3
+ export function copyFiles(options) {
4
+ const { outputDir } = options;
5
+ return () => {
6
+ return gulp.src([
7
+ 'typescript/**/*',
8
+ '!typescript/*tsconfig.json',
9
+ '!typescript/**/*.ts',
10
+ '!typescript/**/*.tsx',
11
+ '!typescript/types/**/**',
12
+ '!typescript/__mocks__/**/**',
13
+ '!typescript/public/scss/**',
14
+ ])
15
+ .pipe(gulp.dest(outputDir))
16
+ .on('error', function () {
17
+ console.log(chalk.red.underline.bold('Copy of files failed!'));
18
+ this.emit('end');
19
+ })
20
+ .on('end', function () { console.log(chalk.blueBright.underline('Copy of files succeeded!')); });
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { TaksOptions } from '../Gulpfile';
3
+ export declare function buildPages(options: TaksOptions): () => NodeJS.ReadWriteStream;
@@ -0,0 +1,22 @@
1
+ import gulp from 'gulp';
2
+ import chalk from 'chalk';
3
+ import { createGulpEsbuild } from 'gulp-esbuild';
4
+ import * as path from 'path';
5
+ export function buildPages(options) {
6
+ const { outputDir, enableIncrementalBuild } = options;
7
+ const gulpEsbuild = createGulpEsbuild({
8
+ incremental: enableIncrementalBuild, // enables the esbuild's incremental build
9
+ });
10
+ return () => {
11
+ return gulp.src('typescript/pages/*.ts')
12
+ .pipe(gulpEsbuild({
13
+ bundle: false,
14
+ }))
15
+ .pipe(gulp.dest(path.join(outputDir, 'pages')))
16
+ .on('error', function () {
17
+ console.log(chalk.red.underline.bold('Build of Pages TS files failed!'));
18
+ this.emit('end');
19
+ })
20
+ .on('end', function () { console.log(chalk.blueBright.underline('Build of Pages TS files succeeded!')); });
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { TaskOptions } from '../Gulpfile';
3
+ export declare function buildPages(options: TaskOptions): () => NodeJS.ReadWriteStream;
@@ -0,0 +1,22 @@
1
+ import gulp from 'gulp';
2
+ import chalk from 'chalk';
3
+ import { createGulpEsbuild } from 'gulp-esbuild';
4
+ import * as path from 'path';
5
+ export function buildPages(options) {
6
+ const { outputDir, enableIncrementalBuild } = options;
7
+ const gulpEsbuild = createGulpEsbuild({
8
+ incremental: enableIncrementalBuild, // enables the esbuild's incremental build
9
+ });
10
+ return () => {
11
+ return gulp.src('typescript/pages/*.ts')
12
+ .pipe(gulpEsbuild({
13
+ bundle: false,
14
+ }))
15
+ .pipe(gulp.dest(path.join(outputDir, 'pages')))
16
+ .on('error', function () {
17
+ console.log(chalk.red.underline.bold('Build of Pages TS files failed!'));
18
+ this.emit('end');
19
+ })
20
+ .on('end', function () { console.log(chalk.blueBright.underline('Build of Pages TS files succeeded!')); });
21
+ };
22
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import { TaskOptions } from '../Gulpfile';
3
+ export declare function buildPublic(options: TaskOptions): () => NodeJS.ReadWriteStream;
4
+ export declare function buildPublicLib(options: TaskOptions): () => NodeJS.ReadWriteStream;
@@ -0,0 +1,50 @@
1
+ import chalk from 'chalk';
2
+ import gulp from 'gulp';
3
+ import { createGulpEsbuild } from 'gulp-esbuild';
4
+ import * as path from 'path';
5
+ export function buildPublic(options) {
6
+ const { outputDir, enableIncrementalBuild } = options;
7
+ const gulpEsbuild = createGulpEsbuild({
8
+ incremental: enableIncrementalBuild,
9
+ });
10
+ return () => {
11
+ return gulp.src([
12
+ 'typescript/public/**/*.ts',
13
+ 'typescript/public/**/*.tsx',
14
+ ])
15
+ .pipe(gulpEsbuild({
16
+ bundle: false,
17
+ }))
18
+ .pipe(gulp.dest(path.join(outputDir, 'public')))
19
+ .on('error', function () {
20
+ console.log(chalk.red.underline.bold('Build of Public TS files failed!'));
21
+ this.emit('end');
22
+ })
23
+ .on('end', function () {
24
+ console.log(chalk.blueBright.underline('Build of Public TS files succeeded!'));
25
+ });
26
+ };
27
+ }
28
+ export function buildPublicLib(options) {
29
+ const { outputDir, enableIncrementalBuild } = options;
30
+ const gulpEsbuild = createGulpEsbuild({
31
+ incremental: enableIncrementalBuild,
32
+ });
33
+ return () => {
34
+ return gulp.src([
35
+ 'wix-lucy-lib/src/public/**/*.ts',
36
+ 'wix-lucy-lib/src/public/**/*.tsx'
37
+ ])
38
+ .pipe(gulpEsbuild({
39
+ bundle: false,
40
+ }))
41
+ .pipe(gulp.dest(path.join(outputDir, 'public')))
42
+ .on('error', function () {
43
+ console.log(chalk.red.underline.bold('Build of Public (LIB) TS files failed!'));
44
+ this.emit('end');
45
+ })
46
+ .on('end', function () {
47
+ console.log(chalk.blueBright.underline('Build of Public (LIB) TS files succeeded!'));
48
+ });
49
+ };
50
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { TaskOptions } from '../Gulpfile';
3
+ export declare function compileScss(options: TaskOptions): () => NodeJS.ReadWriteStream;
@@ -0,0 +1,17 @@
1
+ import gulp from 'gulp';
2
+ import chalk from 'chalk';
3
+ export function compileScss(options) {
4
+ const { sass, outputDir } = options;
5
+ return () => {
6
+ return gulp.src(['typescript/styles/global.scss'])
7
+ .pipe(sass().on('error', sass.logError))
8
+ .pipe(gulp.dest(`${outputDir}/public/css`))
9
+ .on('error', function () {
10
+ console.log(chalk.red.underline.bold('Compiling of scss files failed!'));
11
+ this.emit('end');
12
+ })
13
+ .on('end', function () {
14
+ console.log(chalk.blueBright.underline('Compiling of scss files succeeded!'));
15
+ });
16
+ };
17
+ }
@@ -0,0 +1 @@
1
+ export declare function previewTemplates(): () => any;
@@ -0,0 +1,21 @@
1
+ import gulp from 'gulp';
2
+ import chalk from 'chalk';
3
+ import exec from 'gulp-exec';
4
+ export function previewTemplates() {
5
+ const options = {
6
+ continueOnError: true,
7
+ };
8
+ return () => {
9
+ return gulp.src([
10
+ 'typescript/backend/templates/**/*.tsx',
11
+ 'typescript/backend/templates/data/*.json',
12
+ '!typescript/backend/templates/render.ts',
13
+ ])
14
+ .pipe(exec((file) => `npx ts-node-esm -T ${file.path}`, options))
15
+ .on('error', function () {
16
+ console.log(chalk.red.underline.bold('Render of Template failed!'));
17
+ this.emit('end');
18
+ })
19
+ .on('end', function () { console.log(chalk.blueBright.underline('Render of Template succeeded!')); });
20
+ };
21
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import gulp from 'gulp';
3
+ import { TaskOptions } from '../Gulpfile';
4
+ export declare function updateWixTypes(options: TaskOptions): () => any;
5
+ export declare function addTypes(options: TaskOptions, done: gulp.TaskFunctionCallback): NodeJS.ReadWriteStream;
@@ -0,0 +1,73 @@
1
+ import chalk from 'chalk';
2
+ import gulp from 'gulp';
3
+ import * as path from 'path';
4
+ import replace from 'gulp-string-replace';
5
+ import foreach from 'gulp-foreach';
6
+ import jeditor from 'gulp-json-editor';
7
+ import merge from 'merge-stream';
8
+ import * as insert from 'gulp-insert';
9
+ export function updateWixTypes(options) {
10
+ const { publicSettings, backendSettings, masterSettings, pageSettings, replaceOpions } = options;
11
+ let count = 0;
12
+ return () => {
13
+ return gulp.src(['./.wix/types/*/*.json', '!./.wix/types/wix-code-types/*.json'])
14
+ .pipe(foreach(function (stream, file) {
15
+ count++;
16
+ if (file.dirname.endsWith('public'))
17
+ return stream.pipe(jeditor(publicSettings));
18
+ if (file.dirname.endsWith('backend'))
19
+ return stream.pipe(jeditor(backendSettings));
20
+ if (file.dirname.endsWith('masterPage'))
21
+ return stream.pipe(jeditor(masterSettings));
22
+ return stream.pipe(jeditor(pageSettings));
23
+ }))
24
+ .pipe(replace('masterPage.masterPage.js', 'masterPage.ts', replaceOpions))
25
+ .pipe(replace('/src/', '/typescript/', replaceOpions))
26
+ .pipe(replace('.js"', '.ts"', replaceOpions))
27
+ // .pipe(tap(function(file) { // tap into the stream to log the output
28
+ // console.log(file.contents?.toString() ?? 'no content');
29
+ // }))
30
+ .pipe(gulp.dest((file) => {
31
+ const filePath = file.dirname;
32
+ const outputDir = path.dirname(filePath);
33
+ return path.join(outputDir);
34
+ }))
35
+ .on('error', function () {
36
+ console.log(chalk.red.underline.bold('Modification of WIX configs failed!'));
37
+ this.emit('end');
38
+ })
39
+ .on('end', function () { console.log(chalk.blueBright.underline(`Modification of ${count} WIX configs succeeded!`)); });
40
+ };
41
+ }
42
+ export function addTypes(options, done) {
43
+ const { replaceOpions, cwd } = options;
44
+ console.log('CWD', cwd);
45
+ const processPages = gulp.src(['./.wix/types/wix-code-types/dist/types/page/$w.d.ts'])
46
+ .pipe(replace('declare namespace \\$w {', ' declare namespace $w{\nconst api: $w.Api;\n', replaceOpions))
47
+ .pipe(gulp.dest('./.wix/types/wix-code-types/dist/types/page/'));
48
+ const exportTypes = gulp.src(['./.wix/types/wix-code-types/dist/types/common/*.d.ts', '!./.wix/types/wix-code-types/dist/types/common/$w.d.ts'])
49
+ .pipe(replace('interface ', 'export interface ', replaceOpions))
50
+ .pipe(replace('enum ', 'export enum ', replaceOpions))
51
+ .pipe(replace('type ', 'export type ', replaceOpions))
52
+ .pipe(gulp.dest('./.wix/types/wix-code-types/dist/types/common/'));
53
+ const exportTypesBeta = gulp.src(['./.wix/types/wix-code-types/dist/types/beta/common/*.d.ts', '!./.wix/types/wix-code-types/dist/types/beta/common/$w.d.ts'])
54
+ .pipe(replace('interface ', 'export interface ', replaceOpions))
55
+ .pipe(replace('enum ', 'export enum ', replaceOpions))
56
+ .pipe(replace('type ', 'export type ', replaceOpions))
57
+ .pipe(gulp.dest('./.wix/types/wix-code-types/dist/types/beta/common/'));
58
+ const processCommon = gulp.src(['./.wix/types/wix-code-types/dist/types/common/$w.d.ts'])
59
+ .pipe(insert.prepend("import { FrontendAPISchema } from '../../../../../../typescript/public/models/common/frontendApi.model';\nimport '@total-typescript/ts-reset';\n"))
60
+ .pipe(replace('namespace \\$w {', 'declare namespace $w{\ntype Api = FrontendAPISchema;\n', replaceOpions))
61
+ .pipe(gulp.dest('./.wix/types/wix-code-types/dist/types/common/'));
62
+ return merge(processPages, processCommon, exportTypesBeta, exportTypes)
63
+ .on('error', function () {
64
+ console.log(chalk.red.underline.bold('Add of new Types (store & Global) failed!'));
65
+ this.emit('end');
66
+ done();
67
+ })
68
+ .on('end', function () {
69
+ console.log(chalk.blueBright.underline('Add of new Types (store & Global) succeeded!'));
70
+ done();
71
+ });
72
+ }
73
+ ;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import { dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { existsSync } from 'fs';
5
+ import chalk from 'chalk';
6
+ import { join } from 'path';
7
+ import fs from 'fs/promises';
8
+ import { init } from './init.js';
9
+ import { dev } from './dev.js';
10
+ // eslint-disable-next-line @typescript-eslint/naming-convention
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ const __dirname = dirname(__filename);
14
+ /**
15
+ *
16
+ */
17
+ async function main() {
18
+ const moduleSettings = {
19
+ packageRoot: dirname(__dirname),
20
+ targetFolder: process.cwd(),
21
+ args: process.argv.slice(2),
22
+ wixConfigPath: join(process.cwd(), 'wix.config.json'),
23
+ lucyConfigPath: join(process.cwd(), 'lucy.json')
24
+ };
25
+ let projectSettings;
26
+ if (!existsSync(moduleSettings.wixConfigPath)) {
27
+ console.log(chalk.red.underline.bold(`This is not a WIX project ${moduleSettings.targetFolder}`));
28
+ return;
29
+ }
30
+ const packageJSONraw = await fs.readFile(join(moduleSettings.targetFolder, 'package.json'), 'utf8');
31
+ const packageJSON = JSON.parse(packageJSONraw);
32
+ if (existsSync(moduleSettings.lucyConfigPath)) {
33
+ try {
34
+ const data = await fs.readFile(moduleSettings.lucyConfigPath, 'utf8');
35
+ projectSettings = JSON.parse(data);
36
+ }
37
+ catch (parseError) {
38
+ console.error(chalk.red.underline.bold('Error parsing Lucy.json', parseError));
39
+ }
40
+ }
41
+ else {
42
+ console.log(chalk.blueBright.underline.bold('Project not Intialized!'));
43
+ return;
44
+ }
45
+ if (packageJSON?.wixLucy?.intialized && !args.includes('-f')) {
46
+ console.error(chalk.red.underline.bold(`This project is already initialized ${moduleSettings.targetFolder}`));
47
+ return;
48
+ }
49
+ console.log({ args, cwd });
50
+ if (args.includes('help') || args.includes('-h')) {
51
+ console.log('Help is on the way!');
52
+ return;
53
+ }
54
+ if (args.includes('version') || args.includes('-v')) {
55
+ console.log('1.0.0');
56
+ return;
57
+ }
58
+ if (args.includes('init')) {
59
+ init(cwd, packageRoot, args);
60
+ return;
61
+ }
62
+ if (args.includes('dev')) {
63
+ dev(cwd, args);
64
+ return;
65
+ }
66
+ if (args.includes('sync')) {
67
+ console.log('Hello serve');
68
+ return;
69
+ }
70
+ }
71
+ main();
72
+ // const fs = require("fs"),
73
+ // path = require("path")
74
+ // /** Parse the command line */
75
+ // var args = process.argv.slice(2);
76
+ // // Validate input
77
+ // if (args.length !== 2) {
78
+ // console.log("Warning: Requires 2 arguments");
79
+ // console.log("node index.js [path/source.html] [targetfile]");
80
+ // process.exit();
81
+ // }
82
+ // const src = args[0];
83
+ // const target = args[1];
84
+ // const dirsrc = path.dirname(src);
85
+ // if (!fs.existsSync(src)) {
86
+ // console.log("Error: Source file doesn't exist. Given: ", src);
87
+ // process.exit();
88
+ // }
package/dist/init.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Init Lucy project
3
+ * @param {string} cwd Current working directory
4
+ * @param {string} packageRoot Package root directory
5
+ * @returns {void}
6
+ */
7
+ export declare function init(cwd: string, packageRoot: string, args: string[]): Promise<void>;
package/dist/init.js ADDED
@@ -0,0 +1,176 @@
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 settings from './settings.json' assert { type: 'json' };
9
+ import path from 'path';
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(cwd, packageRoot, args) {
17
+ const sourceFolder = join(packageRoot, 'files');
18
+ const targetFolder = cwd;
19
+ let projectSettings;
20
+ if (existsSync(join(targetFolder, 'lucy.json'))) {
21
+ try {
22
+ const lucyConfig = join(targetFolder, 'lucy.json');
23
+ const data = await fs.readFile(lucyConfig, 'utf8');
24
+ projectSettings = JSON.parse(data);
25
+ }
26
+ catch (parseError) {
27
+ console.error(chalk.red.underline.bold('Error parsinc Lucy.json', parseError));
28
+ }
29
+ }
30
+ else {
31
+ const lucyConfig = {
32
+ packages: settings.packages,
33
+ modules: settings.modules
34
+ };
35
+ await fs.writeFile(join(targetFolder, 'lucy.json'), JSON.stringify(lucyConfig, null, 2), 'utf8');
36
+ console.log(chalk.blueBright.underline.bold('Created Lucy config file!'));
37
+ }
38
+ const wixConfigPath = join(targetFolder, 'wix.config.json');
39
+ const packageJSONraw = await fs.readFile(join(targetFolder, 'package.json'), 'utf8');
40
+ const packageJSON = JSON.parse(packageJSONraw);
41
+ if (packageJSON?.wixLucy?.intialized && !args.includes('-f')) {
42
+ console.error(chalk.red.underline.bold(`This project is already initialized ${targetFolder}`));
43
+ return;
44
+ }
45
+ if (!existsSync(wixConfigPath)) {
46
+ console.error(chalk.red.underline.bold(`This is not a WIX project ${targetFolder}`));
47
+ return;
48
+ }
49
+ await copyFolder(sourceFolder, targetFolder);
50
+ await editJson(join(targetFolder, 'package.json'), ['type', 'scripts', 'wixLucy'], ['module', settings.scripts, settings.lucySettings]);
51
+ await stringReplace(join(targetFolder, 'currents.config.js'), ['__ProjectName__'], [path.basename(targetFolder)]);
52
+ await installPackages(projectSettings?.packages ? projectSettings?.packages : settings.packages, targetFolder);
53
+ await editJson(join(targetFolder, 'jsconfig.json'), ['compilerOptions', 'exclude'], [settings.wixSettings.compilerOptions, settings.wixSettings.exclude]);
54
+ await editJson(join(targetFolder, 'typedoc.json'), ['name'], [path.basename(targetFolder)]);
55
+ await gitInit(targetFolder, projectSettings?.modules ? projectSettings?.modules : settings.modules);
56
+ console.log(chalk.blueBright.underline.bold('Done!'));
57
+ }
58
+ /**
59
+ * Copy files from source to target
60
+ * @param {string} source Source folder
61
+ * @param {string} target Target folder
62
+ * @returns {Promise<void>}
63
+ */
64
+ async function copyFolder(source, target) {
65
+ if (!existsSync(target)) {
66
+ console.error(chalk.red.underline.bold(`Target folder doesn't exist: ${target}`));
67
+ return;
68
+ }
69
+ try {
70
+ const files = await fsPromises.readdir(source);
71
+ for (const file of files) {
72
+ const sourcePath = join(source, file);
73
+ const targetPath = join(target, file);
74
+ if (file === 'lucy.json' && existsSync(targetPath)) {
75
+ continue;
76
+ }
77
+ const stats = await fsPromises.stat(sourcePath);
78
+ if (stats.isDirectory()) {
79
+ if (!existsSync(file)) {
80
+ mkdirSync(file);
81
+ }
82
+ await fse.copySync(sourcePath, targetPath, { overwrite: true });
83
+ }
84
+ else {
85
+ fse.copySync(sourcePath, targetPath, { overwrite: true });
86
+ }
87
+ }
88
+ }
89
+ catch (err) {
90
+ console.error(chalk.red.underline.bold(err));
91
+ }
92
+ finally {
93
+ console.log(chalk.blueBright.underline.bold('Copy files completed!'));
94
+ }
95
+ }
96
+ /**
97
+ * Edit Json files
98
+ * @param {string} filePath File path
99
+ * @param {string[]} keys Keys to edit
100
+ * @param {string[]} values Values to edit
101
+ * @returns {void}
102
+ */
103
+ async function editJson(filePath, keys, values) {
104
+ try {
105
+ const data = await fs.readFile(filePath, 'utf8');
106
+ let jsonData;
107
+ try {
108
+ jsonData = JSON.parse(data);
109
+ }
110
+ catch (parseError) {
111
+ console.error(chalk.red.underline.bold('Error parsing JSON:', parseError));
112
+ return;
113
+ }
114
+ for (const key of keys) {
115
+ const index = keys.indexOf(key);
116
+ const value = values[index];
117
+ jsonData[key] = value;
118
+ }
119
+ const updatedJsonData = JSON.stringify(jsonData, null, 2);
120
+ await fs.writeFile(filePath, updatedJsonData, 'utf8');
121
+ }
122
+ catch (err) {
123
+ console.log(chalk.red.underline.bold(err));
124
+ }
125
+ finally {
126
+ console.log(chalk.blueBright.underline.bold(`File ${filePath} updated successfully!`));
127
+ }
128
+ }
129
+ async function stringReplace(filePath, keys, values) {
130
+ try {
131
+ let modifiedContent = '';
132
+ const data = await fs.readFile(filePath, 'utf8');
133
+ for (const key of keys) {
134
+ const index = keys.indexOf(key);
135
+ const value = values[index];
136
+ const regex = new RegExp(`${key}`, 'g');
137
+ modifiedContent = data.replace(regex, `${value}`);
138
+ }
139
+ await fs.writeFile(filePath, modifiedContent, 'utf8');
140
+ }
141
+ catch (err) {
142
+ console.log(chalk.red.underline.bold(err));
143
+ }
144
+ finally {
145
+ console.log(chalk.blueBright.underline.bold(`File ${filePath} updated successfully!`));
146
+ }
147
+ }
148
+ async function installPackages(packages, cwd) {
149
+ const packageNames = Object.keys(packages);
150
+ const packageVersions = Object.values(packages);
151
+ const packageNamesAndVersions = packageNames.map((name, index) => `${name}@${packageVersions[index]}`);
152
+ const command = `yarn add ${packageNamesAndVersions.join(' ')}`;
153
+ const result = spawnSync(command, { shell: true, stdio: 'inherit' });
154
+ if (result.error) {
155
+ console.error(chalk.red.underline.bold(`Command failed: ${result.error.message}`));
156
+ }
157
+ else {
158
+ console.log(chalk.blueBright.underline.bold(`Command succeeded: ${result.stdout}`));
159
+ }
160
+ }
161
+ async function gitInit(cwd, modules) {
162
+ const git = simpleGit({ baseDir: cwd });
163
+ for (const [name, url] of Object.entries(modules)) {
164
+ console.log(chalk.green.underline.bold(`Cloning ${name}`));
165
+ try {
166
+ await git.submoduleAdd(url, name);
167
+ }
168
+ catch (e) {
169
+ console.error(chalk.red.underline.bold(`Command failed: ${e}`));
170
+ }
171
+ finally {
172
+ console.log(chalk.blueBright.underline.bold(`Cloned ${name}`));
173
+ }
174
+ }
175
+ console.log(chalk.blueBright.underline.bold(`All Modules cloned!`));
176
+ }
@@ -0,0 +1,91 @@
1
+ {
2
+ "modules": {
3
+ "wix-lucy-lib": "git@github.com:Integral-Systems/wix-lucy-lib.git"
4
+ },
5
+ "wixSettings": {
6
+ "compilerOptions": {
7
+ "composite": true,
8
+ "noEmit": false,
9
+ "lib": [
10
+ "DOM"
11
+ ],
12
+ "jsx": "react"
13
+ },
14
+ "exclude": [
15
+ "**/*.js"
16
+ ]
17
+ },
18
+ "lucySettings": {
19
+ "intialized": true
20
+ },
21
+ "packages": {
22
+ "@danpercic86/helpful-decorators": "^2.4.0",
23
+ "@js-joda/core": "5.5.3",
24
+ "@js-joda/locale": "4.8.10",
25
+ "@js-joda/locale_de": "4.8.10",
26
+ "@js-joda/locale_en": "4.8.10",
27
+ "@js-joda/timezone": "2.18.0",
28
+ "@react-pdf/renderer": "2.0.17",
29
+ "@total-typescript/ts-reset": "^0.4.2",
30
+ "@types/i18n": "^0.13.6",
31
+ "@types/jest": "^29.5.3",
32
+ "@types/node": "^20.5.7",
33
+ "@types/nodemailer": "^6.4.10",
34
+ "@types/react": "^18.2.21",
35
+ "@typescript-eslint/eslint-plugin": "^5.61.0",
36
+ "@typescript-eslint/parser": "^5.61.0",
37
+ "@typescript-eslint/utils": "^5.61.0",
38
+ "@wix/cli": "1.0.83",
39
+ "@wix/eslint-plugin-cli": "^1.0.1",
40
+ "@wix/image": "1.96.0",
41
+ "@wix/velo-bind": "1.0.8",
42
+ "add": "^2.0.6",
43
+ "await-semaphore": "0.1.3",
44
+ "axios": "1.4.0",
45
+ "crypto-js": "4.1.1",
46
+ "cypress": "^12.17.2",
47
+ "cypress-cloud": "^1.9.3",
48
+ "esbuild": "^0.18.11",
49
+ "eslint": "^8.25.0",
50
+ "eslint-plugin-import": "^2.27.5",
51
+ "eslint-plugin-jsdoc": "^46.4.3",
52
+ "eslint-plugin-named-import-spacing": "^1.0.3",
53
+ "eslint-plugin-simple-import-sort": "^10.0.0",
54
+ "eventemitter3": "4.0.7",
55
+ "gsap": "3.11.4",
56
+ "helpful-decorators": "^2.1.0",
57
+ "i18next": "22.4.7",
58
+ "jest": "^29.6.1",
59
+ "merge-stream": "^2.0.0",
60
+ "mobx": "6.8.0",
61
+ "mobx-utils": "6.0.3",
62
+ "node-cache": "5.1.2",
63
+ "nodemailer": "6.9.3",
64
+ "payment": "2.3.0",
65
+ "prettier": "^3.0.3",
66
+ "react": "18.2.0",
67
+ "react-dom": "18.1.0",
68
+ "react-transition-group": "4.4.5",
69
+ "sass": "^1.65.1",
70
+ "ts-jest": "^29.1.1",
71
+ "ts-node": "^10.9.1",
72
+ "tsx": "^3.13.0",
73
+ "typedoc": "^0.25.1",
74
+ "typedoc-theme-hierarchy": "^4.0.0",
75
+ "typescript": "^5.1.6",
76
+ "uuid": "9.0.0",
77
+ "zod": "3.22.2"
78
+ },
79
+ "scripts": {
80
+ "postinstall": "wix sync-types",
81
+ "wix:dev": "wix dev",
82
+ "dev": "gulp dev",
83
+ "lint": "eslint .",
84
+ "docs": "typedoc --tsconfig typescript/tsconfig.json --skipErrorChecking",
85
+ "build": "gulp build-prod",
86
+ "fix-wix": "gulp fix-wix",
87
+ "tsc": "tsc -p ./typescript/tsconfig.json --noEmit",
88
+ "test": "jest --config jest.config.ts --passWithNoTests",
89
+ "test:watch": "jest --config jest.config.ts --watch"
90
+ }
91
+ }