Skip to content

Commit 3a5bec5

Browse files
committed
Fix Schema Generator Issue as npm package
1 parent cfbe3fa commit 3a5bec5

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb-schema-cli",
3-
"version": "1.0",
3+
"version": "1.0.0",
44
"description": "A MongoDB Schema Generator CLI",
55
"main": "index.js",
66
"bin": {

src/main.js

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const fs = require("fs");
33
const { promisify } = require("util");
44
const Listr = require("listr");
55
const schema = require("../template");
6+
const chalk = require("chalk");
67

78
const writeFile = promisify(fs.writeFile);
89
const appendFile = promisify(fs.appendFile);
@@ -11,50 +12,27 @@ export async function createSchema(options, schemaKeyValues) {
1112
const schemaOptions = {
1213
...options,
1314
dirPath: path.resolve(__dirname, "../template"),
14-
outPath: path.resolve(__dirname, "../out", `./${options.schema}.js`),
15+
outPath: path.resolve(process.cwd(), `./${options.schema}.js`),
1516
};
1617

1718
console.log();
1819

19-
// initializeSchema(schemaOptions.outPath);
20-
// await createObjects(schemaOptions.outPath, schemaKeyValues);
21-
// exportSchema(schemaOptions.outPath, schema.schemaBottom());
22-
2320
const tasks = new Listr([
2421
{
25-
title: "Creating File and Adding Imports",
26-
task: () => initializeSchema(schemaOptions.outPath),
27-
},
28-
{
29-
title: "Adding Schema Keys",
22+
title: "Creating Schema",
3023
task: async () =>
3124
await createObjects(schemaOptions.outPath, schemaKeyValues),
3225
},
33-
{
34-
title: "Making Schema Exportable",
35-
task: () => exportSchema(schemaOptions.outPath, schema.schemaBottom()),
36-
},
3726
]);
3827

3928
await tasks.run();
40-
41-
// Append Objects to the Schema
42-
43-
// Close the Schema and Add Export
44-
45-
// await appendFile(schemaOptions.out, schema.schemaBottom(true));
46-
}
47-
48-
async function initializeSchema(outPath) {
49-
await writeFile(outPath, schema.schemaTop());
29+
console.log(chalk.green("DONE!"), "Schema Generated");
5030
}
5131

5232
async function createObjects(outPath, schemaKeyValues) {
33+
await writeFile(outPath, schema.schemaTop());
5334
for (let i = 0; i < schemaKeyValues.length; i++) {
5435
await appendFile(outPath, schema.createSchemaObject(schemaKeyValues[i]));
5536
}
56-
}
57-
58-
async function exportSchema(outPath) {
5937
await appendFile(outPath, schema.schemaBottom());
6038
}

0 commit comments

Comments
 (0)