fib-typify
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -44,10 +44,18 @@ #!/usr/bin/env fibjs | ||
finalParams.configFilepath = getParamFromArgs(args, ['-c', '--config-file']) | ||
let configFilepath = finalParams.configFilepath ? path.resolve(baseDir, finalParams.configFilepath) : null | ||
let configFilepath = finalParams.configFilepath ? path.resolve(cwd, finalParams.configFilepath) : null | ||
isDebug && console.log('configFilepath', configFilepath) | ||
if (configFilepath && fs.exists(configFilepath)) { | ||
let config = {} | ||
try { | ||
config = JSON.parse(fs.readTextFile(configFilepath)) | ||
} catch (e) { | ||
console.warn(`error occured when trying to parse config file: ${configFilepath}`) | ||
if (['.json', '.js', '.jsc'].some(ext => configFilepath.endsWith(ext))) { | ||
config = require(configFilepath) | ||
isDebug && console.log('internal extension', config) | ||
} else { | ||
try { | ||
config = JSON.parse(fs.readTextFile(configFilepath)) | ||
} catch (e) { | ||
console.warn(`error occured when trying to parse config file: ${configFilepath}`) | ||
} | ||
} | ||
tsCompilerOptions = util.extend({}, tsCompilerOptions, config) | ||
@@ -54,0 +62,0 @@ } |
{ | ||
"name": "fib-typify", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "just write fibjs with typescript : )", | ||
@@ -44,4 +44,4 @@ "main": "index.js", | ||
"@fibjs/ci": "^2.0.0", | ||
"@types/fibjs": "github:fibjs/fib-types#v1.0.6" | ||
"@types/fibjs": "github:fibjs/fib-types#v1.0.7" | ||
} | ||
} |
@@ -16,2 +16,9 @@ # fib-typify | ||
```bash | ||
# locally | ||
fibjs --install fib-typify | ||
# or globally | ||
npm i -g fib-typify | ||
``` | ||
### APIs | ||
@@ -82,2 +89,21 @@ | ||
## CLI | ||
Started from `0.2.0`, you can run `fib-typify` in CLI. | ||
```bash | ||
fib-typify src -o lib -c .typify.json | ||
``` | ||
Command above means compiling directory `src` to directory `lib` with configuration file `.typify.json`. The default tsCompilerOptions is | ||
```javascript | ||
{ | ||
target: 'es6', | ||
module: 'commonjs' | ||
} | ||
``` | ||
if you want to extend it, just write .json/.js/.jsc file, and put its path relateive to `cwd()` after `-c`/`--config-file` CLI option. | ||
I only provided one simple and crude error exception mechanism, so in some cases it may be not friendly as you like, it's welcome to take PR to help optimizting this part of `fib-typify` :) | ||
## TODO | ||
@@ -93,3 +119,3 @@ | ||
- [ ] pack compiled '.jsc' to binary and extract one zipped file. | ||
- [ ] `--help` CLI option for cli | ||
## Contributions | ||
@@ -96,0 +122,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
62879
568
130
15