Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: allow custom eol characters
Browse files Browse the repository at this point in the history
Closes #609
  • Loading branch information
KnisterPeter committed Aug 16, 2018
1 parent bb84cc9 commit 3e41b31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as babylon from 'babylon';
import * as fs from 'fs';
import * as getStdin from 'get-stdin';

import { generateTypings } from './deprecated';
import { Generator } from './generator';
import { createTypings } from './typings';
Expand Down Expand Up @@ -47,6 +46,15 @@ export interface Options {
* @memberOf Options
*/
filename?: string;

/**
* EOL character. This would be changed to whatever is liked to
* terminate lines. Defaults to '\r\n'
*
* @type {string}
* @memberOf Options
*/
eol?: string;
}

export function cli(options: any): void {
Expand Down
6 changes: 5 additions & 1 deletion src/typings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as ASTQ from 'astq';
import * as dom from 'dts-dom';
import pascalCase = require('pascal-case');
import { InstanceOfResolver, IOptions } from './index';
import * as types from './types';

import pascalCase = require('pascal-case');

export interface AstQuery {
ast: any;
query(query: string): any[];
Expand All @@ -22,6 +23,9 @@ export interface ImportedPropTypes {

export function createTypings(moduleName: string|null, programAst: any, options: IOptions,
reactImport: string): string {
// #609: configure eol character
dom.config.outputEol = options.eol || '\r\n';

const astq = new ASTQ();
const ast = {
ast: programAst,
Expand Down
9 changes: 7 additions & 2 deletions tests/parsing-test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// tslint:disable:no-implicit-dependencies
import test, { TestContext } from 'ava';

import chalk from 'chalk';
import * as diff from 'diff';
import * as fs from 'fs';
import * as path from 'path';

import * as react2dts from '../src/index';

let basedir = path.join(__dirname, '..', '..', 'tests');
Expand Down Expand Up @@ -118,3 +116,10 @@ test('Parsing should support an SFC with default export babeled to es6', t => {
test('Parsing should suppport components that extend PureComponent', t => {
compare(t, 'component', 'pure-component.jsx', 'pure-component.d.ts');
});
test('Parsing should suppport custom eol style', t => {
textDiff(
t,
react2dts.generateFromFile('component', path.join(basedir, 'pure-component.jsx'), {eol: '\n'}, 'react'),
fs.readFileSync(path.join(basedir, 'pure-component.d.ts')).toString().replace('\r\n', '\n')
);
});

0 comments on commit 3e41b31

Please sign in to comment.