-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import glob from 'fast-glob' | ||
|
||
import { Platforms, platforms } from '../core/platforms' | ||
import { getPlatformFromFilePath } from './utils' | ||
|
||
export async function loadSources(path: string[], platform: Platforms): Promise<string[]> { | ||
const levels = platforms.get(platform) | ||
|
||
if (levels === undefined) { | ||
throw new Error(`Unexpected platform: ${platform}, please check configuration.`) | ||
} | ||
|
||
const files = await glob(path) | ||
|
||
const result = files | ||
.filter((file) => { | ||
const filePlatform = getPlatformFromFilePath(file) | ||
return levels.includes(filePlatform as Platforms) | ||
}) | ||
.sort((a, b) => { | ||
const a1 = getPlatformFromFilePath(a) | ||
const b1 = getPlatformFromFilePath(b) | ||
return levels.indexOf(a1) - levels.indexOf(b1) | ||
}) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { Platforms } from '../core/platforms' | ||
|
||
export function getFolderWithPlatform(fileName: string): string { | ||
const [name, platform] = fileName.split('@') | ||
if (platform === undefined) { | ||
return name | ||
} | ||
return `${name}/${platform}` | ||
} | ||
|
||
export function getPlatformFromFilePath(filePath: string): Platforms { | ||
const matched = filePath.match(/@([\w|-]+)+\./) | ||
return matched === null ? 'common' : (matched[1] as Platforms) | ||
} |