@ooneex/seeds 1.3.0 → 1.4.0
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/dist/index.d.ts +1 -0
- package/dist/index.js +21 -8
- package/dist/index.js.map +3 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,11 +24,13 @@ var getSeeds = () => {
|
|
|
24
24
|
};
|
|
25
25
|
// src/seedCreate.ts
|
|
26
26
|
import { join } from "path";
|
|
27
|
-
import { toPascalCase } from "@ooneex/utils";
|
|
27
|
+
import { toKebabCase, toPascalCase } from "@ooneex/utils";
|
|
28
28
|
var {Glob } = globalThis.Bun;
|
|
29
29
|
|
|
30
30
|
// src/seed.test.txt
|
|
31
|
-
var seed_test_default = `import {
|
|
31
|
+
var seed_test_default = `import { existsSync } from "node:fs";
|
|
32
|
+
import { join } from "node:path";
|
|
33
|
+
import { describe, expect, test } from "bun:test";
|
|
32
34
|
import { {{NAME}}Seed } from "@/seeds/{{NAME}}Seed";
|
|
33
35
|
|
|
34
36
|
describe("{{NAME}}Seed", () => {
|
|
@@ -50,17 +52,23 @@ describe("{{NAME}}Seed", () => {
|
|
|
50
52
|
expect({{NAME}}Seed.prototype.getDependencies).toBeDefined();
|
|
51
53
|
expect(typeof {{NAME}}Seed.prototype.getDependencies).toBe("function");
|
|
52
54
|
});
|
|
55
|
+
|
|
56
|
+
test("should have a data yml file", () => {
|
|
57
|
+
const dataFile = join(__dirname, "..", "src", "seeds", "{{DATA_FILE}}.yml");
|
|
58
|
+
expect(existsSync(dataFile)).toBe(true);
|
|
59
|
+
});
|
|
53
60
|
});
|
|
54
61
|
`;
|
|
55
62
|
|
|
56
63
|
// src/seed.txt
|
|
57
64
|
var seed_default = `import { decorator, type ISeed, type SeedClassType } from "@ooneex/seeds";
|
|
65
|
+
import data from "./{{ dataFile }}.yml";
|
|
58
66
|
|
|
59
67
|
@decorator.seed()
|
|
60
68
|
export class {{ name }} implements ISeed {
|
|
61
|
-
public async run<T>(
|
|
69
|
+
public async run<T>(): Promise<T> {
|
|
62
70
|
// Your seed logic here
|
|
63
|
-
|
|
71
|
+
console.log(data);
|
|
64
72
|
|
|
65
73
|
return data as T;
|
|
66
74
|
}
|
|
@@ -79,10 +87,14 @@ export class {{ name }} implements ISeed {
|
|
|
79
87
|
var seedCreate = async (config) => {
|
|
80
88
|
const name = toPascalCase(config.name).replace(/Seed$/, "");
|
|
81
89
|
const seedName = `${name}Seed`;
|
|
90
|
+
const dataFile = toKebabCase(seedName);
|
|
82
91
|
const seedsDir = config.seedsDir || "seeds";
|
|
83
92
|
const testsDir = config.testsDir || join("tests", "seeds");
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
const seedContent = seed_default.replaceAll("{{ name }}", seedName).replaceAll("{{ dataFile }}", dataFile);
|
|
94
|
+
await Bun.write(join(process.cwd(), seedsDir, `${seedName}.ts`), seedContent);
|
|
95
|
+
await Bun.write(join(process.cwd(), seedsDir, `${dataFile}.yml`), `# Seed data
|
|
96
|
+
`);
|
|
97
|
+
const testContent = seed_test_default.replace(/\{\{NAME\}\}/g, name).replace(/\{\{DATA_FILE\}\}/g, dataFile);
|
|
86
98
|
await Bun.write(join(process.cwd(), testsDir, `${seedName}.spec.ts`), testContent);
|
|
87
99
|
const imports = [];
|
|
88
100
|
const glob = new Glob("**/*Seed.ts");
|
|
@@ -95,7 +107,8 @@ var seedCreate = async (config) => {
|
|
|
95
107
|
`);
|
|
96
108
|
return {
|
|
97
109
|
seedPath: join(seedsDir, `${seedName}.ts`),
|
|
98
|
-
testPath: join(testsDir, `${seedName}.spec.ts`)
|
|
110
|
+
testPath: join(testsDir, `${seedName}.spec.ts`),
|
|
111
|
+
dataPath: join(seedsDir, `${dataFile}.yml`)
|
|
99
112
|
};
|
|
100
113
|
};
|
|
101
114
|
// src/seedRun.ts
|
|
@@ -173,4 +186,4 @@ export {
|
|
|
173
186
|
decorator
|
|
174
187
|
};
|
|
175
188
|
|
|
176
|
-
//# debugId=
|
|
189
|
+
//# debugId=B5DCEF6606F01A8664756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"import { container, EContainerScope } from \"@ooneex/container\";\nimport { SEEDS_CONTAINER } from \"./container\";\nimport type { SeedClassType } from \"./types\";\n\nexport const decorator = {\n seed: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: SeedClassType): void => {\n container.add(target, scope);\n SEEDS_CONTAINER.push(target);\n };\n },\n};\n",
|
|
6
6
|
"import type { SeedClassType } from \"./types\";\n\nexport const SEEDS_CONTAINER: SeedClassType[] = [];\n",
|
|
7
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 { toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport testTemplate from \"./seed.test.txt\";\nimport template from \"./seed.txt\";\n\nexport const seedCreate = async (config: {\n name: string;\n seedsDir?: string;\n testsDir?: string;\n}): Promise<{ seedPath: string; testPath: string }> => {\n const name = toPascalCase(config.name).replace(/Seed$/, \"\");\n const seedName = `${name}Seed`;\n const seedsDir = config.seedsDir || \"seeds\";\n const testsDir = config.testsDir || join(\"tests\", \"seeds\");\n\n await Bun.write(join(process.cwd(), seedsDir, `${seedName}.ts`),
|
|
8
|
+
"import { join } from \"node:path\";\nimport { toKebabCase, toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport testTemplate from \"./seed.test.txt\";\nimport template from \"./seed.txt\";\n\nexport const seedCreate = async (config: {\n name: string;\n seedsDir?: string;\n testsDir?: string;\n}): Promise<{ seedPath: string; testPath: string; dataPath: string }> => {\n const name = toPascalCase(config.name).replace(/Seed$/, \"\");\n const seedName = `${name}Seed`;\n const dataFile = toKebabCase(seedName);\n const seedsDir = config.seedsDir || \"seeds\";\n const testsDir = config.testsDir || join(\"tests\", \"seeds\");\n\n const seedContent = template.replaceAll(\"{{ name }}\", seedName).replaceAll(\"{{ dataFile }}\", dataFile);\n await Bun.write(join(process.cwd(), seedsDir, `${seedName}.ts`), seedContent);\n\n await Bun.write(join(process.cwd(), seedsDir, `${dataFile}.yml`), \"# Seed data\\n\");\n\n const testContent = testTemplate.replace(/\\{\\{NAME\\}\\}/g, name).replace(/\\{\\{DATA_FILE\\}\\}/g, dataFile);\n await Bun.write(join(process.cwd(), testsDir, `${seedName}.spec.ts`), testContent);\n\n const imports: string[] = [];\n const glob = new Glob(\"**/*Seed.ts\");\n for await (const file of glob.scan(join(process.cwd(), seedsDir))) {\n const seedClassName = file.replace(/\\.ts$/, \"\");\n imports.push(`export { ${seedClassName} } from './${seedClassName}';`);\n }\n\n await Bun.write(join(process.cwd(), seedsDir, \"seeds.ts\"), `${imports.sort().join(\"\\n\")}\\n`);\n\n return {\n seedPath: join(seedsDir, `${seedName}.ts`),\n testPath: join(testsDir, `${seedName}.spec.ts`),\n dataPath: join(seedsDir, `${dataFile}.yml`),\n };\n};\n",
|
|
9
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\", undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n return;\n }\n\n logger.info(`Running ${seeds.length} seed(s)...\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\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`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n continue;\n }\n\n try {\n await run(seed);\n logger.success(`Seed ${seedName} completed\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n } catch (error) {\n logger.error(`Seed ${seedName} failed\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n logger.error(error as IException);\n process.exit(1);\n }\n }\n\n logger.success(\"\\nAll seeds completed successfully\\n\", undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n};\n"
|
|
10
10
|
],
|
|
11
|
-
"mappings": ";;AAAA;;;ACEO,IAAM,kBAAmC,CAAC;;;ADE1C,IAAM,YAAY;AAAA,EACvB,MAAM,CAAC,QAAyB,gBAAgB,cAAc;AAAA,IAC5D,OAAO,CAAC,WAAgC;AAAA,MACtC,UAAU,IAAI,QAAQ,KAAK;AAAA,MAC3B,gBAAgB,KAAK,MAAM;AAAA;AAAA;AAGjC;;AEXA,sBAAS;AAIF,IAAM,WAAW,MAAe;AAAA,EACrC,MAAM,gBAAgB,gBAAgB,IAAI,CAAC,cAAc;AAAA,IACvD,OAAO,WAAU,IAAI,SAAS;AAAA,GAC/B;AAAA,EAED,OAAO,cAAc,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC;AAAA;;ACTvD;AACA;AACA
|
|
12
|
-
"debugId": "
|
|
11
|
+
"mappings": ";;AAAA;;;ACEO,IAAM,kBAAmC,CAAC;;;ADE1C,IAAM,YAAY;AAAA,EACvB,MAAM,CAAC,QAAyB,gBAAgB,cAAc;AAAA,IAC5D,OAAO,CAAC,WAAgC;AAAA,MACtC,UAAU,IAAI,QAAQ,KAAK;AAAA,MAC3B,gBAAgB,K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ACX,WAAW;AAAA,MACb,CAAC;AAAA,MACD;AAAA,IACF;AAAA,IAEA,IAAI;AAAA,MACF,MAAM,IAAI,IAAI;AAAA,MACd,OAAO,QAAQ,QAAQ;AAAA,GAAwB,WAAW;AAAA,QACxD,eAAe;AAAA,QACf,WAAW;AAAA,QACX,WAAW;AAAA,MACb,CAAC;AAAA,MACD,OAAO,OAAO;AAAA,MACd,OAAO,MAAM,QAAQ;AAAA,GAAqB,WAAW;AAAA,QACnD,eAAe;AAAA,QACf,WAAW;AAAA,QACX,WAAW;AAAA,MACb,CAAC;AAAA,MACD,OAAO,MAAM,KAAmB;AAAA,MAChC,QAAQ,KAAK,CAAC;AAAA;AAAA,EAElB;AAAA,EAEA,OAAO,QAAQ;AAAA;AAAA,GAAwC,WAAW;AAAA,IAChE,eAAe;AAAA,IACf,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AAAA;",
|
|
12
|
+
"debugId": "B5DCEF6606F01A8664756E2164756E21",
|
|
13
13
|
"names": []
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/seeds",
|
|
3
3
|
"description": "Database seeding framework for populating initial data, fixtures, and test datasets with execution logging and idempotent operations",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"npm:publish": "bun publish --tolerate-republish --force --production --access public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ooneex/container": "1.
|
|
32
|
-
"@ooneex/logger": "1.2.
|
|
33
|
-
"@ooneex/utils": "0.4.
|
|
31
|
+
"@ooneex/container": "1.3.0",
|
|
32
|
+
"@ooneex/logger": "1.2.9",
|
|
33
|
+
"@ooneex/utils": "0.4.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@ooneex/exception": "1.2.
|
|
36
|
+
"@ooneex/exception": "1.2.2"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"bun",
|