New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

git-pwa

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-pwa - npm Package Compare versions

Comparing version

to
1.0.8

16

git.js
#!/usr/bin/env node
import question from './src/question.js';
import GitLoader from './src/GitLoader.js';
import ora from 'ora';
import ini from 'ini';
import fs from 'fs';
import 'dotenv/config';

@@ -11,15 +8,4 @@

const aIgnoreCommands = ['init', 'status'];
if (!aIgnoreCommands.includes(process.argv[2]) && !process.env['USER_NAME']) {
process.env['USER_NAME'] = await question('Enter your user name: ');
process.env['USER_EMAIL'] = await question('Enter your email: ');
fs.appendFileSync('.env', `USER_NAME="${process.env['USER_NAME']}"\n`);
fs.appendFileSync('.env', `USER_EMAIL="${process.env['USER_EMAIL']}"\n`);
}
if (!aIgnoreCommands.includes(process.argv[2]) && !process.env['USER_TOKEN']) {
process.env['USER_TOKEN'] = await question('Enter your token: ');
fs.appendFileSync('.env', `USER_TOKEN="${process.env['USER_TOKEN']}"\n`);
}
const oLoader = new GitLoader();
await oLoader.checkCommand();
const spinner = ora(`running git ${process.argv[2] || ''} ... `).start();

