From 00dd22ff2940559b26bfc1fde1474f685342f49c Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 22 Dec 2022 02:13:19 +0600 Subject: [PATCH 1/6] Add bash script to find submodules dependands and replace nodemodules by submodules --- replace_nodemodules_by_submodules.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 replace_nodemodules_by_submodules.sh diff --git a/replace_nodemodules_by_submodules.sh b/replace_nodemodules_by_submodules.sh new file mode 100644 index 00000000..bc6a9c9c --- /dev/null +++ b/replace_nodemodules_by_submodules.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +submodule_paths=$(find ./packages -maxdepth 1 -mindepth 1 -type d) + +for submodule_path in ${submodule_paths[*]}; do + dependants_node_modules_paths=$(find ./ -type d -wholename "*node_modules/@deep-foundation/$(basename ${submodule_path})") + for dependant_node_modules_path in ${dependants_node_modules_paths[*]}; do + { + printf "Copying ${submodule_path} to ${dependant_node_modules_path} excluding node_modules \n" & + rsync --archive --exclude='./packages/hasura/node_modules' ${submodule_path} ${dependant_node_modules_path} & + } + done +done From 5f33ce1457e36382ffdb8aa2c0cf04ad9fe5f19a Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 22 Dec 2022 14:05:03 +0600 Subject: [PATCH 2/6] Copy synchronously --- replace_nodemodules_by_submodules.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/replace_nodemodules_by_submodules.sh b/replace_nodemodules_by_submodules.sh index bc6a9c9c..338af5fa 100644 --- a/replace_nodemodules_by_submodules.sh +++ b/replace_nodemodules_by_submodules.sh @@ -5,9 +5,7 @@ submodule_paths=$(find ./packages -maxdepth 1 -mindepth 1 -type d) for submodule_path in ${submodule_paths[*]}; do dependants_node_modules_paths=$(find ./ -type d -wholename "*node_modules/@deep-foundation/$(basename ${submodule_path})") for dependant_node_modules_path in ${dependants_node_modules_paths[*]}; do - { - printf "Copying ${submodule_path} to ${dependant_node_modules_path} excluding node_modules \n" & - rsync --archive --exclude='./packages/hasura/node_modules' ${submodule_path} ${dependant_node_modules_path} & - } + printf "Copying ${submodule_path} to ${dependant_node_modules_path} excluding node_modules \n" + rsync --archive --exclude='./packages/hasura/node_modules' ${submodule_path} ${dependant_node_modules_path} done done From 8af1d3fc7b5f63bbe6a8bf92bc5730ed6ef875f9 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 22 Dec 2022 14:05:40 +0600 Subject: [PATCH 3/6] Revert package.json changes --- .vscode/settings.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 442837fe..ac269204 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "workbench.colorTheme": "Starfall Ocean", + "workbench.colorTheme": "Default Dark+", "editor.tabSize": 2, "files.autoSave": "off", "workbench.colorCustomizations": { @@ -7,5 +7,6 @@ "titleBar.activeBackground": "#181818", "titleBar.activeForeground": "#F9FAFF" }, - "editor.wordWrap": "on" + "editor.wordWrap": "on", + "typescript.tsdk": "node_modules/typescript/lib" } \ No newline at end of file From e9b903ef603f6695bb26f41f13911bd41a708c3c Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 22 Dec 2022 14:09:00 +0600 Subject: [PATCH 4/6] Revert settings.json changes --- .vscode/settings.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ac269204..442837fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "workbench.colorTheme": "Default Dark+", + "workbench.colorTheme": "Starfall Ocean", "editor.tabSize": 2, "files.autoSave": "off", "workbench.colorCustomizations": { @@ -7,6 +7,5 @@ "titleBar.activeBackground": "#181818", "titleBar.activeForeground": "#F9FAFF" }, - "editor.wordWrap": "on", - "typescript.tsdk": "node_modules/typescript/lib" + "editor.wordWrap": "on" } \ No newline at end of file From 89e90b70d2c9d8743806ecbfb68c71c1d025dae0 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Fri, 23 Dec 2022 14:01:23 +0600 Subject: [PATCH 5/6] Update bash scripts --- build_submodules.sh | 13 +++++++++++++ replace_nodemodules_by_submodules.sh | 11 +++++++---- unbuild_submodules.sh | 13 +++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100755 build_submodules.sh mode change 100644 => 100755 replace_nodemodules_by_submodules.sh create mode 100755 unbuild_submodules.sh diff --git a/build_submodules.sh b/build_submodules.sh new file mode 100755 index 00000000..3ca52c27 --- /dev/null +++ b/build_submodules.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +initial_directory=${PWD} +submodule_paths=$(find ./packages -maxdepth 1 -mindepth 1 -type d) + +for submodule_path in ${submodule_paths[*]}; do + cd ${submodule_path} + if grep -q '"package:build":' ./package.json; then + printf "Building ${submodule_path}\n" + npm run package:build + fi + cd ${initial_directory} +done diff --git a/replace_nodemodules_by_submodules.sh b/replace_nodemodules_by_submodules.sh old mode 100644 new mode 100755 index 338af5fa..5664643d --- a/replace_nodemodules_by_submodules.sh +++ b/replace_nodemodules_by_submodules.sh @@ -3,9 +3,12 @@ submodule_paths=$(find ./packages -maxdepth 1 -mindepth 1 -type d) for submodule_path in ${submodule_paths[*]}; do - dependants_node_modules_paths=$(find ./ -type d -wholename "*node_modules/@deep-foundation/$(basename ${submodule_path})") - for dependant_node_modules_path in ${dependants_node_modules_paths[*]}; do - printf "Copying ${submodule_path} to ${dependant_node_modules_path} excluding node_modules \n" - rsync --archive --exclude='./packages/hasura/node_modules' ${submodule_path} ${dependant_node_modules_path} + for dependant_submodule_path in ${submodule_paths[*]}; do + dependant_node_module_dependency_path="${dependant_submodule_path}/node_modules/@deep-foundation/$(basename ${submodule_path})" + if [ -d $dependant_node_module_dependency_path ] + then + printf "Copying ${submodule_path} to ${dependant_node_module_dependency_path} without ${submodule_path}/node_modules \n"; + rsync --archive --exclude='${submodule_path}/node_modules' ${submodule_path} ${dependant_node_module_dependency_path} + fi done done diff --git a/unbuild_submodules.sh b/unbuild_submodules.sh new file mode 100755 index 00000000..8f7b5fa2 --- /dev/null +++ b/unbuild_submodules.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +initial_directory=${PWD} +submodule_paths=$(find ./packages -maxdepth 1 -mindepth 1 -type d) + +for submodule_path in ${submodule_paths[*]}; do + cd ${submodule_path} + if grep -q '"package:unbuild":' ./package.json; then + printf "Unbuilding ${submodule_path}\n" + npm run package:unbuild + fi + cd ${initial_directory} +done From 2b7c1d123c34526010e441f0dfbb7c3b0d513146 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Sat, 24 Dec 2022 02:32:18 +0600 Subject: [PATCH 6/6] Add draft --- gulpfile.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 2dcae372..552362a6 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -1,12 +1,13 @@ import url from 'url'; import del from 'del'; -import fs from 'fs'; +import fsExtra from 'fs-extra'; import concurrently from 'concurrently'; import minimist from 'minimist'; import * as gulp from 'gulp'; import Git from 'simple-git/promise'; import { HasuraApi } from '@deep-foundation/hasura/api'; +import * as pathUtils from 'path'; process.setMaxListeners(0); @@ -98,7 +99,7 @@ gulp.task('gitpod:hasura:reattach', async () => { }); gulp.task('assets:update', () => { - const packages = fs.readdirSync(`${__dirname}/packages`); + const packages = fsExtra.readdirSync(`${__dirname}/packages`); let g = gulp.src('assets/*', { base: 'assets' }).pipe(gulp.dest(`./`)); for (let p in packages) { const pckg = packages[p]; @@ -137,7 +138,7 @@ gulp.task('packages:ci', async () => { }); const getModules = () => { - const gitmodules = fs.readFileSync(`${__dirname}/.gitmodules`, { encoding: 'utf8' }); + const gitmodules = fsExtra.readFileSync(`${__dirname}/.gitmodules`, { encoding: 'utf8' }); const modulesArray: any = gitmodules.split('[').filter(m => !!m).map((m, i) => m.split(` `).map((p, i) => !i ? p.split(' ')[1].slice(1, process.platform === 'win32' ? -3 : -2) : p.replace('\n', '').split(' = '))); const modules = {}; @@ -175,7 +176,7 @@ gulp.task('packages:set', async () => { }); gulp.task('packages:sync', async () => { - const packages = fs.readdirSync(`${__dirname}/packages`); + const packages = fsExtra.readdirSync(`${__dirname}/packages`); const npmPackages = {}; console.log('find buildable packages'); for (let p in packages) { @@ -246,3 +247,43 @@ gulp.task('packages:sync', async () => { } catch (error) {} } }); + +gulp.task('replace-node-modules-by-submodules', async () => { + // TODO: Replace node modules not only for submodules but for dev monorepository too + + const packagesDirectoryPath = pathUtils.resolve('packages'); + + const submodulePathArray = fsExtra.readdirSync(packagesDirectoryPath).map((name) => + pathUtils.resolve(packagesDirectoryPath, name) + ); + console.log({ submodulePathArray }); + + + for (const submodulePath of submodulePathArray) { + for (const dependantSubmodulePath of submodulePathArray) { + + const dependantDependencyNodeModulePath = pathUtils.resolve( + dependantSubmodulePath, + 'node_modules', + '@deep-foundation', + pathUtils.basename(submodulePath) + ); + + + if (!fsExtra.existsSync(dependantDependencyNodeModulePath)) { + continue; + } + console.info(`Copying ${submodulePath} to ${dependantDependencyNodeModulePath}`) + fsExtra.rmSync(dependantDependencyNodeModulePath, {force: true, recursive: true}); + fsExtra.mkdirSync(dependantDependencyNodeModulePath); + fsExtra.copySync(submodulePath, dependantDependencyNodeModulePath, { + recursive: true, + filter: (path) => { + console.log({path}) + console.log(`path == pathUtils.join(submodulePath, "node_modules")` ,path == pathUtils.join(submodulePath, "node_modules")) + return false; + }, + }) + } + } +}); \ No newline at end of file