Skip to content

Commit

Permalink
fix(projects): fix cwd in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Aug 22, 2023
1 parent 52dafd4 commit f15472e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,39 @@ import { setupWatcher } from './watcher';
* the class of the plugin
*/
export default class ElegantRouter {
/**
* the plugin options
*/
options: ElegantRouterOption;

/**
* the page globs
*/
pageGlobs: string[] = [];

/**
* the router files
*/
files: ElegantRouterFile[] = [];

/**
* the router name path maps
*/
maps: ElegantRouterNamePathMap = new Map<string, string>();

/**
* the router name path entries
*/
entries: ElegantRouterNamePathEntry[] = [];

/**
* the router trees
*/
trees: ElegantRouterTree[] = [];

/**
* the FS watcher
*/
fsWatcher?: FSWatcher;

constructor(options: Partial<ElegantRouterOption> = {}) {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/core/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { consola } from 'consola';
import type { LogType } from 'consola';
import { lightGreen } from 'kolorist';

/**
* log the message
* @param msg the message
* @param type the log type
* @param show whether to show the log
*/
export function log(msg: string, type: LogType, show = true) {
if (!show) return;

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ export function createPluginOptions(options?: Partial<ElegantRouterOption>): Ele
...options
};

// normalize the path if it is windows
opts.cwd = opts.cwd.replace(/\\/g, '/');

return opts;
}
6 changes: 6 additions & 0 deletions packages/core/src/core/path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import path from 'node:path';

/**
* get the full path of the page glob
* @param glob the page glob
* @param pageDir the page dir
* @param cwd the process root directory
*/
export function getFullPathOfPageGlob(glob: string, pageDir: string, cwd: string) {
return path.posix.join(cwd, pageDir, glob);
}

0 comments on commit f15472e

Please sign in to comment.