@@ -26,0 +12,0 @@ try{

2

package.json
{
"name": "git-pwa",
"version": "1.0.7",
"version": "1.0.8",
"description": "git to use in a progressive web app",

@@ -5,0 +5,0 @@ "bin": {

@@ -10,1 +10,17 @@ # git-pwa

2. `npx git-pwa --branch next clone https://github.com/diy-pwa/coming-soon.git .`
### Workflow
This is meant to support the workflow for creating and maintaining a new repo. For instance:
```bash
echo "# testOct15" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/rhildred/testOct15.git
git push -u origin main
```
After it has been pushed, git clones, adds, and commits should be the bulk of what is required. Please let me know by filing an issue if it is not.
import fs from 'fs';
import fsp from 'fs/promises';
import question from './question.js';
import path from 'path';

@@ -10,148 +10,192 @@ import ini from 'ini';

export default class {
constructor(init) {
if (typeof init != 'undefined') {
Object.assign(this, init);
} else {
this.argv = parseArgs(process.argv);
constructor(init) {
if (typeof init != 'undefined') {
Object.assign(this, init);
} else {
this.argv = parseArgs(process.argv);
}
this.base = {
gitdir: '.git',
dir: '.',
fs: fs,
http,
};
this.base.USER_TOKEN = process.env['USER_TOKEN'];
this.base.onAuth = () => ({ username: this.base.USER_TOKEN });
try {
this.config = ini.parse(
fs.readFileSync(`${this.base.dir}/${this.base.gitdir}/config`, 'utf-8')
);
} catch {
this.config = {};
}
this.base.corsProxy = 'https://corsproxy-dqo.pages.dev/corsproxy';
if (this.config && this.config.http && this.config.http.corsProxy) {
this.base.corsProxy = this.config.http.corsProxy;
}
}
this.base = {
gitdir: '.git',
dir: '.',
fs: fs,
http,
};
this.base.USER_TOKEN = process.env['USER_TOKEN'];
this.base.onAuth = () => ({ username: this.base.USER_TOKEN });
try {
this.config = ini.parse(
fs.readFileSync(`${this.base.dir}/${this.base.gitdir}/config`, 'utf-8')
);
} catch {
this.config = {};
async runCommand() {
try {
this.base.ref = await git.currentBranch(this.base);
} catch {
// don't need this
0;
}
this.command = {
add: async (oConfig) => {
let filelist = ['', `on branch ${this.base.ref}`];
if (oConfig.filepath == "." || oConfig.filepath == "all") {
const aFiles = await git.statusMatrix(oConfig);
for (const aFile of aFiles) {
if (aFile[1] == 1 && aFile[2] == 1 && aFile[3] == 1) {
//unchanged
} else {
oConfig.filepath = aFile[0];
await git.add(oConfig);
filelist.push(`added ${aFile[0]}`);
}
}
if (filelist.length <= 2) {
filelist.push("nothing to add");
}
} else {
await git.add(oConfig);
filelist.push(`added ${oConfig.filepath}`);
}
return (filelist.join("\n"));
},
push: async (oConfig) => {
if(this.argv["u"]){
oConfig.remote = this.argv["u"];
oConfig.ref = this.argv._[3];
}
const rc = await git.push(oConfig);
if (rc.ok) {
return 'pushed';
} else {
throw new Error(rc);
}
},
remote: async (oConfig) => {
if (this.argv._[3] == 'add') {
oConfig.remote = this.argv._[4];
oConfig.url = this.argv._[5];
console.log(`remote add ${JSON.stringify(oConfig)}`);
git.addRemote(oConfig);
}
},
status: async (oConfig) => {
if (oConfig.filepath) {
return git.status(oConfig);
} else {
let filelist = ['', `on branch ${this.base.ref}`];
const aFiles = await git.statusMatrix(oConfig);
for (const aFile of aFiles) {
if (aFile[1] == 1 && aFile[2] == 1 && aFile[3] == 1) {
// file is unchanged
} else {
filelist.push(`${aFile[0]}: locally modified`);
}
}
if (filelist.length > 2) {
return filelist.join('\n');
} else {
return 'working folder up to date';
}
}
},
};
const oConfig = this.getConfig();
if (typeof this.command[this.argv._[2]] != 'undefined') {
// add new command
return await this.command[this.argv._[2]](oConfig);
} else if (typeof git[this.argv._[2]] != 'undefined') {
return await git[this.argv._[2]](oConfig);
} else {
throw new Error('unimplemented');
}
}
this.base.corsProxy = 'https://corsproxy-dqo.pages.dev/corsproxy';
if (this.config && this.config.http && this.config.http.corsProxy) {
this.base.corsProxy = this.config.http.corsProxy;
getConfig(){
let oConfig = {};
Object.assign(oConfig, this.base);
this.commandData = {
clone: {
url: this.argv._[3],
ref: this.argv.b || this.argv.branch || 'main',
singleBranch: true,
depth: 10,
dir: this.argv._[4] || path.basename(this.argv._[3] || '', '.git'),
gitdir: undefined,
},
add: {
filepath: this.argv._[3],
},
rm: {
filepath: this.argv._[3],
},
status: {
filepath: this.argv._[3],
},
commit: {
message: this.argv.m,
author: { name: process.env['USER_NAME'], email: process.env['USER_EMAIL'] }
},
addRemote: {
remote: this.argv._[3],
url: this.argv._[4],
},
push: {
remote: this.argv._[3] || 'origin',
ref: this.argv._[4] || this.base.ref,
},
init: {
dir: this.argv._[3] || this.base.dir,
defaultBranch: this.argv.b || this.base.ref,
},
branch: {
ref: this.argv._[3] || this.argv["M"] || this.base.ref,
},
};
if (typeof this.commandData[this.argv._[2]] != 'undefined') {
Object.assign(oConfig, this.commandData[this.argv._[2]]);
}
return oConfig;
}
}
async runCommand() {
try {
this.base.ref = await git.currentBranch(this.base);
} catch {
// don't need this
0;
}
this.commandData = {
clone: {
url: this.argv._[3],
ref: this.argv.b || this.argv.branch || 'main',
singleBranch: true,
depth: 10,
dir: this.argv._[4] || path.basename(this.argv._[3] || '', '.git'),
gitdir: undefined,
},
add: {
filepath: this.argv._[3],
},
rm: {
filepath: this.argv._[3],
},
status: {
filepath: this.argv._[3],
},
commit: {
message: this.argv.m,
author: {name: process.env['USER_NAME'], email: process.env['USER_EMAIL']}
},
addRemote: {
remote: this.argv._[3],
url: this.argv._[4],
},
push: {
remote: this.argv._[3] || 'origin',
ref: this.argv._[4] || this.base.ref,
},
init: {
dir: this.argv._[3] || this.base.dir,
defaultBranch: this.argv.b || this.base.ref,
},
branch: {
ref: this.argv._[3] || this.base.ref,
},
};
this.command = {
add: async (oConfig) => {
let filelist = ['', `on branch ${this.base.ref}`];
if(oConfig.filepath == "." || oConfig.filepath == "all"){
async checkCommand() {
const aIgnoreCommands = ['init', 'status'];
const oConfig = this.getConfig();
if (!aIgnoreCommands.includes(this.argv._[2]) && !process.env['USER_NAME']) {
process.env['USER_NAME'] = await question('Enter your user name: ');
process.env['USER_EMAIL'] = await question('Enter your email: ');
fs.appendFileSync('.env', `USER_NAME="${process.env['USER_NAME']}"\n`);
fs.appendFileSync('.env', `USER_EMAIL="${process.env['USER_EMAIL']}"\n`);
}
if (!aIgnoreCommands.includes(this.argv._[2]) && !process.env['USER_TOKEN']) {
process.env['USER_TOKEN'] = await question('Enter your token: ');
fs.appendFileSync('.env', `USER_TOKEN="${process.env['USER_TOKEN']}"\n`);
}
if(this.argv._[2] == "add" && this.argv._[3] != "." && this.argv._[3] != "all"){
// check for other unadded files
const aFiles = await git.statusMatrix(oConfig);
for(const aFile of aFiles){
if(aFile[1] == 1 && aFile[2] == 1 && aFile[3] == 1){
//unchanged
}else{
oConfig.filepath = aFile[0];
await git.add(oConfig);
filelist.push(`added ${aFile[0]}`);
let bChangedUnadded = false;
for (const aFile of aFiles) {
if(aFile[0] != this.argv._[3] &&
!(aFile[1] == 1 && aFile[2] == 1 && aFile[3] == 1 ) &&
!(aFile[2] == 2 && aFile[3] == 2)){
bChangedUnadded = true;
console.log(aFile[0]);
}
}
if(filelist.length <= 2){
filelist.push("nothing to add");
if(bChangedUnadded){
const sAddAll = await question("These files also have un-added changes ... do you want to add them all to what will be committed (y or n)\n");
if(sAddAll.match(/(y|Y)/)){
this.argv._[3] = ".";
}
}
}else{
await git.add(oConfig);
filelist.push(`added ${oConfig.filepath}`);
}
return(filelist.join("\n"));
},
push: async (oConfig) => {
const rc = await git.push(oConfig);
if (rc.ok) {
return 'pushed';
} else {
throw new Error(rc);
}
},
remote: async (oConfig) => {
if (this.argv._[3] == 'add') {
oConfig.remote = this.argv._[4];
oConfig.url = this.argv._[5];
console.log(`remote add ${JSON.stringify(oConfig)}`);
git.addRemote(oConfig);
}
},
status: async (oConfig) => {
if (oConfig.filepath) {
return git.status(oConfig);
} else {
let filelist = ['', `on branch ${this.base.ref}`];
const aFiles = await git.statusMatrix(oConfig);
for(const aFile of aFiles){
if(aFile[1] == 1 && aFile[2] == 1 && aFile[3] == 1){
// file is unchanged
}else{
filelist.push(`${aFile[0]}: locally modified`);
}
}
if (filelist.length > 2) {
return filelist.join('\n');
} else {
return 'working folder up to date';
}
}
},
};
let oConfig = {};
Object.assign(oConfig, this.base);
if (typeof this.commandData[this.argv._[2]] != 'undefined') {
Object.assign(oConfig, this.commandData[this.argv._[2]]);
}
if (typeof this.command[this.argv._[2]] != 'undefined') {
// add new command
return await this.command[this.argv._[2]](oConfig);
} else if (typeof git[this.argv._[2]] != 'undefined') {
return await git[this.argv._[2]](oConfig);
} else {
throw new Error('unimplemented');
}
}
}