Skip to content

Commit

Permalink
Added semla cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
jonerer committed Oct 26, 2024
1 parent 5fb8b61 commit e6942bf
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 27 deletions.
14 changes: 0 additions & 14 deletions semla/babel.config.js

This file was deleted.

56 changes: 56 additions & 0 deletions semla/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node

import { program } from 'commander'
import { runMigrations, start } from '../lib.js'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import execa from 'execa'

program
.version('1.0.0')
.description('Your CLI description')
.option('-n, --name <name>', 'input name')
.option('-d, --debug', 'output extra debugging')

program
.command('dev')
.description('Run the development server')
.action(() => {
/*
We run the dev server by invoking nodemon in the applications root directory.
We tell nodemon to watch the app directory for changes, and to execute the dev.js script in the bin directory.
*/

const appdir = process.cwd()

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

console.log('Running development server')
execa(
'nodemon',
['--watch', appdir, '--exec', 'node ' + __dirname + '/dev.js'],
{
stdio: 'inherit',
env: {
...process.env,
NODE_ENV: 'dev',
},
}
)
})

program
.command('migrate')
.description('Run migrations')
.action(() => {
runMigrations()
})
const options = program.opts()

if (options.debug) console.log(options)
if (options.name) console.log(`Hello ${options.name}!`)

program.parse()
3 changes: 3 additions & 0 deletions semla/bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
import { start } from '../lib.js'
start()
2 changes: 2 additions & 0 deletions semla/buildSpa.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require('@babel/register')

// note: this is WIP (or more likely on the way to the trash can. maybe use inertia instead.)

const fw = require('./fw/fw')
const { buildSpa, getFwSpa } = require('./fw/spas')
const { setAppBasedir } = require('./fw/appinfo.js')
Expand Down
2 changes: 1 addition & 1 deletion semla/fw/appinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

let appBasedir = __dirname
let appBasedir = process.cwd()
let relativeBasedir = '..'
let fwBaseDir = __dirname

Expand Down
3 changes: 0 additions & 3 deletions semla/libbabel.js

This file was deleted.

9 changes: 0 additions & 9 deletions semla/migrate.js

This file was deleted.

4 changes: 4 additions & 0 deletions semla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "semla",
"version": "0.0.2",
"license": "MIT",
"bin": {
"semla": "./bin/cli.js"
},
"scripts": {
"dev": "cross-env NODE_ENV=dev nodemon index.js",
"migrate": "node migrate.js",
Expand Down Expand Up @@ -31,6 +34,7 @@
"chalk": "^4.1.0",
"cheerio": "^1.0.0-rc.3",
"chokidar": "^3.3.1",
"commander": "^12.1.0",
"connect-pg-simple": "^6.1.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
Expand Down
5 changes: 5 additions & 0 deletions semla/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

commander@^12.1.0:
version "12.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3"
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==

commander@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
Expand Down

0 comments on commit e6942bf

Please sign in to comment.