-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
e4d3819
commit f642c0e
Showing
40 changed files
with
520 additions
and
374 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,3 @@ | ||
declare const _defaultCopyStaticFiles: readonly [readonly [".npmignore", "file/npmignore"], readonly [".gitignore", "file/gitignore"], readonly [".eslintignore", "file/eslintignore"], readonly [".nvmrc", "file/nvmrc"], readonly [".browserslistrc", "file/browserslistrc"], readonly ["tsconfig.json.tpl", "file/tsconfig.json.tpl", "tsconfig.json"], readonly ["test/tsconfig.json.tpl", "file/test/tsconfig.json.tpl", "test/tsconfig.json"], readonly ["tsconfig.esm.json.tpl", "file/tsconfig.esm.json.tpl", "tsconfig.esm.json"], readonly [".eslintrc.json.tpl", "file/eslintrc.json.tpl", ".eslintrc.json"], readonly ["README.md", "file/README.md"], readonly [".nycrc", "file/nycrc"], readonly [".mocharc.yml", "file/mocharc.yml"], readonly ["jest.config.js", "file/jest.config.js"], readonly [".nowignore", "file/nowignore"], readonly ["now.json.tpl", "file/now.json.tpl", "now.json"], readonly ["lerna.json.tpl", "file/lerna.json.tpl", "lerna.json"], readonly ["pnpm-workspace.yaml.tpl", "file/pnpm-workspace.yaml", "pnpm-workspace.yaml"], readonly [".npmrc.tpl", "file/npmrc", ".npmrc"], readonly ["tsdx.config.js.tpl", "file/tsdx.config.js", "tsdx.config.js"], readonly [".github/workflows/coverage.yml", "file/github/workflows/coverage.yml"]]; | ||
export declare type IStaticFilesID<T = typeof _defaultCopyStaticFiles> = T extends ({ | ||
[n: number]: [infer U, string, string?] | readonly [infer U, string, string?]; | ||
} | { | ||
readonly [n: number]: [infer U, string, string?] | readonly [infer U, string, string?]; | ||
}) ? U : never; | ||
export declare type IStaticFilesRow<K extends string> = [K, string, string?]; | ||
declare type IStaticFilesMap01<K extends string> = { | ||
[P in K]: IStaticFilesRow<P>; | ||
}; | ||
export declare type IStaticFilesMapRecord<K extends string> = { | ||
[P in K]: string; | ||
}; | ||
export declare type IStaticFilesMapArray<K extends string> = IStaticFilesMap01<K>[K][]; | ||
export declare type IStaticFiles<K extends string> = IStaticFilesMapArray<K> | IStaticFilesMapRecord<K>; | ||
export declare const defaultCopyStaticFiles: IStaticFilesMapArray<IStaticFilesID>; | ||
export interface ICopyStaticFilesOptionsBase<K extends string = string> { | ||
cwd: string; | ||
staticRoot?: string; | ||
overwrite?: boolean; | ||
} | ||
export interface ICopyStaticFilesOptions<K extends string = string> extends ICopyStaticFilesOptionsBase<K> { | ||
file_map?: IStaticFiles<K>; | ||
} | ||
export declare function parseStaticMap<K extends string>(file_map: IStaticFilesMapRecord<K>): [K | IStaticFilesID, string, string?][]; | ||
export declare function parseStaticMap<K extends string>(file_map: IStaticFilesMapArray<K>): [K | IStaticFilesID, string, string?][]; | ||
export declare function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): [K | IStaticFilesID, string, string?][]; | ||
export declare function getStaticFile<K extends string>(file_id: K, options?: Pick<ICopyStaticFilesOptions<string>, 'file_map'>): [K, string, string?]; | ||
export declare function copyStaticFiles<K extends string>(options: ICopyStaticFilesOptions<K>): [".npmignore" | ".gitignore" | ".eslintignore" | ".nvmrc" | ".browserslistrc" | "tsconfig.json.tpl" | "test/tsconfig.json.tpl" | "tsconfig.esm.json.tpl" | ".eslintrc.json.tpl" | "README.md" | ".nycrc" | ".mocharc.yml" | "jest.config.js" | ".nowignore" | "now.json.tpl" | "lerna.json.tpl" | "pnpm-workspace.yaml.tpl" | ".npmrc.tpl" | "tsdx.config.js.tpl" | ".github/workflows/coverage.yml" | K, string, string?][]; | ||
import { copyStaticFiles } from './lib/copyStaticFiles'; | ||
export { copyStaticFiles }; | ||
export default copyStaticFiles; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,181 +1,5 @@ | ||
import { | ||
existsSync, | ||
copySync, | ||
CopyOptionsSync, | ||
pathExistsSync, | ||
ensureDirSync, | ||
} from 'fs-extra'; | ||
import { resolve, dirname } from 'path'; | ||
import { copyStaticFiles } from './lib/copyStaticFiles'; | ||
|
||
const _defaultCopyStaticFiles = [ | ||
export { copyStaticFiles } | ||
|
||
['.npmignore', 'file/npmignore'], | ||
['.gitignore', 'file/gitignore'], | ||
|
||
['.eslintignore', 'file/eslintignore'], | ||
|
||
['.nvmrc', 'file/nvmrc'], | ||
['.browserslistrc', 'file/browserslistrc'], | ||
|
||
['tsconfig.json.tpl', 'file/tsconfig.json.tpl', 'tsconfig.json'], | ||
|
||
['test/tsconfig.json.tpl', 'file/test/tsconfig.json.tpl', 'test/tsconfig.json'], | ||
|
||
['tsconfig.esm.json.tpl', 'file/tsconfig.esm.json.tpl', 'tsconfig.esm.json'], | ||
|
||
['.eslintrc.json.tpl', 'file/eslintrc.json.tpl', '.eslintrc.json'], | ||
|
||
['README.md', 'file/README.md'], | ||
|
||
['.nycrc', 'file/nycrc'], | ||
|
||
['.mocharc.yml', 'file/mocharc.yml'], | ||
['jest.config.js', 'file/jest.config.js'], | ||
|
||
['.nowignore', 'file/nowignore'], | ||
|
||
['now.json.tpl', 'file/now.json.tpl', 'now.json'], | ||
|
||
['lerna.json.tpl', 'file/lerna.json.tpl', 'lerna.json'], | ||
|
||
['pnpm-workspace.yaml.tpl', 'file/pnpm-workspace.yaml', 'pnpm-workspace.yaml'], | ||
|
||
['.npmrc.tpl', 'file/npmrc', '.npmrc'], | ||
|
||
['tsdx.config.js.tpl', 'file/tsdx.config.js', 'tsdx.config.js'], | ||
|
||
['.github/workflows/coverage.yml', 'file/github/workflows/coverage.yml'], | ||
|
||
] as const; | ||
|
||
export type IStaticFilesID<T = typeof _defaultCopyStaticFiles> = | ||
T extends ({ | ||
[n: number]: [infer U, string, string?] | readonly [infer U, string, string?]; | ||
} | { | ||
readonly [n: number]: [infer U, string, string?] | readonly [infer U, string, string?]; | ||
}) | ||
? U | ||
: never | ||
; | ||
|
||
export type IStaticFilesRow<K extends string> = [K, string, string?] | ||
|
||
type IStaticFilesMap01<K extends string> = { | ||
[P in K]: IStaticFilesRow<P> | ||
} | ||
|
||
export type IStaticFilesMapRecord<K extends string> = { | ||
[P in K]: string | ||
} | ||
|
||
export type IStaticFilesMapArray<K extends string> = IStaticFilesMap01<K>[K][] | ||
|
||
export type IStaticFiles<K extends string> = IStaticFilesMapArray<K> | IStaticFilesMapRecord<K> | ||
|
||
export const defaultCopyStaticFiles: IStaticFilesMapArray<IStaticFilesID> = Object.freeze(_defaultCopyStaticFiles) as any; | ||
|
||
export interface ICopyStaticFilesOptionsBase<K extends string = string> | ||
{ | ||
cwd: string, | ||
staticRoot?: string, | ||
overwrite?: boolean, | ||
} | ||
|
||
export interface ICopyStaticFilesOptions<K extends string = string> extends ICopyStaticFilesOptionsBase<K> | ||
{ | ||
file_map?: IStaticFiles<K>, | ||
} | ||
|
||
export function parseStaticMap<K extends string>(file_map: IStaticFilesMapRecord<K>): [K | IStaticFilesID, string, string?][] | ||
export function parseStaticMap<K extends string>(file_map: IStaticFilesMapArray<K>): [K | IStaticFilesID, string, string?][] | ||
export function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): [K | IStaticFilesID, string, string?][] | ||
export function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): [K, string, string?][] | ||
{ | ||
let ls: IStaticFilesRow<K>[]; | ||
|
||
if (Array.isArray(file_map)) | ||
{ | ||
// @ts-ignore | ||
ls = Object.values(file_map) | ||
} | ||
else | ||
{ | ||
// @ts-ignore | ||
ls = Object.entries(file_map) | ||
} | ||
|
||
return ls | ||
.filter(v => v && Array.isArray(v) && v.length > 1) | ||
; | ||
} | ||
|
||
export function getStaticFile<K extends string>(file_id: K, options?: Pick<ICopyStaticFilesOptions<string>, 'file_map'>): [K, string, string?] | ||
{ | ||
let ls = parseStaticMap(options && options.file_map || defaultCopyStaticFiles as IStaticFilesMapArray<K>); | ||
|
||
return ls.find(([a]) => { | ||
return a === file_id; | ||
}) as [K, string, string?] | ||
} | ||
|
||
export function copyStaticFiles<K extends string>(options: ICopyStaticFilesOptions<K>) | ||
{ | ||
if (!options.cwd || typeof options.cwd != 'string') | ||
{ | ||
throw new TypeError(`options.cwd must is string`) | ||
} | ||
|
||
if (!pathExistsSync(options.cwd)) | ||
{ | ||
throw new TypeError(`options.cwd not exists`) | ||
} | ||
|
||
let copyOptions: CopyOptionsSync = { | ||
overwrite: options.overwrite || false, | ||
preserveTimestamps: true, | ||
errorOnExist: false, | ||
}; | ||
|
||
const { cwd, file_map = defaultCopyStaticFiles as IStaticFilesMapArray<K> } = options; | ||
const staticRoot = options.staticRoot || __dirname; | ||
|
||
let ls = parseStaticMap<K>(file_map); | ||
|
||
ls = ls.filter(v => v && Array.isArray(v) && v.length > 1); | ||
|
||
if (!ls.length) | ||
{ | ||
throw new TypeError(`file_map is not file map`) | ||
} | ||
|
||
return ls | ||
// @ts-ignore | ||
.filter(function ([a, b, c]: IStaticFilesRow<K>) | ||
{ | ||
let fa = resolve(cwd, a); | ||
let fb = resolve(staticRoot, b); | ||
|
||
if (c != null) | ||
{ | ||
let fc = resolve(cwd, c); | ||
|
||
if (existsSync(fc)) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
if (!existsSync(fb)) | ||
{ | ||
throw new Error(`file not exists. ${fb}`) | ||
} | ||
|
||
ensureDirSync(dirname(fa)) | ||
copySync(fb, fa, copyOptions); | ||
|
||
return true; | ||
}) | ||
; | ||
} | ||
|
||
export default copyStaticFiles | ||
export default copyStaticFiles; |
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,3 @@ | ||
import { IStaticFilesMapArray } from './types'; | ||
export declare const defaultCopyStaticFiles: IStaticFilesMapArray<"tsconfig.json.tpl" | "test/tsconfig.json.tpl" | "tsconfig.esm.json.tpl" | ".eslintrc.json.tpl" | "now.json.tpl" | ".npmrc.tpl" | "tsdx.config.js.tpl">; | ||
export declare const defaultCopyStaticFilesRootOnly: IStaticFilesMapArray<"tsconfig.json" | "lerna.json.tpl" | "pnpm-workspace.yaml.tpl">; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.