Skip to content

Commit 4c4bcf2

Browse files
committed
refactor: move classes into separate files
Part of #31
1 parent 0d485ec commit 4c4bcf2

File tree

6 files changed

+77
-75
lines changed

6 files changed

+77
-75
lines changed

src/cli.js

+2-75
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const parseArgs = require('minimist')
1010

1111
const { Parser } = require('node-sql-parser')
1212

13+
const Generator = require('./generator/Generator')
14+
1315
const endpointsFile = 'endpoints.yaml'
1416

1517
const parseCommandLineArgs = (args) => {
@@ -335,81 +337,6 @@ const createTypeScriptConfig = async (destDir, lang) => {
335337
return fsPromises.writeFile(resultFile, tsConfigJson)
336338
}
337339

338-
class JsGenerator {
339-
340-
usageExampleAsText() {
341-
return `Use
342-
npm install
343-
to install its dependencies and
344-
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
345-
npm start
346-
afteward to run`
347-
}
348-
349-
}
350-
351-
class TsGenerator {
352-
353-
usageExampleAsText() {
354-
return `Use
355-
npm install
356-
to install its dependencies,
357-
npm run build
358-
to build the application, and
359-
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
360-
npm start
361-
afteward to run`
362-
}
363-
364-
}
365-
366-
class GoGenerator {
367-
368-
usageExampleAsText() {
369-
return `Use
370-
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
371-
go run *.go
372-
or
373-
go build -o app
374-
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
375-
./app
376-
to build and run it`
377-
}
378-
379-
}
380-
381-
class PyGenerator {
382-
383-
usageExampleAsText() {
384-
return `Use
385-
pip install -r requirements.txt
386-
to install its dependencies and
387-
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
388-
uvicorn app:app
389-
afteward to run`
390-
}
391-
392-
}
393-
394-
class Generator {
395-
396-
static for(lang) {
397-
switch (lang) {
398-
case 'js':
399-
return new JsGenerator()
400-
case 'ts':
401-
return new TsGenerator()
402-
case 'go':
403-
return new GoGenerator()
404-
case 'python':
405-
return new PyGenerator()
406-
default:
407-
throw new Error(`Unsupported language: ${lang}`)
408-
}
409-
}
410-
411-
}
412-
413340
const absolutePathToDestDir = (argv) => {
414341
const relativeDestDir = argv._.length > 0 ? argv._[0] : argv['dest-dir']
415342
return path.resolve(process.cwd(), relativeDestDir)

src/generator/Generator.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const JsGenerator = require('./JsGenerator')
2+
const TsGenerator = require('./TsGenerator')
3+
const GoGenerator = require('./GoGenerator')
4+
const PyGenerator = require('./PyGenerator')
5+
6+
module.exports = class Generator {
7+
8+
static for(lang) {
9+
switch (lang) {
10+
case 'js':
11+
return new JsGenerator()
12+
case 'ts':
13+
return new TsGenerator()
14+
case 'go':
15+
return new GoGenerator()
16+
case 'python':
17+
return new PyGenerator()
18+
default:
19+
throw new Error(`Unsupported language: ${lang}`)
20+
}
21+
}
22+
23+
}

src/generator/GoGenerator.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = class GoGenerator {
2+
3+
usageExampleAsText() {
4+
return `Use
5+
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
6+
go run *.go
7+
or
8+
go build -o app
9+
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
10+
./app
11+
to build and run it`
12+
}
13+
14+
}

src/generator/JsGenerator.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = class JsGenerator {
2+
3+
usageExampleAsText() {
4+
return `Use
5+
npm install
6+
to install its dependencies and
7+
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
8+
npm start
9+
afteward to run`
10+
}
11+
12+
}

src/generator/PyGenerator.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = class PyGenerator {
2+
3+
usageExampleAsText() {
4+
return `Use
5+
pip install -r requirements.txt
6+
to install its dependencies and
7+
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
8+
uvicorn app:app
9+
afteward to run`
10+
}
11+
12+
}

src/generator/TsGenerator.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = class TsGenerator {
2+
3+
usageExampleAsText() {
4+
return `Use
5+
npm install
6+
to install its dependencies,
7+
npm run build
8+
to build the application, and
9+
export DB_NAME=db DB_USER=user DB_PASSWORD=secret
10+
npm start
11+
afteward to run`
12+
}
13+
14+
}

0 commit comments

Comments
 (0)