Skip to content

Commit be1d89e

Browse files
committed
Remove from .gitignore
1 parent 628a3e8 commit be1d89e

File tree

5 files changed

+216
-1
lines changed

5 files changed

+216
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
See http://help.github.com/ignore-files/ for more about ignoring files.
22

33
# compiled output
4-
/dist
54
/tmp
65
/out-tsc
76
out/*

dist/bin/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
var __importDefault = (this && this.__importDefault) || function (mod) {
4+
return (mod && mod.__esModule) ? mod : { "default": mod };
5+
};
6+
Object.defineProperty(exports, "__esModule", { value: true });
7+
const cli_1 = __importDefault(require("../src/cli"));
8+
cli_1.default(process.argv);

dist/src/cli.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
const arg_1 = __importDefault(require("arg"));
16+
const inquirer_1 = __importDefault(require("inquirer"));
17+
const main_1 = __importDefault(require("./main"));
18+
function parseArgumentsIntoOptions(rawArgs) {
19+
const args = arg_1.default({
20+
"--typescript": Boolean,
21+
"--filepath": String,
22+
// Aliases
23+
"-t": "--typescript",
24+
"-m": "--mongoose",
25+
}, {
26+
argv: rawArgs.slice(2),
27+
});
28+
return {
29+
language: args["--typescript"] || false,
30+
filePath: args["--filepath"] || "/",
31+
};
32+
}
33+
function promptForMissingOptions(options) {
34+
return __awaiter(this, void 0, void 0, function* () {
35+
const defaultOptions = {
36+
language: "Javascript",
37+
schema: "default",
38+
};
39+
const questions = [];
40+
//@TODO: Temporary Disabled, Uncomment after adding Typescript Schema
41+
// if (!options.language) {
42+
// questions.push({
43+
// type: "list",
44+
// name: "language",
45+
// message: "Please choose which language Schema to use",
46+
// choices: ["JavaScript", "TypeScript"],
47+
// default: defaultOptions.language,
48+
// });
49+
// }
50+
questions.push({
51+
type: "input",
52+
name: "schema",
53+
message: "Please input Schema name",
54+
default: defaultOptions.schema,
55+
});
56+
const answers = yield inquirer_1.default.prompt(questions);
57+
return Object.assign(Object.assign({}, options), { language: options.language || answers.language, schema: answers.schema });
58+
});
59+
}
60+
function promptForSchemaObject() {
61+
return __awaiter(this, void 0, void 0, function* () {
62+
const defaultOptions = {
63+
name: "default",
64+
type: "String",
65+
required: true,
66+
default: "",
67+
};
68+
const questions = [];
69+
questions.push({
70+
type: "input",
71+
name: "name",
72+
message: "Please input Schema Key name",
73+
default: defaultOptions.name,
74+
});
75+
questions.push({
76+
type: "list",
77+
name: "type",
78+
message: "Please input Schema Key type",
79+
choices: ["String", "Number", "Boolean"],
80+
default: defaultOptions.name,
81+
});
82+
questions.push({
83+
type: "confirm",
84+
name: "required",
85+
message: "Is this Schema Key Required",
86+
default: defaultOptions.required,
87+
});
88+
questions.push({
89+
type: "input",
90+
name: "default",
91+
message: "What is the default value?",
92+
default: defaultOptions.default,
93+
});
94+
const answers = yield inquirer_1.default.prompt(questions);
95+
return {
96+
name: answers.name,
97+
type: answers.type,
98+
isRequired: answers.required,
99+
defaultValue: answers.default,
100+
};
101+
});
102+
}
103+
function cli(args) {
104+
return __awaiter(this, void 0, void 0, function* () {
105+
var options = parseArgumentsIntoOptions(args);
106+
var missingOptions = yield promptForMissingOptions(options);
107+
const { schemaKeys } = yield inquirer_1.default.prompt({
108+
type: "input",
109+
name: "schemaKeys",
110+
message: "How many key this Schema has?",
111+
default: 0,
112+
});
113+
const schemaKeyValues = [];
114+
for (let i = 0; i < schemaKeys; i++) {
115+
const objectValues = yield promptForSchemaObject();
116+
schemaKeyValues.push(objectValues);
117+
}
118+
var schema = missingOptions.schema;
119+
yield main_1.default(schema, schemaKeyValues);
120+
});
121+
}
122+
exports.default = cli;

dist/src/main.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
const path_1 = __importDefault(require("path"));
16+
const fs_1 = __importDefault(require("fs"));
17+
const util_1 = require("util");
18+
const listr_1 = __importDefault(require("listr"));
19+
const template_1 = require("../template");
20+
const writeFile = util_1.promisify(fs_1.default.writeFile);
21+
const appendFile = util_1.promisify(fs_1.default.appendFile);
22+
function createSchema(schema, schemaKeyValues) {
23+
return __awaiter(this, void 0, void 0, function* () {
24+
const schemaOptions = {
25+
// ...options,
26+
dirPath: path_1.default.resolve(__dirname, "../template"),
27+
outPath: path_1.default.resolve(process.cwd(), `./${schema}.js`),
28+
};
29+
console.log();
30+
const tasks = new listr_1.default([
31+
{
32+
title: "Creating Schema",
33+
task: () => __awaiter(this, void 0, void 0, function* () { return yield createObjects(schemaOptions.outPath, schemaKeyValues); }),
34+
},
35+
]);
36+
yield tasks.run();
37+
console.log("DONE! Schema Generated");
38+
});
39+
}
40+
function createObjects(outPath, schemaKeyValues) {
41+
return __awaiter(this, void 0, void 0, function* () {
42+
console.log(outPath);
43+
yield writeFile(outPath, template_1.schemaTop());
44+
for (let i = 0; i < schemaKeyValues.length; i++) {
45+
yield appendFile(outPath, template_1.createSchemaObject(schemaKeyValues[i]));
46+
}
47+
yield appendFile(outPath, template_1.schemaBottom());
48+
});
49+
}
50+
exports.default = createSchema;

dist/template/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.schemaBottom = exports.schemaTop = exports.createSchemaObject = void 0;
4+
function createSchemaObject(options) {
5+
const { name, type, isRequired, defaultValue } = options;
6+
return `
7+
${name}: {
8+
type: ${type},
9+
required: ${isRequired},
10+
default: "${defaultValue}"
11+
},
12+
`;
13+
}
14+
exports.createSchemaObject = createSchemaObject;
15+
function schemaTop() {
16+
return `
17+
const mongoose = require("mongoose");
18+
const Schema = mongoose.Schema;
19+
20+
const userSchema = new Schema({
21+
`;
22+
}
23+
exports.schemaTop = schemaTop;
24+
function schemaBottom() {
25+
return `
26+
timestamps: { createdAt: "created_at", updatedAt: "updated_at" }
27+
});
28+
module.exports = userSchema;
29+
`;
30+
}
31+
exports.schemaBottom = schemaBottom;
32+
// module.exports = {
33+
// createSchemaObject,
34+
// schemaTop,
35+
// schemaBottom,
36+
// };

0 commit comments

Comments
 (0)