Skip to content

Commit 724855b

Browse files
committed
chore: generate package.json file and give a hint on how to run an app
1 parent f1df2ce commit 724855b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/cli.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const yaml = require('js-yaml');
44
const fs = require('fs');
5+
const path = require('path');
56

67
const endpointsFile = 'endpoints.yaml';
78
const resultFile = 'app.js';
@@ -41,5 +42,31 @@ const createEndpoints = (config, resultFile) => {
4142
fs.writeFileSync(resultFile, resultedCode);
4243
};
4344

45+
const createPackageJson = (destDir, fileName) => {
46+
console.log('Generate', fileName);
47+
48+
const resultFile = path.join(destDir, fileName);
49+
const projectName = path.basename(destDir);
50+
console.log('Project name:', projectName);
51+
52+
const minimalPackageJson = `{
53+
"name": "${projectName}",
54+
"version": "1.0.0",
55+
"scripts": {
56+
"start": "node app.js"
57+
},
58+
"dependencies": {
59+
"express": "~4.17.1"
60+
}
61+
}\n`.replace(/^ /gm, '');
62+
63+
fs.writeFileSync(resultFile, minimalPackageJson);
64+
};
65+
4466
const config = loadConfig(endpointsFile);
4567
createEndpoints(config, resultFile);
68+
69+
const destDir = process.cwd();
70+
createPackageJson(destDir, 'package.json');
71+
72+
console.info('The application has been generated!\nUse\n npm install\nto install its dependencies and\n npm start\nafteward to run it');

0 commit comments

Comments
 (0)