diff --git a/.env.example b/.env.example index 04d8fdf..c47718a 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ -GIT_URI=ssh://git@git.aaro.dev:30009/aarov/vrcboard-website.git +#GIT_URI=ssh://git@git.domain/username/example-repo.git +GIT_URI=https://:@git.domain/username/example-repo.git GIT_BRANCH=main #COMMANDS="['npm i','npm start']" \ No newline at end of file diff --git a/index.js b/index.js index be43acb..e1ef9ef 100644 --- a/index.js +++ b/index.js @@ -3,18 +3,28 @@ const fs = require('fs') const simpleGit = require("simple-git") const path = require("path") +/** + * + * @param {String} a + * @returns + */ +function resolvePath(a) { + a = a.replace("\\",path.sep) + return path.resolve(a) +} + require("dotenv").config() const GIT_URI = process.env.GIT_URI const GIT_BRANCH = process.env.GIT_BRANCH || "main" -const PROJECT_DIR = path.resolve(__dirname + "\\project") +const PROJECT_DIR = resolvePath(__dirname + "\\project") -const KEY_DIR = path.resolve(__dirname + "\\keys") +const KEY_DIR = resolvePath(__dirname + "\\keys") -const KEY_LOCATION = path.resolve(KEY_DIR + "\\deploy.pem") -const KEY_LOCATION_PUBLIC = path.resolve(KEY_LOCATION+".pub") -const KNOWN_HOSTS_FILE = path.resolve(__dirname + "\\known_hosts") +const KEY_LOCATION = resolvePath(KEY_DIR + "\\deploy.pem") +const KEY_LOCATION_PUBLIC = resolvePath(KEY_LOCATION+".pub") +const KNOWN_HOSTS_FILE = resolvePath(__dirname + "\\known_hosts") const KEY_FORMAT = "PEM" const KEY_COMMENT = "nodejs-deploy" @@ -57,6 +67,7 @@ async function tryGenerateKeys() { function onDoneCallback(err, out) { // The error could be related to ssh-keygen binary or file system errors. if (err) { + console.error(err) reject(err); return; } @@ -105,10 +116,11 @@ async function gitMain() { } } +const { execSync, spawn } = require('child_process') + async function ProjectCmd(cmd) { //console.log(`executing "${cmd}"`) const processPromise = new Promise(function(resolve, reject) { - const spawn = require('child_process').spawn; const process = spawn(cmd, { stdio: 'inherit', cwd: PROJECT_DIR, shell:true }); process.on('close', (code) => {