fib-typify
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -0,0 +0,0 @@ #!/usr/bin/env fibjs |
@@ -13,3 +13,3 @@ #!/usr/bin/env fibjs | ||
const pkgJson = require('../package.json') | ||
const cli = require('@fxjs/cli')(pkgJson.name) | ||
const cli = require('@fxjs/cli')('ftsc') | ||
@@ -21,14 +21,15 @@ const CWD = process.cwd() | ||
const runProgram = (fileNames, cmdLineOptions) => { | ||
const compilerOptions = util.pick(cmdLineOptions, [ | ||
'noEmit', | ||
'project', | ||
'outDir' | ||
]) | ||
const runProgram = (fileNames, compilerOptions, cmdLineOptions) => { | ||
const host = createCompilerHost(compilerOptions) | ||
if (!cmdLineOptions.project) cmdLineOptions.project = 'tsconfig.json' | ||
cmdLineOptions.project = fixNonAbsolutePath(cmdLineOptions.project, CWD) | ||
let parsedTSConfig | ||
// make compilerOptions.project absolute path. | ||
compilerOptions.project = fixNonAbsolutePath(compilerOptions.project || 'tsconfig.json', CWD) | ||
const configParsedResult = ts.parseConfigFileTextToJson(cmdLineOptions.project, fs.readTextFile(cmdLineOptions.project)) | ||
let tsconfigContent = JSON.stringify({}) | ||
try { | ||
tsconfigContent = fs.readTextFile(compilerOptions.project) | ||
} catch (error) {} | ||
const configParsedResult = ts.parseConfigFileTextToJson(compilerOptions.project, tsconfigContent) | ||
@@ -42,3 +43,3 @@ if (configParsedResult.error) | ||
// TODO: learn about ts.ParsedTsConfig, why its real value is augument of its declartion(in types) | ||
const parsedTSConfig = ts.parseJsonConfigFileContent( | ||
parsedTSConfig = ts.parseJsonConfigFileContent( | ||
inputTSConfig, | ||
@@ -90,24 +91,58 @@ /* parseConfigHost */getParseConfigHost(host, CWD), | ||
cli | ||
.command('[...files]', 'source file') | ||
// @TODO: use tyepscript's built-in 18n resources. | ||
.option('--noEmit <noEmit>', 'Do not emit outputs.', { | ||
default: false | ||
const topCmd = cli | ||
.command('[...files]', 'source files', { | ||
allowUnknownOptions: true | ||
}) | ||
.option('-p, --project <project>', 'tsconfig.json path', { | ||
default: path.resolve(CWD, './tsconfig.json') | ||
}) | ||
.option('--outDir [target]', 'output target', { | ||
default: path.resolve(CWD) | ||
}) | ||
/** | ||
* cmd options to be supported in the future. | ||
* | ||
* - [ ] ts.optionsForWatch | ||
* - [x] ts.optionDeclarations | ||
* - [ ] ts.transpileOptionValueCompilerOptions | ||
* - [ ] ts.buildOpts | ||
*/ | ||
ts.optionDeclarations.forEach(cmdOptionWithBuild => { | ||
if (cmdOptionWithBuild.name === 'help') return ; | ||
if (cmdOptionWithBuild.showInSimplifiedHelpView === false) return ; | ||
if (cmdOptionWithBuild.category && [ | ||
ts.Diagnostics.Basic_Options, | ||
ts.Diagnostics.Command_line_Options, | ||
ts.Diagnostics.Advanced_Options, | ||
].indexOf(cmdOptionWithBuild.category) === -1) return ; | ||
topCmd.option([ | ||
cmdOptionWithBuild.shortName ? `--${cmdOptionWithBuild.shortName} ` : '', | ||
`--${cmdOptionWithBuild.name} `, | ||
// `[XTS_${cmdOptionWithBuild.name}]` | ||
].filter(x => x).join(''), [ | ||
/** | ||
* @what if cmdOptionWithBuild.type !== 'string' but cmdOptionWithBuild.type is not empty, maybe it's ReturnType<ts.createMapFromTemplate()> | ||
*/ | ||
cmdOptionWithBuild.type && typeof cmdOptionWithBuild.type === 'string' ? `( type: ${cmdOptionWithBuild.type.padEnd(7, ' ')} ) ` : '', | ||
cmdOptionWithBuild.description ? `TS: ${cmdOptionWithBuild.description.message}` : '' | ||
].filter(x => x).join('')) | ||
}) | ||
topCmd | ||
// .option('--fib:cwd <fib_cwd>', 'just sample option', { | ||
// default: path.resolve(CWD) | ||
// }) | ||
.action(function (files, cmdLineOptions) { | ||
if (!files.length) { | ||
console.log('[ftsc] getCwdFilenamesR()', getCwdFilenamesR()); | ||
// by default, when no files input specified, ftsc use all ts(x) files at current directory as input. | ||
if (files.length) { | ||
// when files is not empty, use it as glob | ||
files = mm(getCwdFilenamesR(), files) | ||
} else { | ||
// if files empty, try to find all files with expected extentensions in CURRENT DIRECTORY | ||
files = mm(getCwdFilenamesR(), ['*.ts', '*.tsx']) | ||
} | ||
const parsedCommandLine = ts.parseCommandLine(process.argv.slice(2), fname => fs.readTextFile(fname)) | ||
if (parsedCommandLine.errors.length) | ||
throw new Error(parsedCommandLine.errors[0].messageText) | ||
runProgram(files, cmdLineOptions) | ||
runProgram(files, parsedCommandLine.options, cmdLineOptions) | ||
}) | ||
cli.help() | ||
@@ -114,0 +149,0 @@ cli.version(pkgJson.version) |
module.exports = { | ||
output: ['--out', '-o'] | ||
} |
@@ -0,0 +0,0 @@ const argFlags = require('./arg_flags') |
@@ -0,0 +0,0 @@ const fs = require('fs') |
module.exports = require('@fibjs/builtin-modules') |
@@ -0,0 +0,0 @@ const fs = require('fs') |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ const fs = require('fs') |
@@ -0,0 +0,0 @@ const fs = require('fs') |
@@ -0,0 +0,0 @@ const { getModuleTranspilor } = require('../ts-apis/transpilor') |
@@ -0,0 +0,0 @@ const fs = require('fs') |
@@ -0,0 +0,0 @@ const path = require('path') |
@@ -0,0 +0,0 @@ const ts = require('typescript') |
@@ -0,0 +0,0 @@ const ts = require('typescript') |
@@ -0,0 +0,0 @@ const ts = require('typescript') |
@@ -0,0 +0,0 @@ const ts = require('typescript') |
v0.7.0 / 2019-09-07 | ||
v0.8.1 / 2020-05-25 | ||
================== | ||
* feat: support more ts build options to ftsc, add test basic sample for ftsc. | ||
* chore: update doc. | ||
v0.8.0 / 2020-05-24 | ||
=================== | ||
* Release v0.8.0 | ||
* feat: replace program API in registerTsCompiler | ||
* feat: use customized ts program (#14) | ||
v0.7.0 / 2019-09-07 | ||
=================== | ||
* Release v0.7.0 | ||
* support compile .tsx to .js | ||
@@ -6,0 +20,0 @@ * upgrade ci config. |
"use strict"; | ||
/// <reference types="@fibjs/types" /> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loader = exports.generateLoaderbox = exports.loaderBox = exports.compileDirectoryTo = exports.compileFileToSandBox = exports.compileFileTo = exports.compileFile = exports.compileRawToSandBox = exports.compileRawToFile = exports.compileRaw = exports.compileModule = exports.defaultCompilerOptions = exports.registerTsCompiler = exports.builtModules = exports.createProgram = exports.createCompilerHost = exports.ChainLoader = void 0; | ||
const vm = require("vm"); | ||
@@ -5,0 +6,0 @@ const compileModule = require('../core/transpile/module').compileModule; |
{ | ||
"name": "fib-typify", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "just write fibjs with typescript : )", | ||
@@ -13,3 +13,3 @@ "main": "./lib", | ||
"scripts": { | ||
"build": "fibjs ./bin/ftsc.js src/* --outDir ./lib -p tsconfig.bootstrap.json", | ||
"build": "fibjs ./bin/ftsc.js src/* -p tsconfig.bootstrap.json --outDir ./lib", | ||
"bootstrap": "fibjs ./scripts/bootstrap", | ||
@@ -16,0 +16,0 @@ "test": "fibjs test/index.js", |
121
README.md
@@ -11,6 +11,8 @@ # fib-typify | ||
- fibjs `>= 0.26.0` | ||
- fibjs `>= 0.27.0` | ||
## Usage | ||
**Via Javascript** | ||
```javascript | ||
@@ -33,18 +35,63 @@ // entry.js | ||
## Introduction | ||
`fib-typify` allows you write fibjs with [typescript] in compilation or in runtime. It depends on original [typescript] stable version. As typescript is written with **nodejs**, it's not restricted in nodejs runtime: you can also compile typescript in browser or _ANY_ other pure Javascript runtime. That is, you can use it in fibjs also. | ||
**Via CLI** | ||
## renderer | ||
`fib-typify`'s core is [jstransformer-typescript]-like ([jstransformer-typescript] is one [jstransformer] aimed to typescript), but this core is only valid in fibjs rather than pure javascript | ||
#### `fstc` | ||
## Usage | ||
Started from `0.8.0`, you can run `ftsc`, it's command line like `tsc` from typescript, but it's for fibjs. | ||
Command above means compiling directory `src` to directory `lib` with configuration file `.typify.json`, which would be passed to `typescript.transpileModule(input, moduleOptions)` as 2nd param. | ||
```bash | ||
# compile, source directory(such as `src` above) is required | ||
./node_modules/.bin/ftsc src/* --outDir lib | ||
``` | ||
#### `fib-typify` | ||
run .ts script directly. | ||
```bash | ||
./node_modules/.bin/fib-typify ./src/index.ts | ||
``` | ||
<!-- Or compile it to same directory with corresponding filename | ||
```bash | ||
# get compiled script `./script/index.js` | ||
fib-typify ./src/index.ts -o | ||
``` --> | ||
<!-- Or compile one file to specified position | ||
```bash | ||
# get compiled script `/tmp/a.js` | ||
fib-typify ./src/index.ts -o /tmp/a.js | ||
``` --> | ||
run valid resolvable script directly. | ||
```bash | ||
## which would try to run `./index.ts`, main script in `package.json`, './index.js', './index.json'... | ||
fib-typify ./ | ||
## run `./src/index.js`, `./src/index.ts`, ... | ||
fib-typify ./src | ||
``` | ||
I only provided simple and crude error exception mechanism, so in some cases the error emitted may be not friendly as you like, it's welcome to take PR to help optimizting this part of `fib-typify` :) | ||
**options** | ||
`-c, --config-file`: equals to `tsconfig.compilerOptions`, would overwrite the one from `tsconfig.json` | ||
`-o, --out`: (fallback to file when necessary,) equals to `tsconfig.outDir`, would overwrite the one from `tsconfig.json` | ||
**Introduction** | ||
`fib-typify` allows you to write fibjs with [typescript] in compilation or in runtime. It depends on original [typescript] stable version. As typescript is written with **nodejs**, it's not restricted in nodejs runtime: you can also compile typescript in browser or _ANY_ other pure Javascript runtime. That is, you can use it in fibjs also. | ||
**Usage** | ||
```bash | ||
# locally | ||
fibjs --install fib-typify | ||
npm i -S fib-typify | ||
# or globally | ||
npm i -g fib-typify | ||
# compile code in ./src to ./dist recursively | ||
fib-typify ./src -o ./dist | ||
``` | ||
@@ -65,3 +112,3 @@ | ||
Start from `0.4.0`, `compilerOptions` from `CWD/tsconfig.json` would overwrite internal default compilerOptions. | ||
Start from `0.4.0`, `compilerOptions` from `CWD/tsconfig.json` would overwrite built-in default compilerOptions. | ||
@@ -76,3 +123,3 @@ ### priority of overwriting | ||
* `loader(moduleOptions: any, sourceMapConfig: any, sandBoxCfg?: SandBoxInitialConfig): ChainLoader` | ||
* `loader(moduleOptions: any, sandBoxCfg?: SandBoxInitialConfig): ChainLoader` | ||
@@ -159,2 +206,3 @@ generate one [ChainLoader] | ||
### require typescript directly by customized loaderBox | ||
```javascript | ||
@@ -188,51 +236,8 @@ // customized-loader.js | ||
## Warning | ||
## CLI | ||
Started from `0.2.0`, you can run `fib-typify` in CLI. | ||
### `loaderBox` Limitations when `fibjs < 0.25.0` | ||
Command above means compiling directory `src` to directory `lib` with configuration file `.typify.json`, which would be passed to `typescript.transpileModule(input, moduleOptions)` as 2nd param. | ||
**NOTE** it's not recommended to use fib-typify in fibjs <= 0.26.x. | ||
```bash | ||
# compile, source directory(such as `src` above) is required | ||
fib-typify src -o lib -c .typify.json | ||
``` | ||
(**Started From 0.5.1**) run .ts script directly. | ||
```bash | ||
fib-typify ./src/index.ts | ||
``` | ||
(**Started From 0.5.1**) or compile it to same directory with corresponding filename | ||
```bash | ||
# get compiled script `./script/index.js` | ||
fib-typify ./src/index.ts -o | ||
``` | ||
(**Started From 0.5.1**) or compile one file to specified position | ||
```bash | ||
# get compiled script `/tmp/a.js` | ||
fib-typify ./src/index.ts -o /tmp/a.js | ||
``` | ||
(**Started From 0.5.1**) run valid resovable script directly. | ||
```bash | ||
## which would try to run `./index.ts`, main script in `package.json`, './index.js', './index.json'... | ||
fib-typify ./ | ||
## run `./src/index.js`, `./src/index.ts`, ... | ||
fib-typify ./src | ||
``` | ||
I only provided 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` :) | ||
### options | ||
`-c, --config-file`: equals to `tsconfig.compilerOptions`, would overwrite the one from `tsconfig.json` | ||
`-o, --out`: (fallback to file when necessary,) equals to `tsconfig.outDir`, would overwrite the one from `tsconfig.json` | ||
## Warning | ||
### `loaderBox` Limitations when `fibjs < 0.25.0` | ||
From fibjs `0.26.0`, fibjs supports `setModuleCompiler` API to customize compiler for specified extension, so we can require typescript file directly by providing compiler for `.ts` file, which provided by fib-typify's `loaderBox`. | ||
@@ -239,0 +244,0 @@ |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ ## Test Cases |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
{ | ||
"extends": "./tsconfig.dft.json" | ||
} |
@@ -0,0 +0,0 @@ /// <reference types="@fibjs/types" /> |
@@ -0,0 +0,0 @@ /// <reference types="@fibjs/types" /> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
90176
875
268
0