@ooneex/seeds 0.10.0 → 0.12.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.js +121 -10
- package/dist/index.js.map +2 -2
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
2
|
+
// src/decorators.ts
|
|
3
|
+
import { container, EContainerScope } from "@ooneex/container";
|
|
4
|
+
|
|
5
|
+
// src/container.ts
|
|
6
|
+
var SEEDS_CONTAINER = [];
|
|
7
|
+
|
|
8
|
+
// src/decorators.ts
|
|
9
|
+
var decorator = {
|
|
10
|
+
seed: (scope = EContainerScope.Singleton) => {
|
|
11
|
+
return (target) => {
|
|
12
|
+
container.add(target, scope);
|
|
13
|
+
SEEDS_CONTAINER.push(target);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
// src/getSeeds.ts
|
|
18
|
+
import { container as container2 } from "@ooneex/container";
|
|
19
|
+
var getSeeds = () => {
|
|
20
|
+
const seedInstances = SEEDS_CONTAINER.map((SeedClass) => {
|
|
21
|
+
return container2.get(SeedClass);
|
|
22
|
+
});
|
|
23
|
+
return seedInstances.filter((seed) => seed.isActive());
|
|
24
|
+
};
|
|
25
|
+
// src/seedCreate.ts
|
|
26
|
+
import { join } from "path";
|
|
27
|
+
import { toPascalCase } from "@ooneex/utils";
|
|
28
|
+
var {Glob } = globalThis.Bun;
|
|
29
|
+
|
|
30
|
+
// src/seed.txt
|
|
31
|
+
var seed_default = `import { decorator, type ISeed, type SeedClassType } from "@ooneex/seeds";
|
|
3
32
|
|
|
4
33
|
@decorator.seed()
|
|
5
34
|
export class {{ name }} implements ISeed {
|
|
@@ -18,15 +47,97 @@ export class {{ name }} implements ISeed {
|
|
|
18
47
|
return [];
|
|
19
48
|
}
|
|
20
49
|
}
|
|
21
|
-
`;
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
// src/seedCreate.ts
|
|
53
|
+
var seedCreate = async (config) => {
|
|
54
|
+
const name = `${toPascalCase(config.name)}Seed`;
|
|
55
|
+
const seedsDir = config.dir || "seeds";
|
|
56
|
+
await Bun.write(join(process.cwd(), seedsDir, `${name}.ts`), seed_default.replaceAll("{{ name }}", name));
|
|
57
|
+
const imports = [];
|
|
58
|
+
const glob = new Glob("**/*Seed.ts");
|
|
59
|
+
for await (const file of glob.scan(seedsDir)) {
|
|
60
|
+
const name2 = file.replace(/\.ts$/, "");
|
|
61
|
+
imports.push(`export { ${name2} } from './${name2}';`);
|
|
62
|
+
}
|
|
63
|
+
await Bun.write(join(process.cwd(), seedsDir, "seeds.ts"), `${imports.sort().join(`
|
|
22
64
|
`)}
|
|
23
|
-
`)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
65
|
+
`);
|
|
66
|
+
return join(seedsDir, `${name}.ts`);
|
|
67
|
+
};
|
|
68
|
+
// src/seedRun.ts
|
|
69
|
+
import { container as container3 } from "@ooneex/container";
|
|
70
|
+
import { TerminalLogger } from "@ooneex/logger";
|
|
71
|
+
var run = async (seed) => {
|
|
72
|
+
const data = [];
|
|
73
|
+
const dependencies = await seed.getDependencies();
|
|
74
|
+
for (const dependency of dependencies) {
|
|
75
|
+
const dep = container3.get(dependency);
|
|
76
|
+
data.push(await run(dep));
|
|
77
|
+
}
|
|
78
|
+
await seed.run(data);
|
|
79
|
+
};
|
|
80
|
+
var seedRun = async () => {
|
|
81
|
+
const seeds = getSeeds();
|
|
82
|
+
const logger = new TerminalLogger;
|
|
83
|
+
if (seeds.length === 0) {
|
|
84
|
+
logger.info(`No seeds found
|
|
85
|
+
`, undefined, {
|
|
86
|
+
showTimestamp: false,
|
|
87
|
+
showArrow: false,
|
|
88
|
+
useSymbol: true
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
logger.info(`Running ${seeds.length} seed(s)...
|
|
93
|
+
`, undefined, {
|
|
94
|
+
showTimestamp: false,
|
|
95
|
+
showArrow: false,
|
|
96
|
+
useSymbol: true
|
|
97
|
+
});
|
|
98
|
+
for (const seed of seeds) {
|
|
99
|
+
const seedName = seed.constructor.name;
|
|
100
|
+
if (!seed.isActive()) {
|
|
101
|
+
logger.warn(`Seed ${seedName} is inactive
|
|
102
|
+
`, undefined, {
|
|
103
|
+
showTimestamp: false,
|
|
104
|
+
showArrow: false,
|
|
105
|
+
useSymbol: true
|
|
106
|
+
});
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
await run(seed);
|
|
111
|
+
logger.success(`Seed ${seedName} completed
|
|
112
|
+
`, undefined, {
|
|
113
|
+
showTimestamp: false,
|
|
114
|
+
showArrow: false,
|
|
115
|
+
useSymbol: true
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
logger.error(`Seed ${seedName} failed
|
|
119
|
+
`, undefined, {
|
|
120
|
+
showTimestamp: false,
|
|
121
|
+
showArrow: false,
|
|
122
|
+
useSymbol: true
|
|
123
|
+
});
|
|
124
|
+
logger.error(error);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
logger.success(`
|
|
29
129
|
All seeds completed successfully
|
|
30
|
-
`,
|
|
130
|
+
`, undefined, {
|
|
131
|
+
showTimestamp: false,
|
|
132
|
+
showArrow: false,
|
|
133
|
+
useSymbol: true
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
export {
|
|
137
|
+
seedRun,
|
|
138
|
+
seedCreate,
|
|
139
|
+
getSeeds,
|
|
140
|
+
decorator
|
|
141
|
+
};
|
|
31
142
|
|
|
32
|
-
//# debugId=
|
|
143
|
+
//# debugId=EA5EA9D6BDBCF90664756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"import { join } from \"node:path\";\nimport { toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport content from \"./seed.txt\";\n\nexport const seedCreate = async (config: { name: string; dir?: string }): Promise<string> => {\n const name = `${toPascalCase(config.name)}Seed`;\n const seedsDir = config.dir || \"seeds\";\n\n await Bun.write(join(process.cwd(), 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(process.cwd(), seedsDir, \"seeds.ts\"), `${imports.sort().join(\"\\n\")}\\n`);\n\n return join(seedsDir, `${name}.ts`);\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": "
|
|
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,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;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,aAAa,OAAO,WAA4D;AAAA,EAC3F,MAAM,OAAO,GAAG,aAAa,OAAO,IAAI;AAAA,EACxC,MAAM,WAAW,OAAO,OAAO;AAAA,EAE/B,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,GAAG,UAAU,GAAG,SAAS,GAAG,aAAQ,WAAW,cAAc,IAAI,CAAC;AAAA,EAEnG,MAAM,UAAoB,CAAC;AAAA,EAC3B,MAAM,OAAO,IAAI,KAAK,aAAa;AAAA,EACnC,iBAAiB,QAAQ,KAAK,KAAK,QAAQ,GAAG;AAAA,IAC5C,MAAM,QAAO,KAAK,QAAQ,SAAS,EAAE;AAAA,IACrC,QAAQ,KAAK,YAAY,mBAAkB,SAAQ;AAAA,EACrD;AAAA,EAEA,MAAM,IAAI,MAAM,KAAK,QAAQ,IAA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;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": "EA5EA9D6BDBCF90664756E2164756E21",
|
|
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 utilities for populating initial and test data with logging support",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"npm:publish": "bun publish --tolerate-republish --access public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ooneex/container": "0.0.
|
|
32
|
-
"@ooneex/logger": "0.
|
|
31
|
+
"@ooneex/container": "0.0.12",
|
|
32
|
+
"@ooneex/logger": "0.10.0",
|
|
33
33
|
"@ooneex/utils": "0.1.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@ooneex/exception": "0.0.
|
|
36
|
+
"@ooneex/exception": "0.0.11"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"bun",
|