-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a51932
Showing
12 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
|
||
[*.ts] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[*.json] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[Makefile] | ||
indent_size = 4 | ||
indent_style = tab | ||
|
||
[*.md] | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": true, | ||
"deno.suggest.imports.hosts": { | ||
"https://deno.land": true, | ||
"https://cdn.nest.land": true, | ||
"https://crux.land": true | ||
}, | ||
"deno.importMap": "./import_map.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fmt: | ||
deno fmt && dprint fmt | ||
|
||
install-win: | ||
powershell -Command 'iwr https://deno.land/install.ps1 -useb | iex' | ||
powershell -Command 'iwr https://dprint.dev/install.ps1 -useb | iex' | ||
|
||
install-sh: | ||
curl -fsSL https://dprint.dev/install.sh | sh | ||
curl -fsSL https://deno.land/install.sh | s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Octorg | ||
|
||
Octocat help you to organize the repositories | ||
|
||
## Installation | ||
|
||
``` | ||
deno install -A -f --no-check -n octorg --import-map=https://deno.land/x/octorg/import_map.json https://deno.land/x/octorg/cli.ts | ||
``` | ||
|
||
--- | ||
|
||
Made with :heart: in Ecuador |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Denomander from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { CloneRepo } from "git/clone.ts"; | ||
import { GoTooctorg } from "git/goToDir.ts"; | ||
|
||
const app = new Denomander({ | ||
app_name: "octorg", | ||
app_version: "1.0", | ||
app_description: "The best way to organize your github repos!", | ||
}); | ||
|
||
app | ||
.command("get [repo]", "Clone the repo into the octorg path!") | ||
.option("-g --github", "Download with the github preset!") | ||
.option("-n --nofast", "Not clone with the depth flag") | ||
.action(({ repo }: any) => { | ||
let github; | ||
if (typeof app.github == "boolean") { | ||
if (app.github == true) { | ||
github = true; | ||
} else { | ||
github = false; | ||
} | ||
} | ||
let nofast; | ||
if (typeof app.nofast == "boolean") { | ||
if (app.nofast == true) { | ||
nofast = false; | ||
} | ||
} | ||
if (typeof repo == "string") { | ||
nofast = (typeof app.nofast == "undefined") ? true : nofast; | ||
CloneRepo(repo, github, nofast); | ||
} | ||
}); | ||
app | ||
.command("cd", "Go to the path") | ||
.option("-r --repo", "Add the repo url for go more fast!") | ||
.action(() => { | ||
if (typeof app.repo == "string") { | ||
if (app.repo != " ") { | ||
GoTooctorg(app.repo); | ||
} | ||
} | ||
GoTooctorg(); | ||
}); | ||
|
||
app.parse(Deno.args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * as fs from "https://deno.land/[email protected]/fs/mod.ts"; | ||
export * as dirs from "https://deno.land/x/[email protected]/mod.ts"; | ||
export * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
export * as colors from "https://deno.land/[email protected]/fmt/colors.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"incremental": true, | ||
"markdown": { | ||
}, | ||
"includes": ["**/*.{md}"], | ||
"excludes": [], | ||
"plugins": [ | ||
"https://plugins.dprint.dev/markdown-0.12.0.wasm" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { exec } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import * as files from "utils/files.ts"; | ||
import * as log from "utils/logs.ts"; | ||
|
||
function endsWith(str: string, suffix: string) { | ||
return str.indexOf(suffix, str.length - suffix.length) !== -1; | ||
} | ||
|
||
export async function CloneRepo( | ||
repo: string, | ||
github?: boolean, | ||
fast?: boolean, | ||
) { | ||
if (repo.substring(0, 8) === "https://") { | ||
repo = `https://${repo}`; | ||
} | ||
if (github === true && repo.substring(0, 8) != "https://") { | ||
repo = `https://github.com/${repo}`; | ||
} | ||
let cmd = ""; | ||
if (fast === true) { | ||
cmd = `git clone --depth=1 ${repo} ${ | ||
files.GetoctorgPath(repo.replace("https://", "")) | ||
}`; | ||
} else { | ||
cmd = `git clone ${repo} ${ | ||
files.GetoctorgPath(repo.replace("https://", "")) | ||
}`; | ||
} | ||
log.info(`Repo to clone!: ${repo}`); | ||
log.info(`Cmd to execute!: ${cmd}`); | ||
await exec(cmd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as files from "utils/files.ts"; | ||
export function GoTooctorg(repo?: string) { | ||
let cmd; | ||
if (typeof repo == "string") { | ||
cmd = repo.replace("https://", ""); | ||
console.log(files.GetoctorgPath(cmd)); | ||
|
||
Deno.exit(2); | ||
} | ||
cmd = files.GetoctorgPath(" "); | ||
console.log(cmd); | ||
Deno.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"imports": { | ||
"src/": "./src/", | ||
"@/": "./", | ||
"runner/": "./runner/", | ||
"utils/": "./utils/", | ||
"git/": "./git/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { dirs, fs, path } from "@/deps.ts"; | ||
import * as log from "utils/logs.ts"; | ||
|
||
export const currentDir: string = Deno.cwd(); | ||
|
||
export const configDir: string = dirs.baseDirs.setup().configDir; | ||
export const homeDir: string = dirs.baseDirs.setup().homeDir; | ||
|
||
/** | ||
* The function to generate and create if dont exists the logs folder | ||
* @param file File to joint to the log path | ||
* @returns {string} Path to the octorg log folder | ||
*/ | ||
export function getLogPath(file: string): string { | ||
const cacheDir: string = dirs.baseDirs.setup().cacheDir; | ||
if (existsFile(path.join(cacheDir, "octorg")) != true) { | ||
Deno.mkdir(path.join(cacheDir, "octorg")); | ||
log.info("octorg folder created"); | ||
} | ||
return path.join(cacheDir, "octorg", file); | ||
} | ||
|
||
/** | ||
* Function to generate the folder and get the path | ||
* @param file File to join to the config dir | ||
* @returns {string} Path to the octorg config folder | ||
*/ | ||
export function getConfigDir(file: string): string { | ||
if (existsFile(path.join(configDir, "octorg")) != true) { | ||
Deno.mkdir(path.join(configDir, "octorg")); | ||
log.info("octorg config folder created"); | ||
} | ||
return path.join(configDir, "octorg", file); | ||
} | ||
|
||
export function GetoctorgPath(folderName: string): string { | ||
if (existsFile(path.join(homeDir, "octorg")) != true) { | ||
Deno.mkdir(path.join(homeDir, "octorg")); | ||
log.info("octorg Path base is created!"); | ||
} | ||
return path.join(homeDir, "octorg", folderName); | ||
} | ||
|
||
/** | ||
* Write a json to any path and log | ||
* @param path Path to write the json | ||
* @param data Data to write the json | ||
*/ | ||
export function writeJson(path: string, data: Record<string, unknown>) { | ||
try { | ||
Deno.writeTextFileSync(path, JSON.stringify(data)); | ||
log.info("Writed the new config.json file!"); | ||
} catch (e) { | ||
log.error(e); | ||
} | ||
} | ||
|
||
/** | ||
* Check if file or folder exists | ||
* @param file File or folder to check if exists | ||
* @returns {boolean} Result true if exists or false if not | ||
*/ | ||
export function existsFile(file: string): boolean { | ||
if (fs.existsSync(file)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as log from "https://deno.land/[email protected]/log/mod.ts"; | ||
import { colors } from "@/deps.ts"; | ||
import { getLogPath } from "utils/files.ts"; | ||
|
||
export const Headers = { | ||
octorgHeader: `octorg ->`, | ||
logsSym: { | ||
info: "ⓘ INFO:", | ||
error: "✗ ERROR:", | ||
warn: "⚠ WARNING:", | ||
}, | ||
}; | ||
|
||
await log.setup({ | ||
handlers: { | ||
file: new log.handlers.FileHandler("INFO", { | ||
filename: getLogPath("octorg.log"), | ||
formatter: "[ octorg ]: {levelName} -> {msg}", | ||
}), | ||
infoFormatter: new log.handlers.ConsoleHandler("INFO", { | ||
formatter: (logRecord: any) => { | ||
const InfoSym = colors.brightCyan(Headers.logsSym.info); | ||
return `${InfoSym} ${logRecord.msg}`; | ||
}, | ||
}), | ||
errorFormatter: new log.handlers.ConsoleHandler("ERROR", { | ||
formatter: (logRecord: any) => { | ||
const ErrorSym = colors.brightRed(Headers.logsSym.error); | ||
return `${ErrorSym} ${logRecord.msg}`; | ||
}, | ||
}), | ||
warnFormatter: new log.handlers.ConsoleHandler("WARNING", { | ||
formatter: (logRecord: any) => { | ||
const WarnSym = colors.brightYellow(Headers.logsSym.warn); | ||
return `${WarnSym} ${logRecord.msg}`; | ||
}, | ||
}), | ||
}, | ||
|
||
loggers: { | ||
infoFmt: { | ||
level: "INFO", | ||
handlers: ["file", "infoFormatter"], | ||
}, | ||
errorFmt: { | ||
level: "ERROR", | ||
handlers: ["file", "errorFormatter"], | ||
}, | ||
warnFmt: { | ||
level: "WARNING", | ||
handlers: ["file", "warnFormatter"], | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* Log to the info level and add to the octorg.log file | ||
* @param message Message to log | ||
*/ | ||
export function info(message: string) { | ||
log.getLogger("infoFmt").info(`${Headers.octorgHeader} ${message} `); | ||
} | ||
|
||
/** | ||
* Log to the warning level and add to the octorg.log file | ||
* @param message Message to log | ||
*/ | ||
export function warn(message: string) { | ||
log.getLogger("warnFmt").warning(`${Headers.octorgHeader} ${message}`); | ||
} | ||
|
||
/** | ||
* Log to the error level, add to the octorg.log and exit to 2 code | ||
* @param message Message to log | ||
*/ | ||
export function error(message: string) { | ||
log.getLogger("errorFmt").error(`${Headers.octorgHeader} ${message}`); | ||
Deno.exit(2); | ||
} |