Skip to content

Commit

Permalink
Added gen command to create cpp template for CP and added metadata.js…
Browse files Browse the repository at this point in the history
…on. Created two utilities for printing Errors and Success
  • Loading branch information
codesculpture committed Oct 22, 2022
1 parent f83a06e commit 5436ce5
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
tests
*.exe
build
rust
go
cpp
native-cpp
.gitignore
deno/binaries
Expand Down
10 changes: 7 additions & 3 deletions deno/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { bold, blue,green, red, yellow, italic} from "https://deno.land/[email protected]/fmt/colors.ts";
import {checkFolder, showVersion} from "./src/index.ts";
import {checkFolder, generateTemplate, showVersion} from "./src/index.ts";

const printFileError = (): void => {
console.log(red(bold("Error At Loading File. Please Make Sure You provided correct Name")));
}


if(Deno.args[0] == undefined) {
printFileError();
console.log(bold(blue("Welcome To CMON :) !@^%&*(@!")));
Deno.exit(0);
}
if(Deno.args[0] == 'version') {
else if(Deno.args[0] == 'version') {
console.log(bold(yellow('Version')));
console.log(showVersion());
Deno.exit(0);
}

else if(Deno.args[0] == 'gen' && Deno.args[1]){
generateTemplate(Deno.args[1]);
Deno.exit(0);
}
const PATH = Deno.args[0];

const fileNameArr = Deno.args[0].split('/');
Expand Down
5 changes: 5 additions & 0 deletions deno/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"author": "Deepak Aravind",
"github": "https://github.com/codesculpture/cmon",
"version": "1.0.2-alpha"
}
35 changes: 35 additions & 0 deletions deno/src/genCP/createTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {printError, printSuccess} from "../index.ts";
const content = `#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vp vector<pair<int, int>>
#define pb push_back
#define pi pair<int, int>
using namespace std;
void solve() {
//Crack It..
}
int main() {
int T;
cin >> T;
while(T--) solve();
return 0;
}
`


const generateTemplate = (name: string): void => {

try{
Deno.writeTextFile(name+".cpp", content);
printSuccess(`Created Template ${name}.cpp Open in your Code Editor`);
}
catch(e){
printError({name: 'At Creating Template', code: e.message})
}
}

export default generateTemplate;
6 changes: 4 additions & 2 deletions deno/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import checkFolder from './checkFolder/checkFolder.ts';
import showVersion from './version/version.ts'
import printError from './print/printError.ts';
import printSuccess from './print/printSuccess.ts';
import generateTemplate from './genCP/createTemplate.ts';


export {checkFolder, showVersion};
export {checkFolder, showVersion, generateTemplate, printError, printSuccess};
7 changes: 7 additions & 0 deletions deno/src/print/printError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { bold, blue,green, red, yellow, italic} from "https://deno.land/[email protected]/fmt/colors.ts";

const printError = ({name, code}: {name: string, code:string}): void => {
console.log(bold(red(`Error At ${name} Code:${code}`)));
}

export default printError;
7 changes: 7 additions & 0 deletions deno/src/print/printSuccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { bold, blue,green, red, yellow, italic} from "https://deno.land/[email protected]/fmt/colors.ts";

const printSuccess = (message: string): void =>{
console.log(green(`Successfully ${message}!`));
}

export default printSuccess;
8 changes: 0 additions & 8 deletions deno/src/version/version.test.ts

This file was deleted.

5 changes: 2 additions & 3 deletions deno/src/version/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "https://deno.land/x/dotenv/load.ts";

import meta from '../../metadata.json' assert {type: "json"};
const showVersion = (): string | undefined => {
return Deno.env.get('VERSION');
return meta.version;
}

export default showVersion;

0 comments on commit 5436ce5

Please sign in to comment.