path#posix JavaScript Examples
The following examples show how to use
path#posix.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From cs-wiki with GNU General Public License v3.0 | 6 votes |
function getMatcherString(id, resolutionBase) {
if (resolutionBase === false) {
return id;
}
// resolve('') is valid and will default to process.cwd()
const basePath = resolve(resolutionBase || '')
.split(sep)
.join('/')
// escape all possible (posix + win) path characters that might interfere with regex
.replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
// Note that we use posix.join because:
// 1. the basePath has been normalized to use /
// 2. the incoming glob (id) matcher, also uses /
// otherwise Node will force backslash (\) on windows
return posix.join(basePath, id);
}
Example #2
Source File: index.js From fes.js with MIT License | 6 votes |
getRoutePath = function (parentRoutePath, fileName, isFile = true) {
// /index.vue -> /
if (isFile && fileName === 'index') {
fileName = '';
}
// /@id.vue -> /:id
if (fileName.startsWith('@')) {
fileName = fileName.replace(/@/, ':');
}
// /*.vue -> :pathMatch(.*)
if (fileName.includes('*')) {
fileName = fileName.replace('*', ':pathMatch(.*)');
}
return posix.join(parentRoutePath, fileName);
}
Example #3
Source File: index.js From fes.js with MIT License | 5 votes |
getRouteName = function (parentRoutePath, fileName) {
const routeName = posix.join(parentRoutePath, fileName);
return routeName
.slice(1)
.replace(/\//g, '_')
.replace(/@/g, '_')
.replace(/\*/g, 'FUZZYMATCH');
}
Example #4
Source File: index.js From fes.js with MIT License | 5 votes |
genRoutes = function (parentRoutes, path, parentRoutePath) {
const dirList = readdirSync(path);
const hasLayout = checkHasLayout(path);
const layoutRoute = {
children: []
};
if (hasLayout) {
layoutRoute.path = parentRoutePath;
parentRoutes.push(layoutRoute);
}
dirList.forEach((item) => {
// 文件或者目录的绝对路径
const component = join(path, item);
if (isProcessFile(component)) {
const ext = extname(item);
const fileName = basename(item, ext);
// 路由的path
const routePath = getRoutePath(parentRoutePath, fileName);
if (cacheGenRoutes[routePath]) {
logger.warn(`[WARNING]: The file path: ${routePath}(.jsx/.tsx/.vue) conflict in router,will only use ${routePath}.tsx or ${routePath}.jsx,please remove one of.`);
return;
}
cacheGenRoutes[routePath] = true;
// 路由名称
const routeName = getRouteName(parentRoutePath, fileName);
const componentPath = posix.join(path, item);
let content = readFileSync(component, 'utf-8');
let routeMeta = {};
if (ext === '.vue') {
const { descriptor } = parse(content);
const routeMetaBlock = descriptor.customBlocks.find(
b => b.type === 'config'
);
routeMeta = routeMetaBlock?.content ? JSON.parse(routeMetaBlock.content) : {};
if (descriptor.script) {
content = descriptor.script.content;
routeMeta = getRouteMeta(content) || routeMeta;
}
}
if (ext === '.jsx' || ext === '.tsx') {
routeMeta = getRouteMeta(content) || {};
}
const routeConfig = {
path: routePath,
component: componentPath,
name: routeMeta.name || routeName,
meta: routeMeta
};
if (hasLayout) {
if (fileName === 'layout') {
layoutRoute.component = componentPath;
} else {
layoutRoute.children.push(routeConfig);
}
} else {
parentRoutes.push(routeConfig);
}
}
});
dirList.forEach((item) => {
if (isProcessDirectory(path, item)) {
// 文件或者目录的绝对路径
const nextPath = join(path, item);
const nextParentRouteUrl = getRoutePath(parentRoutePath, item, false);
if (hasLayout) {
genRoutes(layoutRoute.children, nextPath, nextParentRouteUrl);
} else {
genRoutes(parentRoutes, nextPath, nextParentRouteUrl);
}
}
});
}
Example #5
Source File: index.js From kit with MIT License | 5 votes |
/** @type {import('.').default} */
export default function (options = {}) {
return {
name: '@sveltejs/adapter-cloudflare',
async adapt(builder) {
const files = fileURLToPath(new URL('./files', import.meta.url).href);
const dest = builder.getBuildDirectory('cloudflare');
const tmp = builder.getBuildDirectory('cloudflare-tmp');
builder.rimraf(dest);
builder.rimraf(tmp);
builder.mkdirp(tmp);
builder.writeStatic(dest);
builder.writeClient(dest);
builder.writePrerendered(dest);
const relativePath = posix.relative(tmp, builder.getServerDirectory());
writeFileSync(
`${tmp}/manifest.js`,
`export const manifest = ${builder.generateManifest({
relativePath
})};\n\nexport const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n`
);
builder.copy(`${files}/worker.js`, `${tmp}/_worker.js`, {
replace: {
SERVER: `${relativePath}/index.js`,
MANIFEST: './manifest.js'
}
});
await esbuild.build({
platform: 'browser',
sourcemap: 'linked',
target: 'es2020',
...options,
entryPoints: [`${tmp}/_worker.js`],
outfile: `${dest}/_worker.js`,
allowOverwrite: true,
format: 'esm',
bundle: true
});
}
};
}
Example #6
Source File: index.js From kit with MIT License | 5 votes |
/**
* @typedef {{
* main: string;
* site: {
* bucket: string;
* }
* }} WranglerConfig
*/
/** @type {import('.').default} */
export default function (options = {}) {
return {
name: '@sveltejs/adapter-cloudflare-workers',
async adapt(builder) {
const { main, site } = validate_config(builder);
const files = fileURLToPath(new URL('./files', import.meta.url).href);
const tmp = builder.getBuildDirectory('cloudflare-workers-tmp');
builder.rimraf(site.bucket);
builder.rimraf(dirname(main));
builder.log.info('Installing worker dependencies...');
builder.copy(`${files}/_package.json`, `${tmp}/package.json`);
// TODO would be cool if we could make this step unnecessary somehow
const stdout = execSync('npm install', { cwd: tmp });
builder.log.info(stdout.toString());
builder.log.minor('Generating worker...');
const relativePath = posix.relative(tmp, builder.getServerDirectory());
builder.copy(`${files}/entry.js`, `${tmp}/entry.js`, {
replace: {
SERVER: `${relativePath}/index.js`,
MANIFEST: './manifest.js'
}
});
writeFileSync(
`${tmp}/manifest.js`,
`export const manifest = ${builder.generateManifest({
relativePath
})};\n\nexport const prerendered = new Map(${JSON.stringify(
Array.from(builder.prerendered.pages.entries())
)});\n`
);
await esbuild.build({
platform: 'browser',
sourcemap: 'linked',
target: 'es2020',
...options,
entryPoints: [`${tmp}/entry.js`],
outfile: main,
bundle: true,
external: ['__STATIC_CONTENT_MANIFEST', ...(options?.external || [])],
format: 'esm'
});
builder.log.minor('Copying assets...');
builder.writeClient(site.bucket);
builder.writeStatic(site.bucket);
builder.writePrerendered(site.bucket);
}
};
}
Example #7
Source File: index.js From kit with MIT License | 5 votes |
/**
* @param { object } params
* @param {import('@sveltejs/kit').Builder} params.builder
*/
async function generate_edge_functions({ builder }) {
const tmp = builder.getBuildDirectory('netlify-tmp');
builder.rimraf(tmp);
builder.mkdirp(tmp);
builder.mkdirp('.netlify/edge-functions');
// Don't match the static directory
const pattern = '^/.*$';
// Go doesn't support lookarounds, so we can't do this
// const pattern = appDir ? `^/(?!${escapeStringRegexp(appDir)}).*$` : '^/.*$';
/** @type {HandlerManifest} */
const edge_manifest = {
functions: [
{
function: 'render',
pattern
}
],
version: 1
};
builder.log.minor('Generating Edge Function...');
const relativePath = posix.relative(tmp, builder.getServerDirectory());
builder.copy(`${files}/edge.js`, `${tmp}/entry.js`, {
replace: {
'0SERVER': `${relativePath}/index.js`,
MANIFEST: './manifest.js'
}
});
const manifest = builder.generateManifest({
relativePath
});
writeFileSync(
`${tmp}/manifest.js`,
`export const manifest = ${manifest};\n\nexport const prerendered = new Set(${JSON.stringify(
builder.prerendered.paths
)});\n`
);
await esbuild.build({
entryPoints: [`${tmp}/entry.js`],
outfile: '.netlify/edge-functions/render.js',
bundle: true,
format: 'esm',
platform: 'browser',
sourcemap: 'linked',
target: 'es2020'
});
writeFileSync('.netlify/edge-functions/manifest.json', JSON.stringify(edge_manifest));
}