Skip to content

Commit

Permalink
Merge pull request #13 from artpani4/artpani/ward
Browse files Browse the repository at this point in the history
Artpani/ward
  • Loading branch information
artpani4 authored Jul 28, 2024
2 parents 41f76b2 + d51a5a4 commit a812c89
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 106 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
},
"tasks": {
"start": "deno run --allow-all src/index.ts"
"start": "config=develop deno run --allow-all example/config/main.ts"
},
"lint": {
"files": {
Expand Down
63 changes: 62 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions example/config/a.tuner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ export default Tuner.tune({
// 'http://localhost:8000/example/config/b.tuner.ts',
// ),
env: {
someField: Tuner.Env.getString.orDefault("effe"),
someField: Tuner.Env.getString.orDefault('effe'),
},
child: Tuner.Load.remote.providers.notion(
Tuner.getEnv('NOTION_KEY'),
'https://www.notion.so/artpani/Tuner-15d96fa233e64e8da65c30bfa2ade5e2?pvs=4#8b52d24ee4e1494392ff3f1b58a73753',
),
// child: Tuner.Load.remote.providers.notion(
// Tuner.getEnv('NOTION_KEY'),
// 'https://www.notion.so/artpani/d1ecc246b8304e08a780b9a312548064?pvs=4#ef81f9e0a6b9482db00b2045bc1a76c4',
// ),
config: {
b: 200,
e: 201,
b: 209,
e: 20,
f: 780,
CONFIG_A: false,
},
watch: 5000,
});
2 changes: 1 addition & 1 deletion example/config/b.tuner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Tuner from '../../mod.ts';

export default Tuner.tune({
config: { a: 100, d: 101 },
config: { a: 100, d: 101, CONFIG_B: true },
});
2 changes: 1 addition & 1 deletion example/config/base.tuner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Tuner from '../../mod.ts';

export default Tuner.tune({
config: { a: 400, b: 401, c: 402 },
config: { a: 50, b: 40, c: 402, base: false },
});
22 changes: 9 additions & 13 deletions example/config/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ import { z } from 'https://deno.land/x/zod/mod.ts';
export const configSchema = z.object({
config: z.object({
a: z.number(),
d: z.number(),
CONFIG_B: z.boolean(),
test: z.number(),
develop: z.boolean(),
b: z.number(),
c: z.number(),
e: z.number(),
d: z.number(),
f: z.number(),
CONFIG_A: z.boolean(),
CONFIG_NOTION: z.boolean(),
}),
watch: z.number(),
env: z.object({
someField: z.number(),
someField: z.string(),
}),
});

export type Config = z.infer<typeof configSchema>;

//├─ config
//│ ├─ a
//│ ├─ b
//│ ├─ c
//│ ├─ e
//│ └─ d
//└─ env
// └─ someField
//
7 changes: 4 additions & 3 deletions example/config/develop.tuner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import Tuner from '../../mod.ts';
export default Tuner.tune({
child: Tuner.Load.local.cwd('example/config/a.tuner.ts'),
parent: Tuner.Load.local.configDir('base.tuner.ts'),
parent: Tuner.Load.local.cwd('example/config/b.tuner.ts'),
config: {
a: 300,
b: 301,
test: 1000,
develop: true,
},
watch: 2000,
});
24 changes: 20 additions & 4 deletions example/config/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import Tuner from '../../mod.ts';
import { Config } from './configSchema.ts';
const cfg = (await Tuner.use.loadConfig()) as Config;
// Tuner.use.generateSchema(
import { Ward } from '../../src/ward/ward.ts';

let cfg = await Tuner.use.loadConfig();
// await Tuner.use.generateSchema(
// cfg,
// 'config',
// 'example/config/configSchema.ts',
// );
console.log(cfg);
await Tuner.onChanged(async (_data) => {
// cfg = (await Tuner.use.loadConfig()) as Config;
cfg = await Tuner.use.loadConfig();
console.log(cfg);
});

setInterval(() => {
// console.log(Ward.wards.map((ward) => ward.period).join(' '));
console.log(Deno.memoryUsage().heapUsed);
// gc();
}, 600);

// const a = async (x: number) => x + 2;
// const b = async (x: number) => x + 2;

// console.log(a.toString() === b.toString());
18 changes: 5 additions & 13 deletions example/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
// import Tuner from '../mod.ts';
// import { Config } from './config/schema.ts';
// const config = (await Tuner.use.loadConfig()) as Config;
// console.log(config);

// config/develop.tuner.ts
import Tuner from '../mod.ts';
export default Tuner.tune({
child: Tuner.Load.local.configDir('a.tuner.ts'),
config: {
a: 300,
b: 301,
},
});
import { Config } from './config/configSchema.ts';

const config = (await Tuner.use.loadConfig()) as Config;

setInterval(() => console.log(Deno.memoryUsage()), 500);
4 changes: 3 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import tune from './src/tunerFun.ts';
import Env from './src/envFuns.ts';
import { getEnv } from './src/tuner.ts';
import { getEnv, onChangeTrigger } from './src/tuner.ts';
import Load from './src/loaders.ts';
import { loadConfig } from './src/tuner.ts';
import { generateSchema } from './src/scheme.ts';
import { IFilledTunerConfig } from './src/type.ts';

export default {
tune,
Expand All @@ -14,4 +15,5 @@ export default {
loadConfig,
generateSchema,
},
onChanged: onChangeTrigger<IFilledTunerConfig>,
};
2 changes: 0 additions & 2 deletions src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const myEventTarget = new MyEventTarget();

myEventTarget.addEventListener('myEvent', (event: Event) => {
const customEvent = event as CustomEvent;
console.log('Событие myEvent с данными:', customEvent.detail);
});

myEventTarget.triggerCustomEvent('myEvent', {
Expand All @@ -36,7 +35,6 @@ myEventTarget.triggerCustomEvent('myEvent', {

// myEventTarget.addEventListener('myEvent', (event: Event) => {
// const customEvent = event as CustomEvent;
// console.log('Событие myEvent с данными:', customEvent.detail);
// });

// myEventTarget.triggerCustomEvent('myEvent', {
Expand Down
Loading

0 comments on commit a812c89

Please sign in to comment.