Skip to content

Commit 7459d12

Browse files
authored
Merge pull request #16 from eKhattak/canary
v1.2.0
2 parents 759baad + 3cd00f8 commit 7459d12

File tree

12 files changed

+356
-87
lines changed

12 files changed

+356
-87
lines changed

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: NPM Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
name: Pubish
11+
runs-on: ubuntu-latest,
12+
steps:
13+
- name: ⏬ checkout
14+
uses: actions/[email protected]
15+
- name: 📦 Node
16+
uses: actions/[email protected]
17+
with:
18+
node-version: 12
19+
registry-url: https://registry.npmjs.org
20+
- name: 🚀 Publish
21+
run: npm publish --access publish
22+
env:
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.npmignore

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
out/*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
*.pid.lock
14+
15+
# Directory for instrumented libs generated by jscoverage/JSCover
16+
lib-cov
17+
18+
# Coverage directory used by tools like istanbul
19+
coverage
20+
21+
# nyc test coverage
22+
.nyc_output
23+
24+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25+
.grunt
26+
27+
# Bower dependency directory (https://bower.io/)
28+
bower_components
29+
30+
# node-waf configuration
31+
.lock-wscript
32+
33+
# IDEs and editors
34+
.idea
35+
.project
36+
.classpath
37+
.c9/
38+
*.launch
39+
.settings/
40+
*.sublime-workspace
41+
42+
# IDE - VSCode
43+
.vscode/*
44+
!.vscode/settings.json
45+
!.vscode/tasks.json
46+
!.vscode/launch.json
47+
!.vscode/extensions.json
48+
49+
# misc
50+
.sass-cache
51+
connect.lock
52+
typings
53+
54+
# Logs
55+
logs
56+
*.log
57+
npm-debug.log*
58+
yarn-debug.log*
59+
yarn-error.log*
60+
61+
62+
# Dependency directories
63+
node_modules/
64+
jspm_packages/
65+
66+
# Optional npm cache directory
67+
.npm
68+
69+
# Optional eslint cache
70+
.eslintcache
71+
72+
# Optional REPL history
73+
.node_repl_history
74+
75+
# Output of 'npm pack'
76+
*.tgz
77+
78+
# Yarn Integrity file
79+
.yarn-integrity
80+
81+
# dotenv environment variables file
82+
.env
83+
84+
# next.js build output
85+
.next
86+
87+
# Lerna
88+
lerna-debug.log
89+
90+
# System Files
91+
.DS_Store
92+
Thumbs.db
93+
94+
/src
95+
/bin
96+
/template
97+
/.vscode
98+
99+
./src
100+
./bin
101+
./template
102+
./.vscode
File renamed without changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
22

3-
const cli = require("../src/cli");
4-
3+
import cli from "../src/cli";
54
cli(process.argv);

package-lock.json

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "mongoose-schema-cli",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "A MongoDB Schema Generator CLI",
55
"main": "index.js",
6+
"files": [
7+
"dist"
8+
],
69
"bin": {
7-
"msc": "bin/index.js"
10+
"msc": "dist/bin/index.js"
811
},
912
"repository": {
1013
"type": "git",
@@ -21,8 +24,10 @@
2124
"author": "Arsalan Khattak <[email protected]>",
2225
"license": "MIT",
2326
"dependencies": {
27+
"@types/inquirer": "^7.3.0",
28+
"@types/listr": "^0.14.2",
29+
"@types/node": "^14.0.27",
2430
"arg": "^4.1.3",
25-
"chalk": "^4.1.0",
2631
"inquirer": "^7.3.3",
2732
"listr": "^0.14.3"
2833
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
### [Demo](https://github.com/eKhattak/mongoose-schema-cli)
2323

24-
![Demo](/demo.gif)
24+
![Demo](/assets/demo.gif)
2525

2626
## Install
2727

src/cli.js renamed to src/cli.ts

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
const arg = require("arg");
2-
const inquirer = require("inquirer");
3-
const schema = require("./main");
4-
5-
// export var schemaDetails = {};
6-
function parseArgumentsIntoOptions(rawArgs) {
1+
import arg from "arg";
2+
import inquirer from "inquirer";
3+
import createSchema from "./main";
4+
5+
function parseArgumentsIntoOptions(
6+
rawArgs: any[]
7+
): {
8+
language: boolean;
9+
filePath: string;
10+
} {
711
const args = arg(
812
{
913
"--typescript": Boolean,
@@ -17,24 +21,39 @@ function parseArgumentsIntoOptions(rawArgs) {
1721
}
1822
);
1923
return {
20-
language: args["--typescript"] || undefined,
24+
language: args["--typescript"] || false,
2125
filePath: args["--filepath"] || "/",
2226
};
2327
}
2428

25-
async function promptForMissingOptions(options) {
29+
type optionsType = {
30+
language: boolean;
31+
filePath?: string;
32+
schemaKeys?: number | 0;
33+
};
34+
35+
type questionType = {
36+
type: string;
37+
name: string;
38+
message: string;
39+
default: string | boolean | number;
40+
choices?: string[] | number[];
41+
};
42+
43+
async function promptForMissingOptions(
44+
options: optionsType
45+
): Promise<{
46+
language: any;
47+
schema: any;
48+
filePath?: string | undefined;
49+
schemaKeys?: number | undefined;
50+
}> {
2651
const defaultOptions = {
2752
language: "Javascript",
2853
schema: "default",
2954
};
30-
// if (options.skipPrompts) {
31-
// return {
32-
// ...options,
33-
// template: options.template || defaultLanguage,
34-
// };
35-
// }
3655

37-
const questions = [];
56+
const questions: questionType[] = [];
3857
//@TODO: Temporary Disabled, Uncomment after adding Typescript Schema
3958
// if (!options.language) {
4059
// questions.push({
@@ -57,20 +76,18 @@ async function promptForMissingOptions(options) {
5776
return {
5877
...options,
5978
language: options.language || answers.language,
60-
mongoose: options.mongoose || answers.mongoose,
6179
schema: answers.schema,
6280
};
6381
}
6482

6583
async function promptForSchemaObject() {
66-
console.log();
6784
const defaultOptions = {
6885
name: "default",
6986
type: "String",
7087
required: true,
7188
default: "",
7289
};
73-
const questions = [];
90+
const questions: questionType[] = [];
7491

7592
questions.push({
7693
type: "input",
@@ -101,18 +118,23 @@ async function promptForSchemaObject() {
101118
default: defaultOptions.default,
102119
});
103120

104-
const answers = await inquirer.prompt(questions);
121+
const answers: {
122+
name: string;
123+
type: string;
124+
required: boolean;
125+
default: string;
126+
} = await inquirer.prompt(questions);
105127

106128
return {
107-
schemaName: answers.name,
129+
name: answers.name,
108130
type: answers.type,
109131
isRequired: answers.required,
110132
defaultValue: answers.default,
111133
};
112134
}
113135

114-
async function cli(args) {
115-
var options = parseArgumentsIntoOptions(args);
136+
async function cli(args: string[]) {
137+
var options: optionsType = parseArgumentsIntoOptions(args);
116138
options = await promptForMissingOptions(options);
117139

118140
const { schemaKeys } = await inquirer.prompt({
@@ -122,19 +144,20 @@ async function cli(args) {
122144
default: 0,
123145
});
124146

125-
// Get Schema Keys' Input
126-
const schemaKeyValues = [];
147+
const schemaKeyValues: {
148+
name: string;
149+
type: string;
150+
isRequired: boolean;
151+
defaultValue: string;
152+
}[] = [];
127153
for (let i = 0; i < schemaKeys; i++) {
128154
const objectValues = await promptForSchemaObject();
129155
schemaKeyValues.push(objectValues);
130156
}
131157

132-
options = {
133-
...options,
134-
schemaKeys,
135-
};
158+
var schema = { ...schemaKeys };
136159

137-
await schema(options, schemaKeyValues);
160+
await createSchema(schema, schemaKeyValues);
138161
}
139162

140-
module.exports = cli;
163+
export default cli;

0 commit comments

Comments
 (0)