Comparing version 0.0.6 to 0.0.7
@@ -1,5 +0,2 @@ | ||
const { getKnownScripts } = require("./src/utils"); | ||
module.exports = { | ||
getKnownScripts, | ||
}; | ||
export { getKnownScripts } from "./src/utils.js"; | ||
export { logger as cliLogger } from "./src/logger.js"; |
{ | ||
"name": "@lbu/cli", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "CLI containing utilities and simple script runner", | ||
"main": "index.js", | ||
"type": "module", | ||
"bin": { | ||
@@ -19,4 +20,4 @@ "lbu": "./src/bin.js" | ||
"dependencies": { | ||
"@lbu/insight": "^0.0.6", | ||
"@lbu/stdlib": "^0.0.6", | ||
"@lbu/insight": "^0.0.7", | ||
"@lbu/stdlib": "^0.0.7", | ||
"nodemon": "2.0.2" | ||
@@ -38,3 +39,3 @@ }, | ||
}, | ||
"gitHead": "a7b150d9265f449127dc812d4bcef7fb803d6d63" | ||
"gitHead": "4c2199aeb1052bab67b3b1355bd648086736abf7" | ||
} |
@@ -27,16 +27,15 @@ # @lbu/cli | ||
- @lbu/cli: Project template, and simple script runner | ||
- @lbu/code-gen: Flexible code generators. Supports generating validators, | ||
router, SQL and more | ||
- @lbu/code-gen: Flexible code generators. Supports generating router, validator | ||
- @lbu/insight: Opinionated logger | ||
- @lbu/server: Wrap around Koa and some useful middleware | ||
- @lbu/stdlib: Growing library with features like uuid generation and background | ||
jobs | ||
- @lbu/stdlib: Growing library of various common utilities like uuid & a basic | ||
templating system | ||
## Roadmap | ||
- [ ] @lbu/store: Common abstraction for FileSystem, Redis, Memory support for | ||
queues, KV store etc | ||
- [ ] @lbu/code-gen: More plugins | ||
- [ ] @lbu/code-gen: OpenAPI importer | ||
- [ ] @lbu/features: Feature flag implementation based on @lbu/store & support | ||
for code-gen | ||
- [ ] @lbu/code-gen: Postgres query generator | ||
## Docs | ||
@@ -43,0 +42,0 @@ |
@@ -1,8 +0,10 @@ | ||
const { mainFn } = require("@lbu/stdlib"); | ||
import { dirnameForModule, mainFn } from "@lbu/stdlib"; | ||
import { readFileSync } from "fs"; | ||
import { join } from "path"; | ||
import { cliLogger, getKnownScripts } from "../index.js"; | ||
const { logger } = require("../src/logger"); | ||
const { getKnownScripts } = require("../src/utils"); | ||
const { name, version } = JSON.parse( | ||
readFileSync(join(dirnameForModule(import.meta), "../package.json"), "utf-8"), | ||
); | ||
const { name, version } = require("../package"); | ||
const formatCommands = () => { | ||
@@ -25,3 +27,3 @@ const scripts = getKnownScripts(); | ||
mainFn(module, require, logger, logger => { | ||
mainFn(import.meta, cliLogger, async logger => { | ||
logger.info( | ||
@@ -32,4 +34,2 @@ `${name} -- ${version}\nUsage: lbu [command] [...args]\n\nAvailable commands:\n${formatCommands()}`, | ||
module.exports = { | ||
disallowNodemon: true, | ||
}; | ||
export const disallowNodemon = true; |
@@ -1,3 +0,3 @@ | ||
const { mainFn, spawn } = require("@lbu/stdlib"); | ||
const { | ||
import { dirnameForModule, mainFn, spawn } from "@lbu/stdlib"; | ||
import { | ||
existsSync, | ||
@@ -9,7 +9,9 @@ lstatSync, | ||
writeFileSync, | ||
} = require("fs"); | ||
const { join } = require("path"); | ||
const { logger } = require("../src/logger"); | ||
} from "fs"; | ||
import { join } from "path"; | ||
import { cliLogger } from "../index.js"; | ||
const { version } = require("../package"); | ||
const { version } = JSON.parse( | ||
readFileSync(join(dirnameForModule(import.meta), "../package.json"), "utf-8"), | ||
); | ||
@@ -35,8 +37,11 @@ const copyDirRecursive = (source, target, contentHandler) => { | ||
mainFn(module, require, logger, async () => { | ||
mainFn(import.meta, cliLogger, async () => { | ||
const outDir = process.cwd(); | ||
const projectName = outDir.substring(outDir.lastIndexOf("/") + 1); | ||
copyDirRecursive(join(__dirname, "../template"), outDir, input => | ||
input.replace(/{{name}}/g, projectName).replace(/{{version}}/g, version), | ||
copyDirRecursive( | ||
join(dirnameForModule(import.meta), "../template"), | ||
outDir, | ||
input => | ||
input.replace(/{{name}}/g, projectName).replace(/{{version}}/g, version), | ||
); | ||
@@ -43,0 +48,0 @@ |
@@ -1,5 +0,5 @@ | ||
const { mainFn, spawn } = require("@lbu/stdlib"); | ||
const { logger } = require("../src/logger"); | ||
import { mainFn, spawn } from "@lbu/stdlib"; | ||
import { cliLogger } from "../index.js"; | ||
mainFn(module, require, logger, async () => { | ||
mainFn(import.meta, cliLogger, async () => { | ||
await spawn("./node_modules/.bin/eslint", [ | ||
@@ -6,0 +6,0 @@ "./**/*.js", |
#!/usr/bin/env node | ||
const { mainFn } = require("@lbu/stdlib"); | ||
const { logger } = require("./logger"); | ||
const { execScript } = require("./exec"); | ||
import { mainFn } from "@lbu/stdlib"; | ||
import { execScript } from "./exec.js"; | ||
import { logger } from "./logger.js"; | ||
mainFn(module, require, logger, logger => { | ||
mainFn(import.meta, logger, logger => { | ||
const [cmd, ...args] = process.argv.slice(2); | ||
return execScript(logger, cmd, args); | ||
}); |
@@ -1,6 +0,13 @@ | ||
const { isNil, spawn } = require("@lbu/stdlib"); | ||
const { join, resolve } = require("path"); | ||
const { getKnownScripts } = require("./utils"); | ||
import { isNil, spawn } from "@lbu/stdlib"; | ||
import { join } from "path"; | ||
import { getKnownScripts } from "./utils.js"; | ||
/** | ||
* @typedef {{ | ||
* disallowNodemon?: boolean, | ||
* nodemonArgs?: string, | ||
* }} ExecOpts | ||
*/ | ||
/** | ||
* TODO: Watch docs & nodemon customization | ||
@@ -11,3 +18,3 @@ * @param {Logger} logger | ||
*/ | ||
const execScript = (logger, cmd = "help", args = []) => { | ||
export const execScript = (logger, cmd = "help", args = []) => { | ||
let watch = false; | ||
@@ -45,5 +52,5 @@ if (cmd === "--watch") { | ||
const execJsFile = (logger, script, cmd, args, watch) => { | ||
const execJsFile = async (logger, script, cmd, args, watch) => { | ||
if (watch) { | ||
const opts = require(script.path) || {}; | ||
const opts = (await import(script.path)) || {}; | ||
@@ -71,18 +78,9 @@ if (opts.disallowNodemon) { | ||
const execYarnScript = (logger, script, cmd, args, watch) => { | ||
const pattern = /^node ([.\w/]*\.js)(.*)$/gi; | ||
if (watch) { | ||
const patternResult = pattern.exec(script.script); | ||
if (patternResult === null) { | ||
logger.error( | ||
"Can only convert Yarn scripts to enable watch mode if they look like 'node src/script.js --args'", | ||
); | ||
} else { | ||
return execJsFile( | ||
logger, | ||
{ path: resolve(patternResult[1]) }, | ||
`yarn run ${cmd}`, | ||
patternResult[2].split(" "), | ||
true, | ||
); | ||
} | ||
return spawn(`./node_modules/.bin/nodemon`, [ | ||
"--exec", | ||
script.script, | ||
"--", | ||
...args, | ||
]); | ||
} | ||
@@ -92,5 +90,1 @@ | ||
}; | ||
module.exports = { | ||
execScript, | ||
}; |
@@ -1,4 +0,4 @@ | ||
const { newLogger } = require("@lbu/insight"); | ||
import { newLogger } from "@lbu/insight"; | ||
const logger = newLogger({ | ||
export const logger = newLogger({ | ||
ctx: { | ||
@@ -8,5 +8,1 @@ type: "CLI", | ||
}); | ||
module.exports = { | ||
logger, | ||
}; |
@@ -1,5 +0,6 @@ | ||
const { existsSync, readdirSync } = require("fs"); | ||
const { join } = require("path"); | ||
import { dirnameForModule } from "@lbu/stdlib"; | ||
import { existsSync, readdirSync, readFileSync } from "fs"; | ||
import { join } from "path"; | ||
const getKnownScripts = () => { | ||
export const getKnownScripts = () => { | ||
const result = {}; | ||
@@ -21,3 +22,3 @@ | ||
if (existsSync(pkgJsonPath)) { | ||
const pkgJson = require(pkgJsonPath); | ||
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf-8")); | ||
for (const item of Object.keys(pkgJson.scripts || {})) { | ||
@@ -28,3 +29,3 @@ result[item] = { type: "YARN", script: pkgJson.scripts[item] }; | ||
const cliDir = join(__dirname, "../scripts"); | ||
const cliDir = join(dirnameForModule(import.meta), "../scripts"); | ||
for (const item of readdirSync(cliDir)) { | ||
@@ -41,5 +42,1 @@ const name = item.split(".")[0]; | ||
}; | ||
module.exports = { | ||
getKnownScripts, | ||
}; |
@@ -5,4 +5,5 @@ { | ||
"name": "{{name}}", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node src/index.js" | ||
"start": "node src/api.js" | ||
}, | ||
@@ -13,3 +14,4 @@ "dependencies": { | ||
"@lbu/stdlib": "{{version}}", | ||
"dotenv": "8.2.0" | ||
"axios": "0.19.2", | ||
"chance": "1.1.4" | ||
}, | ||
@@ -20,3 +22,4 @@ "devDependencies": { | ||
"@lbu/lint-config": "{{version}}" | ||
} | ||
}, | ||
"prettier": "@lbu/lint-config/prettierrc" | ||
} |
@@ -1,28 +0,38 @@ | ||
const { mainFn } = require("@lbu/stdlib"); | ||
const { | ||
import { | ||
App, | ||
getApiClientPlugin, | ||
getMocksPlugin, | ||
getRouterPlugin, | ||
getValidatorsPlugin, | ||
getTypesPlugin, | ||
getValidatorPlugin, | ||
M, | ||
runCodeGen, | ||
} = require("@lbu/code-gen"); | ||
const { log } = require("@lbu/insight"); | ||
} from "@lbu/code-gen"; | ||
import { log } from "@lbu/insight"; | ||
import { mainFn } from "@lbu/stdlib"; | ||
const app = new App("TODO App"); | ||
app.model( | ||
M("MyObject").object({ | ||
userName: M.string().mock("__.first"), | ||
}), | ||
); | ||
const main = async logger => { | ||
await runCodeGen(logger, () => { | ||
return { | ||
validators: [], | ||
routes: [], | ||
routeTrie: { | ||
children: [], | ||
}, | ||
}; | ||
}).build({ | ||
plugins: [getValidatorsPlugin(), getRouterPlugin()], | ||
outputDir: "./src/generated", | ||
// Code gen validators | ||
await runCodeGen(logger, () => app.build()).build({ | ||
plugins: [ | ||
getTypesPlugin(), | ||
getValidatorPlugin(), | ||
getRouterPlugin(), | ||
getMocksPlugin(), | ||
getApiClientPlugin(), | ||
], | ||
outputDir: "./generated", | ||
}); | ||
}; | ||
mainFn(module, require, log, main); | ||
mainFn(import.meta, log, main); | ||
module.exports = { | ||
nodemonArgs: "--ignore src/generated", | ||
}; | ||
export const nodemonArgs = "--ignore generated -e tmpl,js,json"; |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
12100
302
Yes
47
6
+ Added@lbu/insight@0.0.7(transitive)
+ Added@lbu/stdlib@0.0.7(transitive)
+ Addeddotenv@8.2.0(transitive)
- Removed@lbu/insight@0.0.6(transitive)
- Removed@lbu/stdlib@0.0.6(transitive)
Updated@lbu/insight@^0.0.7
Updated@lbu/stdlib@^0.0.7