Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Store): environment path when generating a new store #1071

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 42 additions & 31 deletions modules/effects/schematics-core/utility/find-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path, join, normalize, relative, strings } from '@angular-devkit/core';
import {
Path,
join,
normalize,
relative,
strings,
basename,
extname,
dirname,
} from '@angular-devkit/core';
import { DirEntry, Tree } from '@angular-devkit/schematics';

export interface ModuleOptions {
Expand Down Expand Up @@ -89,38 +98,40 @@ export function findModule(host: Tree, generateDir: string): Path {
* Build a relative path from one file path to another file path.
*/
export function buildRelativePath(from: string, to: string): string {
from = normalize(from);
to = normalize(to);

// Convert to arrays.
const fromParts = from.split('/');
const toParts = to.split('/');

// Remove file names (preserving destination)
fromParts.pop();
const toFileName = convertToTypeScriptFileName(toParts.pop());

const relativePath = relative(
normalize(fromParts.join('/')),
normalize(toParts.join('/'))
);
let pathPrefix = '';

// Set the path prefix for same dir or child dir, parent dir starts with `..`
if (!relativePath) {
pathPrefix = '.';
} else if (!relativePath.startsWith('.')) {
pathPrefix = `./`;
}
if (pathPrefix && !pathPrefix.endsWith('/')) {
pathPrefix += '/';
}

return toFileName
? pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName
: pathPrefix + relativePath;
const {
path: fromPath,
filename: fromFileName,
directory: fromDirectory,
} = parsePath(from);
const {
path: toPath,
filename: toFileName,
directory: toDirectory,
} = parsePath(to);
const relativePath = relative(fromDirectory, toDirectory);
const fixedRelativePath = relativePath.startsWith('.')
? relativePath
: `./${relativePath}`;

return !toFileName || toFileName === 'index.ts'
? fixedRelativePath
: `${
fixedRelativePath.endsWith('/')
? fixedRelativePath
: fixedRelativePath + '/'
}${convertToTypeScriptFileName(toFileName)}`;
}

function parsePath(path: string) {
const pathNormalized = normalize(path) as Path;
const filename = extname(pathNormalized) ? basename(pathNormalized) : '';
const directory = filename ? dirname(pathNormalized) : pathNormalized;
return {
path: pathNormalized,
filename,
directory,
};
}
/**
* Strips the typescript extension and clears index filenames
* foo.ts -> foo
Expand Down
73 changes: 42 additions & 31 deletions modules/entity/schematics-core/utility/find-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path, join, normalize, relative, strings } from '@angular-devkit/core';
import {
Path,
join,
normalize,
relative,
strings,
basename,
extname,
dirname,
} from '@angular-devkit/core';
import { DirEntry, Tree } from '@angular-devkit/schematics';

export interface ModuleOptions {
Expand Down Expand Up @@ -89,38 +98,40 @@ export function findModule(host: Tree, generateDir: string): Path {
* Build a relative path from one file path to another file path.
*/
export function buildRelativePath(from: string, to: string): string {
from = normalize(from);
to = normalize(to);

// Convert to arrays.
const fromParts = from.split('/');
const toParts = to.split('/');

// Remove file names (preserving destination)
fromParts.pop();
const toFileName = convertToTypeScriptFileName(toParts.pop());

const relativePath = relative(
normalize(fromParts.join('/')),
normalize(toParts.join('/'))
);
let pathPrefix = '';

// Set the path prefix for same dir or child dir, parent dir starts with `..`
if (!relativePath) {
pathPrefix = '.';
} else if (!relativePath.startsWith('.')) {
pathPrefix = `./`;
}
if (pathPrefix && !pathPrefix.endsWith('/')) {
pathPrefix += '/';
}

return toFileName
? pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName
: pathPrefix + relativePath;
const {
path: fromPath,
filename: fromFileName,
directory: fromDirectory,
} = parsePath(from);
const {
path: toPath,
filename: toFileName,
directory: toDirectory,
} = parsePath(to);
const relativePath = relative(fromDirectory, toDirectory);
const fixedRelativePath = relativePath.startsWith('.')
? relativePath
: `./${relativePath}`;

return !toFileName || toFileName === 'index.ts'
? fixedRelativePath
: `${
fixedRelativePath.endsWith('/')
? fixedRelativePath
: fixedRelativePath + '/'
}${convertToTypeScriptFileName(toFileName)}`;
}

function parsePath(path: string) {
const pathNormalized = normalize(path) as Path;
const filename = extname(pathNormalized) ? basename(pathNormalized) : '';
const directory = filename ? dirname(pathNormalized) : pathNormalized;
return {
path: pathNormalized,
filename,
directory,
};
}
/**
* Strips the typescript extension and clears index filenames
* foo.ts -> foo
Expand Down
73 changes: 42 additions & 31 deletions modules/router-store/schematics-core/utility/find-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path, join, normalize, relative, strings } from '@angular-devkit/core';
import {
Path,
join,
normalize,
relative,
strings,
basename,
extname,
dirname,
} from '@angular-devkit/core';
import { DirEntry, Tree } from '@angular-devkit/schematics';

export interface ModuleOptions {
Expand Down Expand Up @@ -89,38 +98,40 @@ export function findModule(host: Tree, generateDir: string): Path {
* Build a relative path from one file path to another file path.
*/
export function buildRelativePath(from: string, to: string): string {
from = normalize(from);
to = normalize(to);

// Convert to arrays.
const fromParts = from.split('/');
const toParts = to.split('/');

// Remove file names (preserving destination)
fromParts.pop();
const toFileName = convertToTypeScriptFileName(toParts.pop());

const relativePath = relative(
normalize(fromParts.join('/')),
normalize(toParts.join('/'))
);
let pathPrefix = '';

// Set the path prefix for same dir or child dir, parent dir starts with `..`
if (!relativePath) {
pathPrefix = '.';
} else if (!relativePath.startsWith('.')) {
pathPrefix = `./`;
}
if (pathPrefix && !pathPrefix.endsWith('/')) {
pathPrefix += '/';
}

return toFileName
? pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName
: pathPrefix + relativePath;
const {
path: fromPath,
filename: fromFileName,
directory: fromDirectory,
} = parsePath(from);
const {
path: toPath,
filename: toFileName,
directory: toDirectory,
} = parsePath(to);
const relativePath = relative(fromDirectory, toDirectory);
const fixedRelativePath = relativePath.startsWith('.')
? relativePath
: `./${relativePath}`;

return !toFileName || toFileName === 'index.ts'
? fixedRelativePath
: `${
fixedRelativePath.endsWith('/')
? fixedRelativePath
: fixedRelativePath + '/'
}${convertToTypeScriptFileName(toFileName)}`;
}

function parsePath(path: string) {
const pathNormalized = normalize(path) as Path;
const filename = extname(pathNormalized) ? basename(pathNormalized) : '';
const directory = filename ? dirname(pathNormalized) : pathNormalized;
return {
path: pathNormalized,
filename,
directory,
};
}
/**
* Strips the typescript extension and clears index filenames
* foo.ts -> foo
Expand Down
73 changes: 42 additions & 31 deletions modules/schematics-core/utility/find-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path, join, normalize, relative, strings } from '@angular-devkit/core';
import {
Path,
join,
normalize,
relative,
strings,
basename,
extname,
dirname,
} from '@angular-devkit/core';
import { DirEntry, Tree } from '@angular-devkit/schematics';

export interface ModuleOptions {
Expand Down Expand Up @@ -89,38 +98,40 @@ export function findModule(host: Tree, generateDir: string): Path {
* Build a relative path from one file path to another file path.
*/
export function buildRelativePath(from: string, to: string): string {
from = normalize(from);
to = normalize(to);

// Convert to arrays.
const fromParts = from.split('/');
const toParts = to.split('/');

// Remove file names (preserving destination)
fromParts.pop();
const toFileName = convertToTypeScriptFileName(toParts.pop());

const relativePath = relative(
normalize(fromParts.join('/')),
normalize(toParts.join('/'))
);
let pathPrefix = '';

// Set the path prefix for same dir or child dir, parent dir starts with `..`
if (!relativePath) {
pathPrefix = '.';
} else if (!relativePath.startsWith('.')) {
pathPrefix = `./`;
}
if (pathPrefix && !pathPrefix.endsWith('/')) {
pathPrefix += '/';
}

return toFileName
? pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName
: pathPrefix + relativePath;
const {
path: fromPath,
filename: fromFileName,
directory: fromDirectory,
} = parsePath(from);
const {
path: toPath,
filename: toFileName,
directory: toDirectory,
} = parsePath(to);
const relativePath = relative(fromDirectory, toDirectory);
const fixedRelativePath = relativePath.startsWith('.')
? relativePath
: `./${relativePath}`;

return !toFileName || toFileName === 'index.ts'
? fixedRelativePath
: `${
fixedRelativePath.endsWith('/')
? fixedRelativePath
: fixedRelativePath + '/'
}${convertToTypeScriptFileName(toFileName)}`;
}

function parsePath(path: string) {
const pathNormalized = normalize(path) as Path;
const filename = extname(pathNormalized) ? basename(pathNormalized) : '';
const directory = filename ? dirname(pathNormalized) : pathNormalized;
return {
path: pathNormalized,
filename,
directory,
};
}
/**
* Strips the typescript extension and clears index filenames
* foo.ts -> foo
Expand Down
Loading