Skip to content

Commit a1a6abe

Browse files
committed
chore: add --lang option
At this moment it defaults to "js" and everything works as before. But if you pass --lang go it won't generate JS-related files. Part of #9
1 parent b2a7ac3 commit a1a6abe

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
},
3232
"dependencies": {
3333
"ejs": "~3.1.3",
34-
"js-yaml": "~3.14.0"
34+
"js-yaml": "~3.14.0",
35+
"minimist": "~1.2.5"
3536
}
3637
}

src/cli.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@ const ejs = require('ejs');
55
const fs = require('fs');
66
const path = require('path');
77

8+
const parseArgs = require('minimist');
9+
810
const endpointsFile = 'endpoints.yaml';
911
const appFile = 'app.js';
1012
const routesFile = 'routes.js';
1113

14+
const parseCommandLineArgs = (args) => {
15+
const opts = {
16+
'string': [ 'lang' ],
17+
'default': {
18+
'lang': 'js'
19+
}
20+
};
21+
const argv = parseArgs(args, opts);
22+
//console.debug('argv:', argv);
23+
return argv;
24+
}
25+
1226
const loadConfig = (endpointsFile) => {
1327
console.log('Read', endpointsFile);
1428
try {
@@ -108,9 +122,11 @@ const createPackageJson = async (destDir, fileName) => {
108122
fs.writeFileSync(resultFile, minimalPackageJson);
109123
};
110124

125+
const argv = parseCommandLineArgs(process.argv.slice(2));
126+
111127
const config = loadConfig(endpointsFile);
112128

113-
let [,, destDir = '.'] = process.argv;
129+
let destDir = argv._.length > 0 ? argv._[0] : '.';
114130
destDir = path.resolve(process.cwd(), destDir);
115131
console.log('Destination directory:', destDir)
116132

@@ -119,14 +135,18 @@ if (!fs.existsSync(destDir)) {
119135
fs.mkdirSync(destDir, {recursive: true});
120136
}
121137

122-
createApp(destDir, appFile, config);
123-
createEndpoints(destDir, routesFile, config);
124-
createPackageJson(destDir, 'package.json');
138+
if (argv.lang === 'js') {
139+
createApp(destDir, appFile, config);
140+
createEndpoints(destDir, routesFile, config);
141+
createPackageJson(destDir, 'package.json');
142+
}
125143

126-
console.info(`The application has been generated!
127-
Use
144+
console.info('The application has been generated!')
145+
if (argv.lang === 'js') {
146+
console.info(`Use
128147
npm install
129148
to install its dependencies and
130149
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
131150
npm start
132151
afteward to run it`);
152+
}

0 commit comments

Comments
 (0)