Skip to content

Commit 4992e99

Browse files
authored
Merge pull request #11 from Tyderion/bugfix/update-targets
Fix update targets on windows
2 parents 49054aa + 9949688 commit 4992e99

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/console/UpdateTargetsCommand.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* This script reads all the api files and generate the
66
* needed ioc targets file.
77
*/
8+
import * as path from 'path';
89
import * as _ from 'lodash';
910
import * as glob from 'glob';
1011
import * as handlebars from 'handlebars';
@@ -40,40 +41,40 @@ export class UpdateTargetsCommand extends AbstractCommand {
4041
return json.replace(/\"([^(\")"]+)\":/g, '$1:').replace(/"/g, '\'');
4142
});
4243

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);
4647

4748
}
4849

4950
private async getFiles(): Promise<string[]> {
5051
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[]) => {
5354
if (err) {
5455
return reject(err);
5556
}
5657
files = files
57-
.map((f) => f.replace(path + '/', ''))
58+
.map(f => path.normalize(f))
59+
.map((f) => f.replace(filepath + path.sep, ''))
5860
.map((f) => f.replace('.ts', ''));
59-
6061
resolve(files);
6162
});
6263
});
6364
}
6465

6566
private divideFilePath(filePath: string): any {
66-
const fs = filePath.split('/');
67+
const fs = filePath.split(path.sep);
6768
const key = fs[0];
6869
fs.splice(0, 1);
6970
return {
7071
key,
71-
path: fs.join('/')
72+
path: fs.join(path.sep)
7273
};
7374
}
7475

7576
private parseFilePath(filePath: string): any {
76-
if (filePath.indexOf('/') !== -1) {
77+
if (filePath.indexOf(path.sep) !== -1) {
7778
const obj = this.divideFilePath(filePath);
7879
return {
7980
[obj.key]: this.parseFilePath(obj.path)

src/console/lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export const existsFile = async (filePath: string, stop: boolean = false, isTest
4646
fs.exists(filePath, async (exists) => {
4747

4848
if (exists) {
49-
let fileName = filePath.split('/src/')[1];
49+
let fileName = filePath.split(path.normalize('/src/'))[1];
5050
if (isTest) {
51-
fileName = filePath.split('/test/')[1];
51+
fileName = filePath.split(path.normalize('/test/'))[1];
5252
}
5353
const answer = await prompt([
5454
{
5555
type: 'confirm',
5656
name: 'override',
57-
message: `Override "${isTest ? 'test' : 'src'}/${fileName}"?`,
57+
message: `Override "${path.join(isTest ? 'test' : 'src', fileName)}"?`,
5858
default: true
5959
}
6060
]);

0 commit comments

Comments
 (0)