ts-creator
Advanced tools
Comparing version 1.1.10 to 1.2.0-173bb449
@@ -1,6 +0,12 @@ | ||
/// <reference path="../../../types/prettier.d.ts" /> | ||
import * as prettier from 'prettier/standalone'; | ||
export declare enum CreatorTarget { | ||
expression = "expression", | ||
runnable = "runnable", | ||
esmodule = "esmodule" | ||
} | ||
export interface Options { | ||
prettierOptions?: Options; | ||
prettierOptions?: prettier.Options; | ||
target?: CreatorTarget; | ||
} | ||
export default function create(code: string, options?: Options): string; | ||
export { transformNode, transformSourceFile } from './transformer'; |
{ | ||
"name": "ts-creator", | ||
"version": "1.1.10", | ||
"version": "1.2.0-173bb449", | ||
"description": "A code generator to generate TypeScript code generator from TypeScript code", | ||
"main": "dist/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"types": "dist/types/src/index.d.ts", | ||
"scripts": { | ||
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js", | ||
"dev": "webpack --config webpack.config.js", | ||
"test": "webpack --config webpack.test.config.js && node ./dist/tests/index.js", | ||
"lint": "prettier --config ./prettier.json --list-different ./src/**/* ./tests/**/*", | ||
"prettier": "prettier --config ./prettier.json --write ./src/**/* ./tests/**/*" | ||
"build": "cross-env NODE_OPTIONS=--max_old_space_size=4096 NODE_ENV=production webpack --config webpack.config.js", | ||
"dev": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.config.js -w", | ||
"test": "cross-env NODE_OPTIONS=--max_old_space_size=4096 gulp --gulpfile gulpfile.test.js", | ||
"lint": "prettier --config ./prettier.json --list-different ./types/**/* ./src/**/* ./tests/**/* ./gulpfile.test.js ./webpack.config.js ./update-next.js", | ||
"prettier": "prettier --config ./prettier.json --write ./types/**/* ./src/**/* ./tests/**/* ./gulpfile.test.js ./webpack.config.js ./update-next.js", | ||
"coverage": "cross-env NODE_OPTIONS=--max_old_space_size=4096 nyc gulp --gulpfile ./gulpfile.test.js coverage" | ||
}, | ||
@@ -17,8 +18,15 @@ "author": "kingwl", | ||
"dependencies": { | ||
"prettier": "^1.15.3", | ||
"typescript": "^3.2.2" | ||
"cardinal": "^2.1.1", | ||
"get-stdin": "^6.0.0", | ||
"prettier": "^1.16.0", | ||
"typescript": "^3.2.2", | ||
"yargs": "^12.0.5" | ||
}, | ||
"bin": { | ||
"ts-creator": "bin/ts-creator" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"bin", | ||
"LICENSE", | ||
@@ -30,10 +38,46 @@ "tsconfig.json", | ||
"devDependencies": { | ||
"@types/get-stdin": "^5.0.1", | ||
"@types/gulp": "^4.0.5", | ||
"@types/gulp-typescript": "^2.13.0", | ||
"@types/memory-fs": "^0.3.2", | ||
"@types/node": "^10.12.18", | ||
"@types/prettier": "^1.15.2", | ||
"@types/webpack-merge": "^4.1.3", | ||
"@types/webpack-stream": "^3.2.10", | ||
"@types/yargs": "^12.0.6", | ||
"cross-env": "^5.2.0", | ||
"codecov": "^3.1.0", | ||
"del": "^3.0.0", | ||
"gulp": "^4.0.0", | ||
"gulp-typescript": "^5.0.0", | ||
"gulp-uglify": "^3.0.1", | ||
"gulp-uglify-es": "^1.0.4", | ||
"istanbul-instrumenter-loader": "^3.0.1", | ||
"memory-fs": "^0.4.1", | ||
"nyc": "^13.2.0", | ||
"require-from-string": "^2.0.2", | ||
"through2": "^3.0.0", | ||
"ts-loader": "^5.3.3", | ||
"uglify-es": "^3.3.9", | ||
"webpack": "^4.28.4", | ||
"webpack-cli": "^3.2.1", | ||
"webpack-merge": "^4.2.1" | ||
"webpack-merge": "^4.2.1", | ||
"webpack-stream": "^5.2.1" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
], | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"**/*.d.ts" | ||
], | ||
"reporter": [ | ||
"text", | ||
"lcov" | ||
], | ||
"all": true | ||
} | ||
} | ||
} |
@@ -1,15 +0,21 @@ | ||
# ts-creator | ||
<div align="center"> | ||
<img width="520" src="./media/Logo.svg"> | ||
# ts-creator | ||
A code generator to generate TypeScript code generator from TypeScript code | ||
A code generator to generate TypeScript code generator from TypeScript code | ||
[![Build Status](https://travis-ci.com/HearTao/ts-creator.svg?branch=master)](https://travis-ci.com/HearTao/ts-creator) [![NPM version](https://img.shields.io/npm/v/ts-creator.svg)](https://www.npmjs.com/package/ts-creator) [![codecov](https://codecov.io/gh/HearTao/ts-creator/branch/master/graph/badge.svg)](https://codecov.io/gh/HearTao/ts-creator) | ||
[![Build Status](https://travis-ci.com/HearTao/ts-creator.svg?branch=master)](https://travis-ci.com/HearTao/ts-creator) [![NPM version](https://img.shields.io/npm/v/ts-creator.svg)](https://www.npmjs.com/package/ts-creator) | ||
👉 [Try It!](https://ts-creator.js.org/) 👈 | ||
</div> | ||
[Try It!](https://ts-creator.js.org/) | ||
## How to use it: | ||
``` | ||
```shell | ||
npm install ts-creator | ||
``` | ||
### 1. generate from code | ||
@@ -98,4 +104,60 @@ | ||
## Cli usage | ||
Use `ts-creator` cli to generate code: | ||
```sh | ||
ts-creator <input> [options] | ||
``` | ||
Simple usage: | ||
```sh | ||
# print generate code | ||
ts-creator foo.ts | ||
# or read data from pipeline | ||
echo 42 | ts-creator | ||
cat foo.ts | ts-creator | ||
ts-creator < foo.ts | ||
# write to file | ||
ts-creator foo.ts -o foo.js | ||
ts-creator foo.ts > foo.js | ||
``` | ||
### Installation | ||
You can install `ts-creator` globally. | ||
```sh | ||
npm i -g ts-creator | ||
# or yarn | ||
yarn global add ts-creator | ||
``` | ||
If you install locally, may prepend `npx` or `yarn` you need. | ||
```sh | ||
# use npm | ||
npm i ts-creator | ||
npx ts-creator -h | ||
# use yarn | ||
yarn add ts-creator | ||
yarn ts-creator -h | ||
``` | ||
### Cli options | ||
| option | description | type | default | | ||
|---|---|---|---| | ||
| --color | colorful print | boolean | false | | ||
| --output, -o | output to filepath | string | undefined | | ||
| --version, -v | show ts-creator version | boolean | false | | ||
| --help, -h | show help | boolean | false | | ||
## TODO: | ||
- [ ] JSDoc |
@@ -43,5 +43,11 @@ import { formatFlags } from './utils' | ||
// NodeFlags.PossiblyContainsDynamicImport, NodeFlags.PossiblyContainsImportMeta, NodeFlags.Ambient, NodeFlags.InWithStatement | ||
const internalFlags: number = 1 << 19 | 1 << 20 | 1 << 22 | 1 << 23 | ||
function filterInternalFlags (flags: NodeFlags): NodeFlags { | ||
return flags &= ~internalFlags | ||
} | ||
/** @internal */ | ||
export function createNodeFlags(flags: NodeFlags) { | ||
const formattedFlags = formatFlags(flags, NodeFlags).map(f => | ||
const formattedFlags = formatFlags(filterInternalFlags(flags), NodeFlags).map(f => | ||
createPropertyAccess( | ||
@@ -52,3 +58,3 @@ createTsAccess(createIdentifier('NodeFlags')), | ||
) | ||
return connectBinary(SyntaxKind.BarBarToken, formattedFlags) | ||
return connectBinary(SyntaxKind.BarToken, formattedFlags) | ||
} | ||
@@ -55,0 +61,0 @@ |
@@ -1,18 +0,28 @@ | ||
///<reference path="../types/prettier.d.ts"/> | ||
import { transformSourceFile, transformNode } from './transformer' | ||
import { | ||
createPrinter, | ||
createSourceFile, | ||
ScriptTarget, | ||
SourceFile | ||
} from 'typescript' | ||
import { transformSourceFile } from './transformer' | ||
import { isDef } from './utils' | ||
import { Options as PrettierOptions, format } from 'prettier' | ||
import { createPrinter, createSourceFile, ScriptTarget } from 'typescript' | ||
import * as prettier from 'prettier/standalone' | ||
import tsPlugin from 'prettier/parser-typescript' | ||
import { resolveRunnable } from './wrapper/runnable' | ||
import { resolveESModule } from './wrapper/esmodule' | ||
// if standalone, that is external module, otherwise undefined | ||
import tsPlugin from 'prettier-typescript-plugins' | ||
export enum CreatorTarget { | ||
expression = 'expression', | ||
runnable = 'runnable', | ||
esmodule = 'esmodule' | ||
} | ||
export interface Options { | ||
prettierOptions?: Options | ||
prettierOptions?: prettier.Options | ||
target?: CreatorTarget | ||
} | ||
const defaultPrettierOptions: PrettierOptions = { | ||
const defaultPrettierOptions: prettier.Options = { | ||
parser: 'typescript', | ||
plugins: [tsPlugin].filter(isDef), | ||
plugins: [tsPlugin], | ||
semi: false, | ||
@@ -28,6 +38,30 @@ singleQuote: true, | ||
function transformRunable(file: SourceFile): SourceFile { | ||
return resolveRunnable(transformNode(file)) | ||
} | ||
function transformExpression(file: SourceFile): SourceFile { | ||
return transformSourceFile(file) | ||
} | ||
function transformESModule(file: SourceFile): SourceFile { | ||
return resolveESModule(transformNode(file)) | ||
} | ||
function transformTarget(file: SourceFile, options: Options): SourceFile { | ||
switch (options.target) { | ||
case CreatorTarget.runnable: | ||
return transformRunable(file) | ||
case CreatorTarget.esmodule: | ||
return transformESModule(file) | ||
default: | ||
return transformExpression(file) | ||
} | ||
} | ||
export default function create(code: string, options: Options = {}): string { | ||
const printer = createPrinter() | ||
const file = createSourceFile('templory.ts', code, ScriptTarget.Latest) | ||
const factoryFile = transformSourceFile(file) | ||
const factoryFile = transformTarget(file, options) | ||
const factoryCode = printer.printFile(factoryFile) | ||
@@ -39,5 +73,5 @@ | ||
} | ||
return format(factoryCode, prettierOptions) | ||
return prettier.format(factoryCode, prettierOptions) | ||
} | ||
export { transformNode, transformSourceFile } from './transformer' |
@@ -8,2 +8,3 @@ { | ||
"target": "es5", | ||
"lib": ["es2015"], | ||
"declaration": true, | ||
@@ -10,0 +11,0 @@ "outDir": "./dist", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
27
163
10187602
5
27
1
3950
4
3
2
+ Addedcardinal@^2.1.1
+ Addedget-stdin@^6.0.0
+ Addedyargs@^12.0.5
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedansicolors@0.3.2(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcardinal@2.1.1(transitive)
+ Addedcliui@4.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcross-spawn@6.0.6(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedfind-up@3.0.0(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-stdin@6.0.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedinvert-kv@2.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlcid@2.0.0(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-locale@3.1.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedredeyed@2.1.1(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@3.0.14.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@12.0.5(transitive)
+ Addedyargs-parser@11.1.1(transitive)
Updatedprettier@^1.16.0