Skip to content

Commit

Permalink
Merge pull request #45 from Jeff-Tian/fix/utf-8
Browse files Browse the repository at this point in the history
feat: save file with utf-8 encoding to support CJK characters
  • Loading branch information
bafolts authored Dec 7, 2019
2 parents 9462ed4 + 50c7c3b commit f1e49e2
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ jspm_packages

# Optional REPL history
.node_repl_history
.idea
output.puml
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tplant",
"version": "2.3.1",
"version": "2.3.2",
"description": "Typescript to PlantUML",
"keywords": [
"class diagram",
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/@types/plantuml-encoder/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

declare module 'plantuml-encoder' {
export function encode(text: string): string;
}
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>', 'Define the path of the Typescript file')
.option('-o, --output <path>', 'Define the path of the output file. If not defined, it\'ll output on the STDOUT')
.option(
Expand Down Expand Up @@ -64,7 +64,7 @@ G(<string>commander.input, {}, (err: Error | null, matches: string[]): void => {
}

// tslint:disable-next-line non-literal-fs-path
fs.writeFileSync(<string>commander.output, plantUMLDocument, 'binary');
fs.writeFileSync(<string>commander.output, plantUMLDocument, 'utf-8');
});

function findTsConfigFile(inputPath: string, tsConfigPath?: string): string | undefined {
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions test/CJK/CJK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CJK {
/**
* ChineseCharacters
*
* Some classes might contains some Chinese characters
*/
class ChineseCharacters {
public 你好: string = '';
}
}
29 changes: 29 additions & 0 deletions test/cjk.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'. */
Expand All @@ -60,4 +60,4 @@
"sample",
"node_modules"
]
}
}

0 comments on commit f1e49e2

Please sign in to comment.