8 Star 33 Fork 8

Gitee 极速下载/FabricJS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/fabricjs/fabric.js/
克隆/下载
playwright.setup.ts 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
import { transformFileAsync } from '@babel/core';
import type { PlaywrightTestConfig } from '@playwright/test';
import { readdirSync, rmSync, statSync, watch, writeFileSync } from 'node:fs';
import { ensureFileSync } from 'fs-extra';
import match from 'micromatch';
import path from 'path';
const include = ['**/*.ts'];
const exclude = ['**/*.spec.ts'];
const src = path.resolve(process.cwd(), 'e2e', 'tests');
const dist = path.resolve(process.cwd(), 'e2e', 'dist');
const includeRe = include.map((glob) => match.makeRe(glob));
const excludeRe = exclude.map((glob) => match.makeRe(glob));
const walkSync = (dir: string, callback: (file: string) => any) => {
const files = readdirSync(dir);
files.forEach((file) => {
var filepath = path.resolve(dir, file);
const stats = statSync(filepath);
if (stats.isDirectory()) {
walkSync(filepath, callback);
} else if (stats.isFile()) {
callback(filepath);
}
});
};
const shouldBuild = (file: string) =>
includeRe.some((re) => re.test(file)) &&
excludeRe.every((re) => !re.test(file));
const getDistFileName = (file: string) => {
const { dir, name } = path.parse(
path.resolve(dist, path.relative(src, file))
);
return path.format({
dir,
name,
ext: '.js',
});
};
const buildFile = async (file: string) => {
const result = await transformFileAsync(file, {
configFile: './e2e/.babelrc.mjs',
babelrc: undefined,
});
if (result?.code) {
const distFile = getDistFileName(file);
ensureFileSync(distFile);
writeFileSync(distFile, result.code);
}
};
export default async (config: PlaywrightTestConfig) => {
const files: string[] = [];
walkSync(src, (file) => files.push(file));
rmSync(dist, { recursive: true, force: true });
const tasks = await Promise.all(
files.filter((file) => shouldBuild(file)).map((file) => buildFile(file))
);
console.log(
`Successfully compiled ${tasks.length} files from ${path.relative(
process.cwd(),
src
)} to ${path.relative(process.cwd(), dist)}`
);
// watch
if (process.argv.includes('--ui')) {
const watcher = watch(
src,
{ recursive: true, persistent: true },
(type, filename) => {
const file = path.join(src, filename);
shouldBuild(file) && buildFile(file);
}
);
process.once('exit', () => watcher.close());
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/FabricJS.git
git@gitee.com:mirrors/FabricJS.git
mirrors
FabricJS
FabricJS
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385