Skip to content

Add replace-node-modules-by-submodules guls task #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build_submodules.sh
Original file line number Diff line number Diff line change
@@ -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
49 changes: 45 additions & 4 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
},
})
}
}
});
14 changes: 14 additions & 0 deletions replace_nodemodules_by_submodules.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions unbuild_submodules.sh
Original file line number Diff line number Diff line change
@@ -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