@ooneex/seeds 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ooneex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @ooneex/seeds
@@ -0,0 +1,14 @@
1
+ import { EContainerScope } from "@ooneex/container";
2
+ type SeedClassType = new (...args: any[]) => ISeed;
3
+ interface ISeed {
4
+ run: <T = unknown>(data?: unknown[]) => Promise<T> | T;
5
+ isActive: () => Promise<boolean> | boolean;
6
+ getDependencies: () => Promise<SeedClassType[]> | SeedClassType[];
7
+ }
8
+ declare const seed: (scope?: EContainerScope) => (target: SeedClassType) => void;
9
+ declare const getSeeds: () => ISeed[];
10
+ declare const seedCreate: (config: {
11
+ dir?: string;
12
+ }) => Promise<void>;
13
+ declare const seedRun: () => Promise<void>;
14
+ export { seedRun, seedCreate, seed, getSeeds, SeedClassType, ISeed };
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ // @bun
2
+ import{ContainerException as f,container as S,EContainerScope as y}from"@ooneex/container";var r=[];var g=(o=y.Singleton)=>{return(e)=>{if(!e.name.endsWith("Seed"))throw new f(`Class name "${e.name}" must end with "Seed"`);S.add(e,o),r.push(e)}};import{container as x}from"@ooneex/container";var i=()=>{return r.map((e)=>{return x.get(e)}).filter((e)=>e.isActive())};import{join as m}from"path";import{parseArgs as T}from"util";import{TerminalLogger as C}from"@ooneex/logger";import{toPascalCase as E}from"@ooneex/utils";var{Glob:I}=globalThis.Bun;var c=`import { type SeedClassType, seed } from '@ooneex/seeds';
3
+
4
+ @seed()
5
+ export class {{ name }} implements ISeed {
6
+ public async run<T>(data?: any[]): Promise<T> {
7
+ // Your seed logic here
8
+ // console.log('{{ name }}!');
9
+
10
+ return data as T;
11
+ }
12
+
13
+ public isActive(): boolean {
14
+ return true;
15
+ }
16
+
17
+ public async getDependencies(): Promise<SeedClassType[]> {
18
+ return [];
19
+ }
20
+ }
21
+ `;var $=async(o)=>{let{values:e}=T({args:Bun.argv,options:{name:{type:"string"}},strict:!0,allowPositionals:!0}),n=new C;if(!e.name)n.error(`Name is required
22
+ `),process.exit(1);let s=`${E(e.name)}Seed`,t=o?.dir||"seeds";await Bun.write(m(t,`${s}.ts`),c.replaceAll("{{ name }}",s));let a=[],l=new I("**/*Seed.ts");for await(let u of l.scan(t)){let p=u.replace(/\.ts$/,"");a.push(`export { ${p} } from './${p}';`)}await Bun.write(m(t,"index.ts"),`${a.sort().join(`
23
+ `)}
24
+ `),n.success(`Seed ${s} created successfully
25
+ `)};import{container as v}from"@ooneex/container";import{TerminalLogger as A}from"@ooneex/logger";var d=async(o)=>{let e=[],n=await o.getDependencies();for(let s of n){let t=v.get(s);e.push(await d(t))}await o.run(e)},h=async()=>{let o=i(),e=new A;if(o.length===0){e.info(`No seeds found
26
+ `);return}e.info(`Running ${o.length} seed(s)...
27
+ `);for(let n of o){let s=n.constructor.name;if(!n.isActive()){e.warn(`Seed ${s} is inactive
28
+ `);continue}try{await d(n),e.success(`Seed ${s} completed
29
+ `)}catch(t){e.error(`Seed ${s} failed
30
+ `),e.error(t),process.exit(1)}}e.success(`
31
+ All seeds completed successfully
32
+ `)};export{h as seedRun,$ as seedCreate,g as seed,i as getSeeds};
33
+
34
+ //# debugId=5E85C214EE269B6D64756E2164756E21
@@ -0,0 +1,14 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/decorators.ts", "src/container.ts", "src/getSeeds.ts", "src/seedCreate.ts", "src/seedRun.ts"],
4
+ "sourcesContent": [
5
+ "import { ContainerException, container, EContainerScope } from \"@ooneex/container\";\nimport { SEEDS_CONTAINER } from \"./container\";\nimport type { SeedClassType } from \"./types\";\n\nexport const seed = (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: SeedClassType): void => {\n if (!target.name.endsWith(\"Seed\")) {\n throw new ContainerException(`Class name \"${target.name}\" must end with \"Seed\"`);\n }\n container.add(target, scope);\n SEEDS_CONTAINER.push(target);\n };\n};\n",
6
+ "import type { SeedClassType } from \"./types\";\n\nexport const SEEDS_CONTAINER: SeedClassType[] = [];\n",
7
+ "import { container } from \"@ooneex/container\";\nimport { SEEDS_CONTAINER } from \"./container\";\nimport type { ISeed } from \"./types\";\n\nexport const getSeeds = (): ISeed[] => {\n const seedInstances = SEEDS_CONTAINER.map((SeedClass) => {\n return container.get(SeedClass);\n });\n\n return seedInstances.filter((seed) => seed.isActive());\n};\n",
8
+ "import { join } from \"node:path\";\nimport { parseArgs } from \"node:util\";\nimport { TerminalLogger } from \"@ooneex/logger\";\nimport { toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport content from \"./seed.txt\";\n\nexport const seedCreate = async (config: { dir?: string }): Promise<void> => {\n const { values } = parseArgs({\n args: Bun.argv,\n options: { name: { type: \"string\" } },\n strict: true,\n allowPositionals: true,\n });\n\n const logger = new TerminalLogger();\n\n if (!values.name) {\n logger.error(\"Name is required\\n\");\n process.exit(1);\n }\n\n const name = `${toPascalCase(values.name)}Seed`;\n const seedsDir = config?.dir || \"seeds\";\n\n await Bun.write(join(seedsDir, `${name}.ts`), content.replaceAll(\"{{ name }}\", name));\n\n const imports: string[] = [];\n const glob = new Glob(\"**/*Seed.ts\");\n for await (const file of glob.scan(seedsDir)) {\n const name = file.replace(/\\.ts$/, \"\");\n imports.push(`export { ${name} } from './${name}';`);\n }\n\n await Bun.write(join(seedsDir, \"index.ts\"), `${imports.sort().join(\"\\n\")}\\n`);\n\n logger.success(`Seed ${name} created successfully\\n`);\n};\n",
9
+ "import { container } from \"@ooneex/container\";\nimport type { IException } from \"@ooneex/exception\";\nimport { TerminalLogger } from \"@ooneex/logger\";\nimport { getSeeds } from \"./getSeeds\";\nimport type { ISeed } from \"./types\";\n\nconst run = async (seed: ISeed): Promise<void> => {\n const data = [];\n\n const dependencies = await seed.getDependencies();\n\n for (const dependency of dependencies) {\n const dep = container.get(dependency);\n data.push(await run(dep));\n }\n\n await seed.run(data);\n};\n\nexport const seedRun = async (): Promise<void> => {\n const seeds = getSeeds();\n const logger = new TerminalLogger();\n\n if (seeds.length === 0) {\n logger.info(\"No seeds found\\n\");\n return;\n }\n\n logger.info(`Running ${seeds.length} seed(s)...\\n`);\n\n for (const seed of seeds) {\n const seedName = seed.constructor.name;\n\n if (!seed.isActive()) {\n logger.warn(`Seed ${seedName} is inactive\\n`);\n continue;\n }\n\n try {\n await run(seed);\n logger.success(`Seed ${seedName} completed\\n`);\n } catch (error) {\n logger.error(`Seed ${seedName} failed\\n`);\n logger.error(error as IException);\n process.exit(1);\n }\n }\n\n logger.success(\"\\nAll seeds completed successfully\\n\");\n};\n"
10
+ ],
11
+ "mappings": ";AAAA,6BAAS,eAAoB,qBAAW,0BCEjC,IAAM,EAAmC,CAAC,EDE1C,IAAM,EAAO,CAAC,EAAyB,EAAg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AChD,IAAM,EAAO,CAAC,EAER,EAAe,MAAM,EAAK,gBAAgB,EAEhD,QAAW,KAAc,EAAc,CACrC,IAAM,EAAM,EAAU,IAAI,CAAU,EACpC,EAAK,KAAK,MAAM,EAAI,CAAG,CAAC,EAG1B,MAAM,EAAK,IAAI,CAAI,GAGR,EAAU,SAA2B,CAChD,IAAM,EAAQ,EAAS,EACjB,EAAS,IAAI,EAEnB,GAAI,EAAM,SAAW,EAAG,CACtB,EAAO,KAAK;AAAA,CAAkB,EAC9B,OAGF,EAAO,KAAK,WAAW,EAAM;AAAA,CAAqB,EAElD,QAAW,KAAQ,EAAO,CACxB,IAAM,EAAW,EAAK,YAAY,KAElC,GAAI,CAAC,EAAK,SAAS,EAAG,CACpB,EAAO,KAAK,QAAQ;AAAA,CAAwB,EAC5C,SAGF,GAAI,CACF,MAAM,EAAI,CAAI,EACd,EAAO,QAAQ,QAAQ;AAAA,CAAsB,EAC7C,MAAO,EAAO,CACd,EAAO,MAAM,QAAQ;AAAA,CAAmB,EACxC,EAAO,MAAM,CAAmB,EAChC,QAAQ,KAAK,CAAC,GAIlB,EAAO,QAAQ;AAAA;AAAA,CAAsC",
12
+ "debugId": "5E85C214EE269B6D64756E2164756E21",
13
+ "names": []
14
+ }
Binary file
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@ooneex/seeds",
3
+ "description": "",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "LICENSE",
9
+ "README.md",
10
+ "package.json"
11
+ ],
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "license": "MIT",
24
+ "scripts": {
25
+ "test": "bun test tests",
26
+ "build": "bunup",
27
+ "lint": "tsgo --noEmit && bunx biome lint",
28
+ "publish:prod": "bun publish --tolerate-republish --access public",
29
+ "publish:pack": "bun pm pack --destination ./dist",
30
+ "publish:dry": "bun publish --dry-run"
31
+ },
32
+ "dependencies": {
33
+ "@ooneex/container": "0.0.1",
34
+ "@ooneex/logger": "0.0.1",
35
+ "@ooneex/utils": "0.0.8"
36
+ },
37
+ "devDependencies": {
38
+ "@ooneex/exception": "0.0.1"
39
+ },
40
+ "peerDependencies": {}
41
+ }