Skip to content

Commit 0f8a39c

Browse files
committed
init work for create command
1 parent 22418fc commit 0f8a39c

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

lib/cli.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const yargs = require('yargs/yargs')
33
const dotenv = require('dotenv')
44
const path = require('path')
5+
const initStatusboard = require('./commands/create')
56

67
const SHARED_OPTIONS = {
78
db: {
@@ -81,8 +82,8 @@ module.exports = (create, builder, argv) => {
8182

8283
let cli = yargs()
8384

84-
.command('create', 'Create a StatusBoard', {}, async (argv) => {
85-
console.log('Coming soon!')
85+
.command('create [directory]', 'Create a StatusBoard', {}, async (argv) => {
86+
await initStatusboard(argv)
8687
})
8788

8889
.command('build', 'Index and build board', SHARED_OPTIONS, async (argv) => {

lib/commands/create.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const inquirer = require("inquirer");
2+
const path = require("node:path");
3+
const createPackageJson = require("create-package-json");
4+
5+
async function create(opts) {
6+
const { directory } = opts;
7+
let projectPath = directory;
8+
9+
if (!projectPath) {
10+
const res = await inquirer.prompt([
11+
{
12+
type: "input",
13+
name: "path",
14+
message: "Where would you like to create your project?",
15+
default: "statusboard",
16+
},
17+
]);
18+
19+
projectPath = res.path.trim();
20+
}
21+
22+
const appPath = path.resolve(projectPath);
23+
let projectName = path.basename(appPath);
24+
25+
const pkg = await createPackageJson(
26+
{
27+
name: projectName,
28+
description: '"A dashboard for project status',
29+
version: "1.0.0",
30+
dependencies: ["@pkgjs/statusboard"],
31+
author: null,
32+
keywords: null,
33+
repository: null,
34+
type: "commonjs",
35+
private: true,
36+
cwd: appPath,
37+
license: "MIT",
38+
main: "config.js",
39+
devDependencies: null,
40+
scrips: {
41+
build: "statusboard build -C ./config",
42+
buildsite: "npm run clean && statusboard site -C ./config",
43+
buildindex: "statusboard index -C ./config",
44+
clean: "rm -rf build/css build/js",
45+
},
46+
},
47+
{}
48+
);
49+
50+
console.log(pkg);
51+
console.log(projectPath, projectName);
52+
}
53+
54+
module.exports = create;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@wesleytodd/buildjs": "0.0.8",
4444
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
4545
"cptmpl": "0.0.4",
46+
"create-package-json": "^1.1.0",
4647
"dotenv": "^8.0.0",
4748
"es5-lit-element": "^2.2.1",
4849
"express": "^4.17.1",

0 commit comments

Comments
 (0)