Skip to content

Commit 3aac1c4

Browse files
feat: suppress install output
- make the install command silent - output a spinner instead of the normal install output so the user knows what is happening and the cli didn't stall - output a console line when we start the applications to tell the user what is happening - rename entrypoint files from mantis to mantis-app to be consistent with the package name we publish to npm Closes #22
1 parent c44a579 commit 3aac1c4

File tree

7 files changed

+68
-51
lines changed

7 files changed

+68
-51
lines changed

bin/mantis-app.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
import '../dist/mantis-app.mjs'

bin/mantis.mjs

-3
This file was deleted.

build.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineBuildConfig } from 'unbuild';
22

33
export default defineBuildConfig({
4-
entries: ['src/mantis'],
4+
entries: ['src/mantis-app'],
55
});

package-lock.json

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

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
},
3030
"type": "module",
3131
"bin": {
32-
"mantis": "./bin/mantis.mjs"
32+
"mantis-app": "./bin/mantis-app.mjs"
3333
},
3434
"files": [
3535
"dist",
3636
"templates"
3737
],
3838
"scripts": {
39-
"start:dev": "npm run build && node dist/mantis.mjs",
39+
"start:dev": "npm run build && node dist/mantis-app.mjs",
4040
"build": "unbuild",
4141
"format": "prettier --write \"**/*.ts\"",
4242
"lint": "eslint '{lib,commands,actions}/**/*.ts' --fix",
@@ -66,9 +66,11 @@
6666
"figlet": "^1.7.0",
6767
"fs-extra": "^11.2.0",
6868
"gradient-string": "^2.0.2",
69+
"log-symbols": "^6.0.0",
6970
"mongodb": "^6.3.0",
7071
"node-emoji": "^2.1.3",
7172
"nypm": "^0.3.6",
73+
"ora": "^8.0.1",
7274
"portscanner": "^2.2.0",
7375
"shelljs": "^0.8.5",
7476
"spinnies": "^0.5.1",

src/commands/init.command.ts

+52-23
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,27 @@ import { fileURLToPath } from 'url';
66
import { execa } from 'execa';
77
import Enquirer from 'enquirer';
88
import { MongoClient } from 'mongodb';
9+
import ora from 'ora';
10+
import logSymbols from 'log-symbols';
911

1012
const __dirname = fileURLToPath(new URL('.', import.meta.url));
1113

1214
export default new Command('init')
1315
.description('Create a basic mantis app')
1416
.action(async () => {
15-
const templatePath = path.resolve(__dirname, '../templates/mantis-todo');
16-
const workspacePath = path.join(process.cwd(), 'mantis-todo');
17-
// Get db url
18-
const dbUrl = await promptForDbUrl();
19-
// Copy over files
20-
await fs.copy(templatePath, workspacePath, { overwrite: true });
21-
const envPath = path.join(workspacePath, 'apps/server/.env.local');
22-
await fs.ensureFile(envPath);
23-
await fs.appendFile(envPath, `\nMONGODB_URI='${dbUrl}'`);
24-
// Install dependencies
25-
await installDependencies({
26-
cwd: workspacePath,
27-
});
28-
// Start application
29-
await execa(
30-
'npx',
31-
[
32-
'nx',
33-
'run-many',
34-
'--target=serve',
35-
'--projects=web-client,mobile-client,server',
36-
],
37-
{ cwd: workspacePath, stdio: 'inherit' },
17+
const templateName = 'mantis-todo';
18+
const templatePath = path.resolve(
19+
__dirname,
20+
`../templates/${templateName}`,
3821
);
22+
const workspaceName = 'mantis-todo';
23+
const workspacePath = path.join(process.cwd(), workspaceName);
24+
await fs.ensureDir(workspacePath);
25+
26+
const dbUrl = await promptForDbUrl();
27+
await copyTemplate({ templatePath, workspacePath, secrets: { dbUrl } });
28+
await installDependenciesWithMessage(workspacePath);
29+
await startApplications(workspacePath);
3930
});
4031

4132
const promptForDbUrl = async (): Promise<string> => {
@@ -60,3 +51,41 @@ const promptForDbUrl = async (): Promise<string> => {
6051
]);
6152
return dbUrl;
6253
};
54+
55+
const copyTemplate = async ({
56+
templatePath,
57+
workspacePath,
58+
secrets: { dbUrl },
59+
}: {
60+
templatePath: string;
61+
workspacePath: string;
62+
secrets: { dbUrl: string };
63+
}) => {
64+
await fs.copy(templatePath, workspacePath, { overwrite: true });
65+
const envPath = path.join(workspacePath, 'apps/server/.env.local');
66+
await fs.ensureFile(envPath);
67+
await fs.appendFile(envPath, `\nMONGODB_URI='${dbUrl}'`);
68+
};
69+
70+
const installDependenciesWithMessage = async (workspacePath: string) => {
71+
const spinner = ora('Installing dependencies').start();
72+
await installDependencies({
73+
cwd: workspacePath,
74+
silent: true,
75+
});
76+
spinner.succeed('Installed dependencies');
77+
};
78+
79+
const startApplications = async (workspacePath: string) => {
80+
console.log(`${logSymbols.info} Starting applications...`);
81+
await execa(
82+
'npx',
83+
[
84+
'nx',
85+
'run-many',
86+
'--target=serve',
87+
'--projects=web-client,mobile-client,server',
88+
],
89+
{ cwd: workspacePath, stdio: 'inherit' },
90+
);
91+
};

src/mantis.ts src/mantis-app.ts

File renamed without changes.

0 commit comments

Comments
 (0)