[ci] format

This commit is contained in:
matthewp 2023-01-23 14:49:20 +00:00 committed by fredkbot
parent f5adbd6b55
commit 0d0974722f
2 changed files with 35 additions and 24 deletions

View file

@ -29,7 +29,7 @@ export async function createRedirects(
input: route.pathname, input: route.pathname,
target: prependForwardSlash(route.distURL.toString().replace(dir.toString(), '')), target: prependForwardSlash(route.distURL.toString().replace(dir.toString(), '')),
status: 200, status: 200,
weight: 1 weight: 1,
}); });
} else { } else {
definitions.push({ definitions.push({
@ -46,33 +46,37 @@ export async function createRedirects(
input: '/*', input: '/*',
target: `/.netlify/${kind}/${entryFile}`, target: `/.netlify/${kind}/${entryFile}`,
status: 404, status: 404,
weight: 0 weight: 0,
}); });
} }
} }
} else { } else {
const pattern = const pattern =
'/' + route.segments.map(([part]) => { '/' +
//(part.dynamic ? '*' : part.content) route.segments
if(part.dynamic) { .map(([part]) => {
if(part.spread) { //(part.dynamic ? '*' : part.content)
return '*'; if (part.dynamic) {
if (part.spread) {
return '*';
} else {
return ':' + part.content;
}
} else { } else {
return ':' + part.content; return part.content;
} }
} else { })
return part.content; .join('/');
}
}).join('/');
if (route.distURL) { if (route.distURL) {
const target = `${pattern}` + (config.build.format === 'directory' ? '/index.html' : '.html'); const target =
`${pattern}` + (config.build.format === 'directory' ? '/index.html' : '.html');
definitions.push({ definitions.push({
dynamic: true, dynamic: true,
input: pattern, input: pattern,
target, target,
status: 200, status: 200,
weight: 1 weight: 1,
}); });
} else { } else {
definitions.push({ definitions.push({
@ -80,7 +84,7 @@ export async function createRedirects(
input: pattern, input: pattern,
target: `/.netlify/${kind}/${entryFile}`, target: `/.netlify/${kind}/${entryFile}`,
status: 200, status: 200,
weight: 1 weight: 1,
}); });
} }
} }
@ -95,21 +99,22 @@ export async function createRedirects(
} }
function prettify(definitions: RedirectDefinition[]) { function prettify(definitions: RedirectDefinition[]) {
let minInputLength = 0, minTargetLength = 0; let minInputLength = 0,
minTargetLength = 0;
definitions.sort((a, b) => { definitions.sort((a, b) => {
// Find the longest input, so we can format things nicely // Find the longest input, so we can format things nicely
if(a.input.length > minInputLength) { if (a.input.length > minInputLength) {
minInputLength = a.input.length; minInputLength = a.input.length;
} }
if(b.input.length > minInputLength) { if (b.input.length > minInputLength) {
minInputLength = b.input.length; minInputLength = b.input.length;
} }
// Same for the target // Same for the target
if(a.target.length > minTargetLength) { if (a.target.length > minTargetLength) {
minTargetLength = a.target.length; minTargetLength = a.target.length;
} }
if(b.target.length > minTargetLength) { if (b.target.length > minTargetLength) {
minTargetLength = b.target.length; minTargetLength = b.target.length;
} }
@ -122,9 +127,15 @@ function prettify(definitions: RedirectDefinition[]) {
definitions.forEach((defn, i) => { definitions.forEach((defn, i) => {
// Figure out the number of spaces to add. We want at least 4 spaces // Figure out the number of spaces to add. We want at least 4 spaces
// after the input. This ensure that all targets line up together. // after the input. This ensure that all targets line up together.
let inputSpaces = (minInputLength - defn.input.length) + 4; let inputSpaces = minInputLength - defn.input.length + 4;
let targetSpaces = (minTargetLength - defn.target.length) + 4; let targetSpaces = minTargetLength - defn.target.length + 4;
_redirects += (i === 0 ? '' : '\n') + defn.input + ' '.repeat(inputSpaces) + defn.target + ' '.repeat(Math.abs(targetSpaces)) + defn.status; _redirects +=
(i === 0 ? '' : '\n') +
defn.input +
' '.repeat(inputSpaces) +
defn.target +
' '.repeat(Math.abs(targetSpaces)) +
defn.status;
}); });
return _redirects; return _redirects;
} }

View file

@ -1,12 +1,12 @@
import load, { resolve } from '@proload/core'; import load, { resolve } from '@proload/core';
import type { AstroIntegration } from 'astro'; import type { AstroIntegration } from 'astro';
import type { CSSOptions, UserConfig } from 'vite';
import autoprefixerPlugin from 'autoprefixer'; import autoprefixerPlugin from 'autoprefixer';
import fs from 'fs/promises'; import fs from 'fs/promises';
import path from 'path'; import path from 'path';
import tailwindPlugin, { Config as TailwindConfig } from 'tailwindcss'; import tailwindPlugin, { Config as TailwindConfig } from 'tailwindcss';
import resolveConfig from 'tailwindcss/resolveConfig.js'; import resolveConfig from 'tailwindcss/resolveConfig.js';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import type { CSSOptions, UserConfig } from 'vite';
function getDefaultTailwindConfig(srcUrl: URL): TailwindConfig { function getDefaultTailwindConfig(srcUrl: URL): TailwindConfig {
return resolveConfig({ return resolveConfig({