diff --git a/.gitignore b/.gitignore index 9279e50..9330f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ jspm_packages # Optional REPL history .node_repl_history +.idea +output.puml diff --git a/package-lock.json b/package-lock.json index 450cc8e..5ad5315 100644 --- a/package-lock.json +++ b/package-lock.json @@ -584,6 +584,12 @@ "normalize-path": "^2.1.1" } }, + "arg": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.2.tgz", + "integrity": "sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -4824,6 +4830,27 @@ } } }, + "ts-node": { + "version": "8.5.4", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.5.4.tgz", + "integrity": "sha512-izbVCRV68EasEPQ8MSIGBNK9dc/4sYJJKYA+IarMQct1RtEot6Xp0bXuClsbUSnKpg50ho+aOAx8en5c+y4OFw==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.6", + "yn": "^3.0.0" + }, + "dependencies": { + "diff": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", + "integrity": "sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==", + "dev": true + } + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", @@ -5268,6 +5295,12 @@ "camelcase": "^5.0.0", "decamelize": "^1.2.0" } + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true } } } diff --git a/package.json b/package.json index bc92d3e..2c499c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tplant", - "version": "2.3.1", + "version": "2.3.2", "description": "Typescript to PlantUML", "keywords": [ "class diagram", @@ -53,6 +53,7 @@ "jest": "^24.8.0", "pre-commit": "^1.2.2", "ts-jest": "^24.0.2", + "ts-node": "^8.5.4", "tslint": "^5.16.0", "tslint-microsoft-contrib": "^6.1.1" }, diff --git a/src/@types/plantuml-encoder/index.d.ts b/src/@types/plantuml-encoder/index.d.ts index ca7a6b4..2406ac7 100644 --- a/src/@types/plantuml-encoder/index.d.ts +++ b/src/@types/plantuml-encoder/index.d.ts @@ -2,4 +2,4 @@ declare module 'plantuml-encoder' { export function encode(text: string): string; - } \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index fcfb7dd..30b1c56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ import { tplant } from './tplant'; const AVAILABLE_PLANTUML_EXTENSIONS: string[] = ['svg', 'png', 'txt']; commander - .version('2.3.1') + .version('2.3.2') .option('-i, --input ', 'Define the path of the Typescript file') .option('-o, --output ', 'Define the path of the output file. If not defined, it\'ll output on the STDOUT') .option( @@ -64,7 +64,7 @@ G(commander.input, {}, (err: Error | null, matches: string[]): void => { } // tslint:disable-next-line non-literal-fs-path - fs.writeFileSync(commander.output, plantUMLDocument, 'binary'); + fs.writeFileSync(commander.output, plantUMLDocument, 'utf-8'); }); function findTsConfigFile(inputPath: string, tsConfigPath?: string): string | undefined { @@ -140,7 +140,7 @@ function requestImageFile(output: string, input: string, extension: string): voi }, (res: http.IncomingMessage): void => { // tslint:disable-next-line non-literal-fs-path const fileStream: fs.WriteStream = fs.createWriteStream(output); - res.setEncoding('binary'); + res.setEncoding('utf-8'); res.pipe(fileStream); res.on('error', (err: Error): void => { throw err; diff --git a/test/CJK/CJK.ts b/test/CJK/CJK.ts new file mode 100644 index 0000000..3182740 --- /dev/null +++ b/test/CJK/CJK.ts @@ -0,0 +1,10 @@ +namespace CJK { + /** + * ChineseCharacters + * + * Some classes might contains some Chinese characters + */ + class ChineseCharacters { + public 你好: string = ''; + } +} diff --git a/test/cjk.test.ts b/test/cjk.test.ts new file mode 100644 index 0000000..cfc4b01 --- /dev/null +++ b/test/cjk.test.ts @@ -0,0 +1,29 @@ +import {exec} from 'child_process'; +import * as fs from 'fs'; +import * as os from 'os'; +import DoneCallback = jest.DoneCallback; + +jest.setTimeout(10000); + +describe('Parse codes that contains CJK characters', () => { + + it('generate PlantUML for classes that contains CJK characters', (done: DoneCallback) => { + // tslint:disable-next-line:max-line-length + exec('ts-node --project ./tsconfig.json ./src/index.ts -i ./test/CJK/CJK.ts --output ./output.puml', () => { + const fileContent: string = fs.readFileSync('./output.puml', 'utf-8'); + + expect(fileContent) + .toEqual( + ['@startuml', + 'namespace CJK {', + ' class ChineseCharacters {', + ' +你好: string', + ' }', + '}', + '@enduml'].join(os.EOL) + ); + + done(); + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index d13a376..0354191 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -38,7 +38,7 @@ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ + "typeRoots": ["./node_modules/@types", "./src/@types"], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ @@ -60,4 +60,4 @@ "sample", "node_modules" ] -} \ No newline at end of file +}