Skip to content

Commit 24012ba

Browse files
committed
Started working on user snippets
1 parent d59c4e5 commit 24012ba

File tree

10 files changed

+95
-3
lines changed

10 files changed

+95
-3
lines changed

.vscode/snippets.code-snippets

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Domain index file": {
3+
"prefix": "nbp-di",
4+
"body": [
5+
"const { routes } = require('./api');",
6+
"",
7+
"const defineRoutes = (expressRouter) => {",
8+
" expressRouter.use('/${1:route}', routes());",
9+
"};",
10+
"",
11+
"module.exports = defineRoutes;"
12+
],
13+
"description": "Nodejs boilerplate domain's index file"
14+
},
15+
}

package-lock.json

Lines changed: 39 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"scripts": {
1111
"test": "jest",
1212
"test:watch": "jest --watch --verbose",
13-
"start": "nodemon src/start.js"
13+
"start": "nodemon src/start.js",
14+
"create-domain": "zx scripts/dev/domain-generator.js"
1415
},
1516
"keywords": [],
1617
"author": "",
@@ -35,6 +36,7 @@
3536
"devDependencies": {
3637
"jest": "^29.7.0",
3738
"mongodb-memory-server": "^9.1.8",
38-
"supertest": "^6.3.4"
39+
"supertest": "^6.3.4",
40+
"zx": "^8.0.1"
3941
}
4042
}

scripts/dev/domain-generator.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env zx
2+
3+
// Function to create the domain structure
4+
const createDomain = async (domainName) => {
5+
cd(`src/domains`);
6+
await $`mkdir ${domainName}`;
7+
8+
// Create the files
9+
await Promise.all([
10+
$`touch ${domainName}/api.js`,
11+
$`touch ${domainName}/event.js`,
12+
$`touch ${domainName}/index.js`,
13+
$`touch ${domainName}/request.js`,
14+
$`touch ${domainName}/schema.js`,
15+
$`touch ${domainName}/service.js`,
16+
]);
17+
};
18+
19+
// Main interaction loop
20+
const main = async () => {
21+
console.log('Enter the domain name:');
22+
23+
const domainName = await $`read domainName && echo $domainName`;
24+
console.log(`Creating domain ${domainName}`);
25+
// Create the domain
26+
await createDomain(domainName);
27+
};
28+
29+
// Run the main function
30+
main();

src/domains/student/api.js

Whitespace-only changes.

src/domains/student/event.js

Whitespace-only changes.

src/domains/student/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { routes } = require('./api');
2+
3+
const defineRoutes = (expressRouter) => {
4+
expressRouter.use('/student', routes());
5+
};
6+
7+
module.exports = defineRoutes;

src/domains/student/request.js

Whitespace-only changes.

src/domains/student/schema.js

Whitespace-only changes.

src/domains/student/service.js

Whitespace-only changes.

0 commit comments

Comments
 (0)