Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@andrewstart/submodule-helper

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@andrewstart/submodule-helper - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

108

index.js

@@ -7,2 +7,3 @@ const util = require('util');

const path = require('path');
const { Command } = require('commander');

@@ -41,18 +42,39 @@ async function exec(command, cwd, returnVal = false)

async function main()
async function readBranches(configPath)
{
const args = process.argv.slice(2);
const modules = await readModules('.gitmodules');
let targetModule = args[1];
if (targetModule && targetModule.endsWith('/'))
const branches = new Map();
try
{
targetModule = targetModule.substring(0, targetModule.length - 1);
const lines = (await readFile(configPath, 'utf8')).split(/[\r\n]+/);
for (const line of lines)
{
const [module, branch] = line.split(' ');
branches.set(module, branch);
}
}
let secondaryTarget = args[2];
if (secondaryTarget && secondaryTarget.endsWith('/')) {
secondaryTarget = secondaryTarget.substring(0, secondaryTarget.length - 1);
catch (e)
{
// optional file is probably not present, just eat the error
}
switch (args[0])
{
case 'clean':
return branches;
}
function cleanModuleName(module)
{
if (module && module.endsWith('/'))
return module.substring(0, module.length - 1);
return module;
}
async function main()
{
const modules = await readModules('.gitmodules');
const branches = await readBranches('.modulebranches');
const program = new Command();
program
.command('clean [targetModule]')
.description('Removes all changes in all submodules, or a single submodule.')
.action(async (targetModule) => {
targetModule = cleanModuleName(targetModule);
for (const module of modules)

@@ -68,4 +90,8 @@ {

}
break;
case 'checkout':
});
program
.command('checkout [targetModule]')
.description('Checks out submodule(s) to current commit, and installs dependencies via pnpm.')
.action(async (targetModule) => {
targetModule = cleanModuleName(targetModule);
for (const module of modules)

@@ -76,6 +102,14 @@ {

await exec(`git submodule update --init ${module}`);
if (branches.has(module))
{
await exec(`git checkout ${branches.get(module)}`, path.resolve(process.cwd(), module));
}
await exec(`pnpm i -P`, path.resolve(process.cwd(), module));
}
break;
case 'pull':
});
program
.command('pull [targetModule]')
.description('Pulls latest commit in submodule(s).')
.action(async (targetModule) => {
targetModule = cleanModuleName(targetModule);
for (const module of modules)

@@ -88,4 +122,8 @@ {

}
break;
case 'remove':
});
program
.command('remove [targetModule]')
.description('Removes submodule(s) from repository.')
.action(async (targetModule) => {
targetModule = cleanModuleName(targetModule);
for (const module of modules)

@@ -99,14 +137,22 @@ {

}
break;
case 'list':
});
program
.command('list')
.description('Lists all submodules in the repository.')
.action(async () => {
console.log(modules.join('\n'));
break;
case 'sync':
if (!targetModule) return;
let hash = await exec('git rev-parse HEAD', path.resolve(process.cwd(), targetModule), true);
});
program
.command('sync <moduleDependency> [targetModule]')
.description('Updates submodule(s) version of the shared dependency (also a submodule) to current commit.')
.action(async (moduleDependency, targetModule) => {
if (!moduleDependency) return;
moduleDependency = cleanModuleName(moduleDependency);
targetModule = cleanModuleName(targetModule);
let hash = await exec('git rev-parse HEAD', path.resolve(process.cwd(), moduleDependency), true);
hash = hash.trim();
for (const module of modules)
{
if (targetModule === module) continue;
if (secondaryTarget && secondaryTarget !== module) continue;
if (moduleDependency === module) continue;
if (targetModule && targetModule !== module) continue;

@@ -116,9 +162,9 @@ const nestedModules = await readModules(path.join(module, '.gitmodules'));

{
if (nest === targetModule)
if (nest === moduleDependency)
{
console.log(`Ensuring that ${module} is up to date...`);
const modulePath = path.resolve(process.cwd(), module);
let mode = await exec(`git ls-files --stage ${targetModule}`, modulePath, true);
let mode = await exec(`git ls-files --stage ${moduleDependency}`, modulePath, true);
mode = mode.substring(0, mode.indexOf(' '));
await exec(`git update-index --add --cacheinfo ${mode},${hash},${targetModule}`, modulePath);
await exec(`git update-index --add --cacheinfo ${mode},${hash},${moduleDependency}`, modulePath);
break;

@@ -128,6 +174,6 @@ }

}
break;
}
});
return program.parseAsync();
}
main();
{
"name": "@andrewstart/submodule-helper",
"version": "1.1.2",
"version": "1.2.0",
"description": "Helps in a few git submodule tasks",

@@ -24,2 +24,3 @@ "main": "index.js",

"dependencies": {
"commander": "^10.0.0",
"rimraf": "^3.0.2"

@@ -26,0 +27,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc