proper argument typings. devMode ON

stable
Valerie 2021-12-22 08:35:48 -05:00
parent 5ca6f94e04
commit 562bc94f9b
5 changed files with 35 additions and 12 deletions

View File

@ -55,5 +55,6 @@
"SLOT3": "0F0B6AEB69754319A7E480E3989F7E54", "SLOT3": "0F0B6AEB69754319A7E480E3989F7E54",
"SLOT4": "34064741B6324D9BBCEE0A1364F21220", "SLOT4": "34064741B6324D9BBCEE0A1364F21220",
"SLOT5": "18461538E5A1487EBC9F54040295440A" "SLOT5": "18461538E5A1487EBC9F54040295440A"
} },
"devMode": true
} }

View File

@ -1,13 +1,14 @@
import { system } from '@kernel:base'; import { system, ParsedSystemState } from '@kernel:base';
import { resolve } from 'path'; import { resolve } from 'path';
import { writeFileSync } from 'fs'; import { writeFileSync } from 'fs';
export default function save() { export default function save() {
const timeStart = new Date().getTime(); const timeStart = new Date().getTime();
const obj: any = { const obj: ParsedSystemState = {
handoff: system.handoff, handoff: system.handoff,
instances: {}, instances: {},
aliases: {} aliases: {},
devMode: system.devMode
}; };
for(const [id, info] of system.instances.entries()) { for(const [id, info] of system.instances.entries()) {
obj.instances[id] = { obj.instances[id] = {

2
src/externals.d.ts vendored
View File

@ -17,6 +17,7 @@ declare module "@kernel:base" {
type Id = string; type Id = string;
type ParsedSystemState = { type ParsedSystemState = {
handoff: string, handoff: string,
devMode: boolean,
instances: { instances: {
[id: Id]: { [id: Id]: {
config: any, config: any,
@ -31,6 +32,7 @@ declare module "@kernel:base" {
aliases: Map<string, string>; aliases: Map<string, string>;
instances: Map<string, Instance>; instances: Map<string, Instance>;
handoff: string; handoff: string;
devMode: boolean;
} }
const system: System; const system: System;
} }

View File

@ -1,6 +1,6 @@
/// <reference path="./externals.d.ts" /> /// <reference path="./externals.d.ts" />
import { Instance, ParsedSystemState } from '@kernel:base'; import { Instance, ParsedSystemState, System } from '@kernel:base';
import '@kernel:log-hook'; import '@kernel:log-hook';
import createExecutor from '@commands:executor'; import createExecutor from '@commands:executor';
import create from '@commands:create'; import create from '@commands:create';
@ -17,12 +17,11 @@ import md5 from 'md5';
const args = process.argv.slice(2); const args = process.argv.slice(2);
const [ startupFile ] = args; const [ startupFile ] = args;
export type Id = string; export const system: System = {
export const system = {
instances: new Map<string, Instance>(), instances: new Map<string, Instance>(),
handoff: '', handoff: '',
aliases: new Map<string, string>() aliases: new Map<string, string>(),
devMode: false
} }
export function reverseAliasMap() { export function reverseAliasMap() {
@ -47,7 +46,22 @@ export function autoColorString(string: string) {
export const exec = async (s: string, echo = true) => { export const exec = async (s: string, echo = true) => {
if(echo) console.log(chalk.cyan('@ ') + chalk.ansi256(242)(s)); if(echo) console.log(chalk.cyan('@ ') + chalk.ansi256(242)(s));
await executor(...(s.split(' ')));
const args: (string | number | boolean)[] = [];
for(const arg of s.split(' ')) {
const asNum = parseFloat(arg);
const isTrue = arg.toLowerCase() === 'true';
const isBoolean = isTrue || arg.toLowerCase() === 'false';
if(isBoolean) {
args.push(isTrue);
} else if(!isNaN(asNum)) {
args.push(asNum)
} else {
args.push(arg);
}
}
await executor(...args);
}; };
export const kernel = { export const kernel = {
@ -87,8 +101,12 @@ export const kernel = {
await exec(line); await exec(line);
} }
}, },
set(variable: string, ...rest: string[]) { set(variable: string, ...rest: any) {
(system as any)[variable] = rest.join(' '); if(rest.length > 1) {
(system as any)[variable] = rest.join(' ');
} else {
(system as any)[variable] = rest[0];
}
}, },
help: help help: help
}; };

View File

@ -13,6 +13,7 @@ function randomNormal(width: number = 1, offset: number = 0) {
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1) while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
while(v === 0) v = Math.random(); while(v === 0) v = Math.random();
const base = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v ); const base = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
return offset + base * width;
} }
export function pull() { export function pull() {