|
5 | 5 | * This script reads all the api files and generate the |
6 | 6 | * needed ioc targets file. |
7 | 7 | */ |
| 8 | +import * as path from 'path'; |
8 | 9 | import * as _ from 'lodash'; |
9 | 10 | import * as glob from 'glob'; |
10 | 11 | import * as handlebars from 'handlebars'; |
@@ -40,40 +41,40 @@ export class UpdateTargetsCommand extends AbstractCommand { |
40 | 41 | return json.replace(/\"([^(\")"]+)\":/g, '$1:').replace(/"/g, '\''); |
41 | 42 | }); |
42 | 43 |
|
43 | | - const path = __dirname.replace('console', 'constants') + `/${this.targetFile}`; |
44 | | - await existsFile(path, true); |
45 | | - await writeTemplate(this.template, path, context); |
| 44 | + const filepath = path.join(__dirname.replace('console', 'constants'), this.targetFile); |
| 45 | + await existsFile(filepath, true); |
| 46 | + await writeTemplate(this.template, filepath, context); |
46 | 47 |
|
47 | 48 | } |
48 | 49 |
|
49 | 50 | private async getFiles(): Promise<string[]> { |
50 | 51 | return new Promise<string[]>((resolve, reject) => { |
51 | | - const path = __dirname.replace('console', 'api'); |
52 | | - glob(`${path}/**/*.ts`, (err: any, files: string[]) => { |
| 52 | + const filepath = path.normalize(__dirname.replace('console', 'api')); |
| 53 | + glob(`${path.join(filepath, '**', '*.ts')}`, (err: any, files: string[]) => { |
53 | 54 | if (err) { |
54 | 55 | return reject(err); |
55 | 56 | } |
56 | 57 | files = files |
57 | | - .map((f) => f.replace(path + '/', '')) |
| 58 | + .map(f => path.normalize(f)) |
| 59 | + .map((f) => f.replace(filepath + path.sep, '')) |
58 | 60 | .map((f) => f.replace('.ts', '')); |
59 | | - |
60 | 61 | resolve(files); |
61 | 62 | }); |
62 | 63 | }); |
63 | 64 | } |
64 | 65 |
|
65 | 66 | private divideFilePath(filePath: string): any { |
66 | | - const fs = filePath.split('/'); |
| 67 | + const fs = filePath.split(path.sep); |
67 | 68 | const key = fs[0]; |
68 | 69 | fs.splice(0, 1); |
69 | 70 | return { |
70 | 71 | key, |
71 | | - path: fs.join('/') |
| 72 | + path: fs.join(path.sep) |
72 | 73 | }; |
73 | 74 | } |
74 | 75 |
|
75 | 76 | private parseFilePath(filePath: string): any { |
76 | | - if (filePath.indexOf('/') !== -1) { |
| 77 | + if (filePath.indexOf(path.sep) !== -1) { |
77 | 78 | const obj = this.divideFilePath(filePath); |
78 | 79 | return { |
79 | 80 | [obj.key]: this.parseFilePath(obj.path) |
|
0 commit comments