Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit d778857

Browse files
authored
fix(generators): import paths correct on windows
* fix(generators): import paths correct on windows * fix(generators): import paths correct on windows * chore(generators): use Path.sep to ensure paths are always correct
1 parent aaa9d3c commit d778857

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/generators/util.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { basename, dirname, join, relative } from 'path';
1+
import { basename, dirname, join, relative, sep } from 'path';
22
import { readdirSync } from 'fs';
33
import { Logger} from '../logger/logger';
4+
import { toUnixPath } from '../util/helpers';
45

56
import * as Constants from '../util/constants';
67
import * as GeneratorConstants from './constants';
@@ -157,7 +158,9 @@ export function nonPageFileManipulation(context: BuildContext, name: string, ngM
157158
fileContent = content;
158159
return generateTemplates(context, hydratedRequest);
159160
}).then(() => {
160-
fileContent = insertNamedImportIfNeeded(ngModulePath, fileContent, hydratedRequest.className, `${relative(dirname(ngModulePath), hydratedRequest.dirToWrite)}/${hydratedRequest.fileName}`);
161+
const importPath = toUnixPath(`${relative(dirname(ngModulePath), hydratedRequest.dirToWrite)}${sep}${hydratedRequest.fileName}`);
162+
163+
fileContent = insertNamedImportIfNeeded(ngModulePath, fileContent, hydratedRequest.className, importPath);
161164
if (type === 'provider') {
162165
fileContent = appendNgModuleDeclaration(ngModulePath, fileContent, hydratedRequest.className, type);
163166
} else {
@@ -171,11 +174,12 @@ export function tabsModuleManipulation(tabs: string[][], hydratedRequest: Hydrat
171174
const ngModulePath = tabs[0].find((element: any): boolean => {
172175
return element.indexOf('module') !== -1;
173176
});
174-
const tabsNgModulePath = `${hydratedRequest.dirToWrite}/${hydratedRequest.fileName}.module.ts`;
177+
const tabsNgModulePath = `${hydratedRequest.dirToWrite}${sep}${hydratedRequest.fileName}.module.ts`;
178+
const importPath = toUnixPath(relative(dirname(tabsNgModulePath), ngModulePath.replace('.module.ts', '')));
175179

176180
return readFileAsync(tabsNgModulePath).then((content) => {
177181
let fileContent = content;
178-
fileContent = insertNamedImportIfNeeded(tabsNgModulePath, fileContent, tabHydratedRequests[0].className, relative(dirname(tabsNgModulePath), ngModulePath.replace('.module.ts', '')));
182+
fileContent = insertNamedImportIfNeeded(tabsNgModulePath, fileContent, tabHydratedRequests[0].className, importPath);
179183
fileContent = appendNgModuleDeclaration(tabsNgModulePath, fileContent, tabHydratedRequests[0].className);
180184

181185
return writeFileAsync(tabsNgModulePath, fileContent);

0 commit comments

Comments
 (0)