Skip to content

Commit

Permalink
Restructured library
Browse files Browse the repository at this point in the history
  • Loading branch information
IHateYourCode committed Oct 8, 2022
1 parent cdca3c6 commit c788085
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 232 deletions.
90 changes: 0 additions & 90 deletions Source/Build.js

This file was deleted.

34 changes: 21 additions & 13 deletions Source/Graphics.js → Source/Deco.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { width } from './Terminal.js';



const { floor , ceil } = Math;
const { log } = console;


const content = (text) => text
Expand All @@ -13,13 +13,21 @@ const contentWidth = (text) =>
content(text).length;


export function print ( ... args ){
log( ... args );
}

export function clear (){
console.clear();
}


export function spacer(project,lines){
project.log('\n'.repeat(lines - 1));
export function spacer(lines){
log('\n'.repeat(lines - 1));
}


export function separator(project,symbol = ' '){
export function separator(symbol = ' '){

const symbolWidth = contentWidth(symbol);

Expand All @@ -37,26 +45,26 @@ export function separator(project,symbol = ' '){
if(lineWidth < columns)
line += symbol.substring(0,columns - lineWidth);

project.log(line);
log(line);
}

export function header(project,symbol = ' ',text = ''){
export function header({ fill = ' ' , text = '' }){

const
textWidth = contentWidth(text),
symbolWidth = contentWidth(symbol);
symbolWidth = contentWidth(fill);

let padding = width();
padding -= textWidth;
padding -= 2 * symbolWidth;
padding *= 0.5;

const header =
symbol +
project.spacer.repeat(floor(padding)) + text +
project.spacer.repeat(ceil(padding)) + symbol;
fill +
' '.repeat(floor(padding)) + text +
' '.repeat(ceil(padding)) + fill;

separator(project,symbol);
project.log(header);
separator(project,symbol);
separator(fill);
log(header);
separator(fill);
}
50 changes: 30 additions & 20 deletions Source/Files.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@

import { Path } from './Imports.js';
import { fromFileUrl , dirname }
from 'https://deno.land/[email protected]/path/mod.ts';

import { ensureDir , emptyDir , walk }
from 'https://deno.land/[email protected]/fs/mod.ts'

export { join }
from 'https://deno.land/[email protected]/path/mod.ts';

export async function discover(path,options){

const files = [];
export function folder ( meta ){
return dirname(fromFileUrl(meta.url));
}


try {
export async function prepare ({ empty , path }){

const action = (empty)
? emptyDir
: ensureDir ;

await action(path);
}

for await (const dir of Deno.readDir(path)){

const { name , isFile , isDirectory } = dir;
export async function discover ({ extension , subfolders , path }){

const filepath = Path.join(path,name);
const paths = [];

switch(true){
case isFile:
if(name.endsWith(options.extension))
files.push(filepath);
continue;
case isDirectory:
files.push(... await discover(filepath,options));
continue;
}
}
} catch (e) {
console.error(e);
const options = {
maxDepth : subfolders ? Math.Infinity : 1 ,
includeDirs : false ,
includeFiles : true ,
followSymlinks : false ,
exts : [ extension ]
}

return files;
for await (const entry of walk(path,options))
paths.push(entry.path);

return paths;
}
22 changes: 22 additions & 0 deletions Source/Formatting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import { green , dim , blue }
from 'https://deno.land/[email protected]/fmt/colors.ts'


export function prettyPath ( path , options = {} ){

const {
folderColor = green ,
separator = dim(blue('/'))
} = options;


if(path.startsWith('file:'))
path = path.slice(7);


return path
.split('/')
.map((folder) => folderColor(folder))
.join(separator);
}
37 changes: 24 additions & 13 deletions Source/GCC.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@

import { Files , Path } from './Imports.js';
import { dirname , join }
from 'https://deno.land/[email protected]/path/mod.ts';

import { ensureDir }
from 'https://deno.land/[email protected]/fs/mod.ts'


const { run , writeFile , remove } = Deno;
const { join , dirname } = Path;
const { ensureDir } = Files;


export default async function gcc(options = {}){
export async function gcc ( options = {} ){

const { buildFolder } = options;
const { paths , names } = options;

const GCC = join(buildFolder,'GCC.sh');
const GCC = join(paths.build,'GCC.sh');

const encoder = new TextEncoder();
const data = encoder.encode(`g++ $@`);
Expand All @@ -20,47 +23,55 @@ export default async function gcc(options = {}){
'./GCC.sh' ,
'-std=c++20' ,
'-fmodules-ts'
];
]


const { verbose } = options;

if(verbose)
parameters.push(`-v`);


const { language } = options;

if(language)
parameters.push(`-x ${ language }`);


const { compileObject } = options;

if(compileObject)
parameters.push('-c');


const { compileAssembly } = options;

if(compileAssembly)
parameters.push('-S');


const { onlyPreprocess } = options;

if(onlyPreprocess)
parameters.push('-E');


const { other } = options;

if(other)
parameters.push(...other);

const { executable } = options;

const { executable } = names;

if(executable)
parameters.push(`-o${ join(buildFolder,executable) }`);
parameters.push(`-o${ join(paths.build,executable) }`);

let { modules , main } = options;
const { input } = paths;
const { main } = names;

if(modules && main){
parameters.push(...[...modules.filter(file => !file.endsWith(main)),modules.find((file) => file.endsWith(main))]);
if(input && main){
parameters.push(...[...input.filter(file => !file.endsWith(main)),input.find((file) => file.endsWith(main))]);
}


Expand All @@ -69,7 +80,7 @@ export default async function gcc(options = {}){

const process = await run({
cmd : parameters ,
cwd : buildFolder ,
cwd : paths.build ,
stdout : 'piped' ,
stderr : 'piped'
});
Expand Down
4 changes: 0 additions & 4 deletions Source/Imports.js

This file was deleted.

23 changes: 0 additions & 23 deletions Source/Pretty.js

This file was deleted.

Loading

0 comments on commit c788085

Please sign in to comment.