Skip to content

Commit c320cfd

Browse files
Vitalii BulyzhynVitalii Bulyzhyn
Vitalii Bulyzhyn
authored and
Vitalii Bulyzhyn
committed
Add checker function to check if the cli is executed in valud Diffgram directory
1 parent 0566c67 commit c320cfd

File tree

6 files changed

+61
-19
lines changed

6 files changed

+61
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules
2-
docker-compose-dev.yaml
2+
docker-compose-dev.yaml
3+
.env

bin/index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env node
22
const yargs = require("yargs")
3-
const create_action = require('./utils/action')
4-
const create_dev_container = require('./utils/container')
3+
const createAction = require('./utils/action')
4+
const createDevContainer = require('./utils/container')
5+
const dirChecker = require('./tools/dirChecker')
56

6-
const usage = "\nDiffgram CLI:";
7-
const options = yargs
8-
.usage(usage)
9-
.command('action [NewActionName]', 'Creates a new Diffgram action', (yargs) => {
10-
yargs.positional('NewActionName', {
11-
type: 'string',
12-
describe: 'Name of your new Diffgram action'
13-
})
14-
}, create_action)
15-
.command('compose', 'Creates a docker-compose file for development environment', create_dev_container)
16-
.help(true)
17-
.argv;
7+
dirChecker()
8+
9+
yargs
10+
.usage("\nDiffgram CLI:")
11+
.command('action [NewActionName]', 'Creates a new Diffgram action', (yargs) => {
12+
yargs.positional('NewActionName', {
13+
type: 'string',
14+
describe: 'Name of your new Diffgram action'
15+
})
16+
}, createAction)
17+
.command('compose', 'Creates a docker-compose file for development environment', createDevContainer)
18+
.help(true)
19+
.argv;

bin/tools/dirChecker.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require('dotenv').config();
2+
const fs = require('fs');
3+
4+
const dev = process.env.DEV
5+
6+
const diffgramDirectoryItems = [
7+
"install.py",
8+
"default",
9+
"walrus",
10+
"local_dispatcher",
11+
"shared",
12+
"frontend"
13+
]
14+
15+
function dirChecker() {
16+
if (dev === 'true') {
17+
console.log("Running in dev mode")
18+
return
19+
}
20+
21+
const currentPath = process.cwd();
22+
filenames = fs.readdirSync(currentPath);
23+
24+
const validDirectory = diffgramDirectoryItems.every(item => filenames.includes(item))
25+
26+
if (!validDirectory) {
27+
console.log("You are not in a valid Diffgram folder")
28+
process.exit()
29+
}
30+
}
31+
32+
33+
module.exports = dirChecker

bin/utils/container.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const prompt = new Prompt({
4545
choices: [ ...Object.keys(templateMap) ]
4646
});
4747

48-
function create_dev_container () {
49-
const file_to_create = `${process.cwd()}/docker-compose-dev.yaml`
48+
function createDevContainer () {
49+
const fileToCreate = `${process.cwd()}/docker-compose-dev.yaml`
5050

5151
const baseComposeFileBuffer = readModuleFile("../snippets/docker-compose/base.txt");
5252
const baseTemplate = baseComposeFileBuffer.toString()
@@ -68,9 +68,9 @@ function create_dev_container () {
6868
servicesTemplate += '\n'
6969
})
7070
const composeReady = baseTemplate.replace(replacer, servicesTemplate)
71-
fs.writeFileSync(file_to_create, composeReady);
71+
fs.writeFileSync(fileToCreate, composeReady);
7272
console.log('Now you can run your dev container with "docker-compose -f docker-compose-dev.yaml up"')
7373
})
7474
}
7575

76-
module.exports = create_dev_container;
76+
module.exports = createDevContainer;

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"author": "Diffgram",
1818
"license": "ISC",
1919
"dependencies": {
20+
"dotenv": "^16.0.1",
2021
"prompt-checkbox": "^2.2.0",
2122
"yargs": "^17.5.1"
2223
}

0 commit comments

Comments
 (0)