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/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 diff --git a/replace_nodemodules_by_submodules.sh b/replace_nodemodules_by_submodules.sh new file mode 100755 index 00000000..5664643d --- /dev/null +++ b/replace_nodemodules_by_submodules.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +submodule_paths=$(find ./packages -maxdepth 1 -mindepth 1 -type d) + +for submodule_path in ${submodule_paths[*]}; do + 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