Skip to content

Commit

Permalink
fix: namespace shoud not start with number
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Apr 26, 2019
1 parent 88327d8 commit 31083f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
27 changes: 8 additions & 19 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
"license": "MIT",
"dependencies": {
"fs-extra": "^7.0.1",
"hash-sum": "^1.0.2",
"lodash": "^4.17.11",
"ts-morph": "^1.3.3",
"ts-morph": "^2.0.1",
"typescript": "^3.4.3",
"yargs": "^13.2.2"
},
Expand Down
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import fs from 'fs-extra';
import path from 'path';
import * as ts from 'typescript';
import hash from 'hash-sum';
import {Project} from 'ts-morph';
import {upperFirst} from 'lodash';

import * as emitter from './emitter';
import {CompilerState} from './types';
Expand All @@ -34,6 +34,14 @@ const defaultOptions = {
customTransformers: []
};

const getRandomString = n => Array(n)
.join()
.split(',')
.map(function() {
return s.charAt(Math.floor(Math.random() * s.length));
}).join('');


export function compile(filePath: string, options: Ts2phpOptions = {}) {

const project = new Project({
Expand Down Expand Up @@ -99,7 +107,7 @@ export function compile(filePath: string, options: Ts2phpOptions = {}) {
moduleDefaultImports: {},
namespace: (options && options.namespace)
|| (options && options.getNamespace && options.getNamespace())
|| hash(filePath),
|| upperFirst(getRandomString(5)),
plugins
});

Expand Down

0 comments on commit 31083f4

Please sign in to comment.