[ci] yarn format
This commit is contained in:
parent
dbd2f5076b
commit
b1b564d03d
3 changed files with 23 additions and 31 deletions
|
@ -27,7 +27,7 @@ This command is meant for local testing only, and is not designed to be run in p
|
||||||
|
|
||||||
### `astro check`
|
### `astro check`
|
||||||
|
|
||||||
Runs diagnostics (such as type-checking) against your project and reports errors to the console. If any errors are found the process will exit with a code of __1__.
|
Runs diagnostics (such as type-checking) against your project and reports errors to the console. If any errors are found the process will exit with a code of **1**.
|
||||||
|
|
||||||
This command is intended to be used in CI workflows.
|
This command is intended to be used in CI workflows.
|
||||||
|
|
||||||
|
|
|
@ -7,25 +7,19 @@ import * as path from 'path';
|
||||||
import { pathToFileURL } from 'url';
|
import { pathToFileURL } from 'url';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
async function openAllDocuments(
|
async function openAllDocuments(workspaceUri: URL, filePathsToIgnore: string[], checker: AstroCheck) {
|
||||||
workspaceUri: URL,
|
|
||||||
filePathsToIgnore: string[],
|
|
||||||
checker: AstroCheck
|
|
||||||
) {
|
|
||||||
const files = await glob('**/*.astro', {
|
const files = await glob('**/*.astro', {
|
||||||
cwd: workspaceUri.pathname,
|
cwd: workspaceUri.pathname,
|
||||||
ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`))
|
ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`)),
|
||||||
});
|
});
|
||||||
const absFilePaths = files.map((f) => path.resolve(workspaceUri.pathname, f));
|
const absFilePaths = files.map((f) => path.resolve(workspaceUri.pathname, f));
|
||||||
|
|
||||||
for (const absFilePath of absFilePaths) {
|
for (const absFilePath of absFilePaths) {
|
||||||
const text = fs.readFileSync(absFilePath, 'utf-8');
|
const text = fs.readFileSync(absFilePath, 'utf-8');
|
||||||
checker.upsertDocument(
|
checker.upsertDocument({
|
||||||
{
|
uri: pathToFileURL(absFilePath).toString(),
|
||||||
uri: pathToFileURL(absFilePath).toString(),
|
text,
|
||||||
text
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,17 +28,17 @@ interface Result {
|
||||||
warnings: number;
|
warnings: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function offsetAt({ line, character }: { line: number, character: number; }, text: string) {
|
function offsetAt({ line, character }: { line: number; character: number }, text: string) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let l = 0;
|
let l = 0;
|
||||||
let c = 0;
|
let c = 0;
|
||||||
while(i < text.length) {
|
while (i < text.length) {
|
||||||
if(l === line && c === character) {
|
if (l === line && c === character) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let char = text[i];
|
let char = text[i];
|
||||||
switch(char) {
|
switch (char) {
|
||||||
case '\n': {
|
case '\n': {
|
||||||
l++;
|
l++;
|
||||||
c = 0;
|
c = 0;
|
||||||
|
@ -66,9 +60,7 @@ function pad(str: string, len: number) {
|
||||||
return Array.from({ length: len }, () => str).join('');
|
return Array.from({ length: len }, () => str).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function check(astroConfig: AstroConfig) {
|
export async function check(astroConfig: AstroConfig) {
|
||||||
const root = astroConfig.projectRoot;
|
const root = astroConfig.projectRoot;
|
||||||
|
@ -79,18 +71,18 @@ export async function check(astroConfig: AstroConfig) {
|
||||||
|
|
||||||
let result: Result = {
|
let result: Result = {
|
||||||
errors: 0,
|
errors: 0,
|
||||||
warnings: 0
|
warnings: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
diagnostics.forEach(diag => {
|
diagnostics.forEach((diag) => {
|
||||||
diag.diagnostics.forEach(d => {
|
diag.diagnostics.forEach((d) => {
|
||||||
switch(d.severity) {
|
switch (d.severity) {
|
||||||
case DiagnosticSeverity.Error: {
|
case DiagnosticSeverity.Error: {
|
||||||
console.error(`${bold(cyan(path.relative(root.pathname, diag.filePath)))}:${bold(yellow(d.range.start.line))}:${bold(yellow(d.range.start.character))} - ${d.message}`);
|
console.error(`${bold(cyan(path.relative(root.pathname, diag.filePath)))}:${bold(yellow(d.range.start.line))}:${bold(yellow(d.range.start.character))} - ${d.message}`);
|
||||||
let startOffset = offsetAt({ line: d.range.start.line, character: 0 }, diag.text);
|
let startOffset = offsetAt({ line: d.range.start.line, character: 0 }, diag.text);
|
||||||
let endOffset = offsetAt({ line: d.range.start.line + 1, character: 0 }, diag.text);
|
let endOffset = offsetAt({ line: d.range.start.line + 1, character: 0 }, diag.text);
|
||||||
let str = diag.text.substring(startOffset, endOffset - 1);
|
let str = diag.text.substring(startOffset, endOffset - 1);
|
||||||
const lineNumStr = (d.range.start.line).toString();
|
const lineNumStr = d.range.start.line.toString();
|
||||||
const lineNumLen = lineNumStr.length;
|
const lineNumLen = lineNumStr.length;
|
||||||
console.error(`${bgWhite(black(lineNumStr))} ${str}`);
|
console.error(`${bgWhite(black(lineNumStr))} ${str}`);
|
||||||
let tildes = pad('~', d.range.end.character - d.range.start.character);
|
let tildes = pad('~', d.range.end.character - d.range.start.character);
|
||||||
|
@ -107,8 +99,8 @@ export async function check(astroConfig: AstroConfig) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if(result.errors) {
|
if (result.errors) {
|
||||||
console.error(`Found ${result.errors} errors.`)
|
console.error(`Found ${result.errors} errors.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exitCode = result.errors ? 1 : 0;
|
const exitCode = result.errors ? 1 : 0;
|
||||||
|
|
|
@ -134,7 +134,7 @@ const cmdMap = new Map<string, (a: AstroConfig, opts?: any) => Promise<any>>([
|
||||||
['dev', devServer],
|
['dev', devServer],
|
||||||
['preview', preview],
|
['preview', preview],
|
||||||
['reload', reloadAndExit],
|
['reload', reloadAndExit],
|
||||||
['check', checkAndExit]
|
['check', checkAndExit],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** The primary CLI action */
|
/** The primary CLI action */
|
||||||
|
|
Loading…
Add table
Reference in a new issue