@valbuild/cli 0.80.0 → 0.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,6 @@ var server = require('@valbuild/server');
|
|
7
7
|
var core = require('@valbuild/core');
|
8
8
|
var fastGlob = require('fast-glob');
|
9
9
|
var picocolors = require('picocolors');
|
10
|
-
var eslint = require('eslint');
|
11
10
|
var fs = require('fs/promises');
|
12
11
|
var vm = require('node:vm');
|
13
12
|
var ts = require('typescript');
|
@@ -125,16 +124,11 @@ function getFileExt(filePath) {
|
|
125
124
|
const textEncoder = new TextEncoder();
|
126
125
|
async function validate({
|
127
126
|
root,
|
128
|
-
fix
|
129
|
-
noEslint
|
127
|
+
fix
|
130
128
|
}) {
|
131
129
|
const valRemoteHost = process.env.VAL_REMOTE_HOST || core.DEFAULT_VAL_REMOTE_HOST;
|
132
130
|
const contentHostUrl = process.env.VAL_CONTENT_URL || core.DEFAULT_CONTENT_HOST;
|
133
131
|
const projectRoot = root ? path__default["default"].resolve(root) : process.cwd();
|
134
|
-
const eslint$1 = new eslint.ESLint({
|
135
|
-
cwd: projectRoot,
|
136
|
-
ignore: false
|
137
|
-
});
|
138
132
|
const valConfigFile = (await evalValConfigFile(projectRoot, "val.config.ts")) || (await evalValConfigFile(projectRoot, "val.config.js"));
|
139
133
|
console.log(picocolors__default["default"].greenBright(`Validating project${valConfigFile !== null && valConfigFile !== void 0 && valConfigFile.project ? ` '${picocolors__default["default"].inverse(valConfigFile === null || valConfigFile === void 0 ? void 0 : valConfigFile.project)}'` : ""}...`));
|
140
134
|
const service = await server.createService(projectRoot, {});
|
@@ -181,34 +175,10 @@ async function validate({
|
|
181
175
|
cwd: projectRoot
|
182
176
|
});
|
183
177
|
let errors = 0;
|
184
|
-
let eslintResults = [];
|
185
|
-
let eslintResultsByFile = {};
|
186
|
-
if (!noEslint) {
|
187
|
-
const lintFiles = await fastGlob.glob("**/*.{js,ts}", {
|
188
|
-
ignore: ["node_modules/**"],
|
189
|
-
cwd: projectRoot
|
190
|
-
});
|
191
|
-
console.log("Running eslint...");
|
192
|
-
eslintResults = await eslint$1.lintFiles(lintFiles);
|
193
|
-
eslintResultsByFile = eslintResults.reduce((acc, result) => ({
|
194
|
-
...acc,
|
195
|
-
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result
|
196
|
-
}), {});
|
197
|
-
eslintResults.forEach(result => {
|
198
|
-
result.messages.forEach(async m => {
|
199
|
-
if (m.messageId === "val/export-content-must-be-valid") {
|
200
|
-
errors += 1;
|
201
|
-
logEslintMessage(await fs__default["default"].readFile(result.filePath, "utf-8"), result.filePath, m);
|
202
|
-
}
|
203
|
-
});
|
204
|
-
});
|
205
|
-
console.log(errors === 0 ? picocolors__default["default"].green("✔") : picocolors__default["default"].red("✘"), "ESlint complete", lintFiles.length, "files");
|
206
|
-
}
|
207
178
|
console.log(picocolors__default["default"].greenBright(`Found ${valFiles.length} files...`));
|
208
179
|
let publicProjectId;
|
209
180
|
let didFix = false; // TODO: ugly
|
210
181
|
async function validateFile(file) {
|
211
|
-
var _eslintResultsByFile;
|
212
182
|
const moduleFilePath = `/${file}`; // TODO: check if this always works? (Windows?)
|
213
183
|
const start = Date.now();
|
214
184
|
const valModule = await service.get(moduleFilePath, "", {
|
@@ -216,21 +186,14 @@ async function validate({
|
|
216
186
|
schema: true,
|
217
187
|
validate: true
|
218
188
|
});
|
219
|
-
const fileContent = await fs__default["default"].readFile(path__default["default"].join(projectRoot, file), "utf-8");
|
220
|
-
const eslintResult = (_eslintResultsByFile = eslintResultsByFile) === null || _eslintResultsByFile === void 0 ? void 0 : _eslintResultsByFile[file];
|
221
189
|
const remoteFiles = {};
|
222
190
|
let remoteFileBuckets = null;
|
223
191
|
let remoteFilesCounter = 0;
|
224
|
-
|
225
|
-
// display surrounding code
|
226
|
-
logEslintMessage(fileContent, moduleFilePath, m);
|
227
|
-
});
|
228
|
-
if (!valModule.errors && (eslintResult === null || eslintResult === void 0 ? void 0 : eslintResult.errorCount) === 0) {
|
192
|
+
if (!valModule.errors) {
|
229
193
|
console.log(picocolors__default["default"].green("✔"), moduleFilePath, "is valid (" + (Date.now() - start) + "ms)");
|
230
194
|
return 0;
|
231
195
|
} else {
|
232
|
-
|
233
|
-
let errors = ((_eslintResultsByFile2 = eslintResultsByFile) === null || _eslintResultsByFile2 === void 0 || (_eslintResultsByFile2 = _eslintResultsByFile2[file]) === null || _eslintResultsByFile2 === void 0 ? void 0 : _eslintResultsByFile2.messages.reduce((prev, m) => m.severity >= 2 ? prev + 1 : prev, 0)) || 0;
|
196
|
+
let errors = 0;
|
234
197
|
let fixedErrors = 0;
|
235
198
|
if (valModule.errors) {
|
236
199
|
if (valModule.errors.validation) {
|
@@ -497,28 +460,6 @@ async function validate({
|
|
497
460
|
service.dispose();
|
498
461
|
return;
|
499
462
|
}
|
500
|
-
function logEslintMessage(fileContent, filePath, eslintMessage) {
|
501
|
-
const lines = fileContent.split("\n");
|
502
|
-
const line = lines[eslintMessage.line - 1];
|
503
|
-
const lineBefore = lines[eslintMessage.line - 2];
|
504
|
-
const lineAfter = lines[eslintMessage.line];
|
505
|
-
const isError = eslintMessage.severity >= 2;
|
506
|
-
console.log(isError ? picocolors__default["default"].red("✘") : picocolors__default["default"].yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`, eslintMessage.message);
|
507
|
-
if (lineBefore) {
|
508
|
-
console.log(picocolors__default["default"].gray(" " + (eslintMessage.line - 1) + " |"), lineBefore);
|
509
|
-
}
|
510
|
-
if (line) {
|
511
|
-
console.log(picocolors__default["default"].gray(" " + eslintMessage.line + " |"), line);
|
512
|
-
}
|
513
|
-
// adds ^ below the relevant line:
|
514
|
-
const amountOfColumns = eslintMessage.endColumn && eslintMessage.endColumn - eslintMessage.column > 0 ? eslintMessage.endColumn - eslintMessage.column : 1;
|
515
|
-
if (line) {
|
516
|
-
console.log(picocolors__default["default"].gray(" " + " ".repeat(eslintMessage.line.toString().length) + " |"), " ".repeat(eslintMessage.column - 1) + (eslintMessage.endColumn ? (isError ? picocolors__default["default"].red("^") : picocolors__default["default"].yellow("^")).repeat(amountOfColumns) : ""));
|
517
|
-
}
|
518
|
-
if (lineAfter) {
|
519
|
-
console.log(picocolors__default["default"].gray(" " + (eslintMessage.line + 1) + " |"), lineAfter);
|
520
|
-
}
|
521
|
-
}
|
522
463
|
|
523
464
|
// GPT generated levenshtein distance algorithm:
|
524
465
|
const levenshtein = (a, b) => {
|
@@ -740,7 +681,6 @@ async function main() {
|
|
740
681
|
Options:
|
741
682
|
--root [root], -r [root] Set project root directory (default process.cwd())
|
742
683
|
--fix [fix] Attempt to fix validation errors
|
743
|
-
--noEslint [noEslint] Disable eslint validation during validate
|
744
684
|
|
745
685
|
|
746
686
|
Command: login
|
@@ -812,8 +752,7 @@ async function main() {
|
|
812
752
|
}
|
813
753
|
return validate({
|
814
754
|
root: flags.root,
|
815
|
-
fix: flags.fix
|
816
|
-
noEslint: flags.noEslint
|
755
|
+
fix: flags.fix
|
817
756
|
});
|
818
757
|
default:
|
819
758
|
return error(`Unknown command "${input.join(" ")}"`);
|
@@ -7,7 +7,6 @@ var server = require('@valbuild/server');
|
|
7
7
|
var core = require('@valbuild/core');
|
8
8
|
var fastGlob = require('fast-glob');
|
9
9
|
var picocolors = require('picocolors');
|
10
|
-
var eslint = require('eslint');
|
11
10
|
var fs = require('fs/promises');
|
12
11
|
var vm = require('node:vm');
|
13
12
|
var ts = require('typescript');
|
@@ -125,16 +124,11 @@ function getFileExt(filePath) {
|
|
125
124
|
const textEncoder = new TextEncoder();
|
126
125
|
async function validate({
|
127
126
|
root,
|
128
|
-
fix
|
129
|
-
noEslint
|
127
|
+
fix
|
130
128
|
}) {
|
131
129
|
const valRemoteHost = process.env.VAL_REMOTE_HOST || core.DEFAULT_VAL_REMOTE_HOST;
|
132
130
|
const contentHostUrl = process.env.VAL_CONTENT_URL || core.DEFAULT_CONTENT_HOST;
|
133
131
|
const projectRoot = root ? path__default["default"].resolve(root) : process.cwd();
|
134
|
-
const eslint$1 = new eslint.ESLint({
|
135
|
-
cwd: projectRoot,
|
136
|
-
ignore: false
|
137
|
-
});
|
138
132
|
const valConfigFile = (await evalValConfigFile(projectRoot, "val.config.ts")) || (await evalValConfigFile(projectRoot, "val.config.js"));
|
139
133
|
console.log(picocolors__default["default"].greenBright(`Validating project${valConfigFile !== null && valConfigFile !== void 0 && valConfigFile.project ? ` '${picocolors__default["default"].inverse(valConfigFile === null || valConfigFile === void 0 ? void 0 : valConfigFile.project)}'` : ""}...`));
|
140
134
|
const service = await server.createService(projectRoot, {});
|
@@ -181,34 +175,10 @@ async function validate({
|
|
181
175
|
cwd: projectRoot
|
182
176
|
});
|
183
177
|
let errors = 0;
|
184
|
-
let eslintResults = [];
|
185
|
-
let eslintResultsByFile = {};
|
186
|
-
if (!noEslint) {
|
187
|
-
const lintFiles = await fastGlob.glob("**/*.{js,ts}", {
|
188
|
-
ignore: ["node_modules/**"],
|
189
|
-
cwd: projectRoot
|
190
|
-
});
|
191
|
-
console.log("Running eslint...");
|
192
|
-
eslintResults = await eslint$1.lintFiles(lintFiles);
|
193
|
-
eslintResultsByFile = eslintResults.reduce((acc, result) => ({
|
194
|
-
...acc,
|
195
|
-
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result
|
196
|
-
}), {});
|
197
|
-
eslintResults.forEach(result => {
|
198
|
-
result.messages.forEach(async m => {
|
199
|
-
if (m.messageId === "val/export-content-must-be-valid") {
|
200
|
-
errors += 1;
|
201
|
-
logEslintMessage(await fs__default["default"].readFile(result.filePath, "utf-8"), result.filePath, m);
|
202
|
-
}
|
203
|
-
});
|
204
|
-
});
|
205
|
-
console.log(errors === 0 ? picocolors__default["default"].green("✔") : picocolors__default["default"].red("✘"), "ESlint complete", lintFiles.length, "files");
|
206
|
-
}
|
207
178
|
console.log(picocolors__default["default"].greenBright(`Found ${valFiles.length} files...`));
|
208
179
|
let publicProjectId;
|
209
180
|
let didFix = false; // TODO: ugly
|
210
181
|
async function validateFile(file) {
|
211
|
-
var _eslintResultsByFile;
|
212
182
|
const moduleFilePath = `/${file}`; // TODO: check if this always works? (Windows?)
|
213
183
|
const start = Date.now();
|
214
184
|
const valModule = await service.get(moduleFilePath, "", {
|
@@ -216,21 +186,14 @@ async function validate({
|
|
216
186
|
schema: true,
|
217
187
|
validate: true
|
218
188
|
});
|
219
|
-
const fileContent = await fs__default["default"].readFile(path__default["default"].join(projectRoot, file), "utf-8");
|
220
|
-
const eslintResult = (_eslintResultsByFile = eslintResultsByFile) === null || _eslintResultsByFile === void 0 ? void 0 : _eslintResultsByFile[file];
|
221
189
|
const remoteFiles = {};
|
222
190
|
let remoteFileBuckets = null;
|
223
191
|
let remoteFilesCounter = 0;
|
224
|
-
|
225
|
-
// display surrounding code
|
226
|
-
logEslintMessage(fileContent, moduleFilePath, m);
|
227
|
-
});
|
228
|
-
if (!valModule.errors && (eslintResult === null || eslintResult === void 0 ? void 0 : eslintResult.errorCount) === 0) {
|
192
|
+
if (!valModule.errors) {
|
229
193
|
console.log(picocolors__default["default"].green("✔"), moduleFilePath, "is valid (" + (Date.now() - start) + "ms)");
|
230
194
|
return 0;
|
231
195
|
} else {
|
232
|
-
|
233
|
-
let errors = ((_eslintResultsByFile2 = eslintResultsByFile) === null || _eslintResultsByFile2 === void 0 || (_eslintResultsByFile2 = _eslintResultsByFile2[file]) === null || _eslintResultsByFile2 === void 0 ? void 0 : _eslintResultsByFile2.messages.reduce((prev, m) => m.severity >= 2 ? prev + 1 : prev, 0)) || 0;
|
196
|
+
let errors = 0;
|
234
197
|
let fixedErrors = 0;
|
235
198
|
if (valModule.errors) {
|
236
199
|
if (valModule.errors.validation) {
|
@@ -497,28 +460,6 @@ async function validate({
|
|
497
460
|
service.dispose();
|
498
461
|
return;
|
499
462
|
}
|
500
|
-
function logEslintMessage(fileContent, filePath, eslintMessage) {
|
501
|
-
const lines = fileContent.split("\n");
|
502
|
-
const line = lines[eslintMessage.line - 1];
|
503
|
-
const lineBefore = lines[eslintMessage.line - 2];
|
504
|
-
const lineAfter = lines[eslintMessage.line];
|
505
|
-
const isError = eslintMessage.severity >= 2;
|
506
|
-
console.log(isError ? picocolors__default["default"].red("✘") : picocolors__default["default"].yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`, eslintMessage.message);
|
507
|
-
if (lineBefore) {
|
508
|
-
console.log(picocolors__default["default"].gray(" " + (eslintMessage.line - 1) + " |"), lineBefore);
|
509
|
-
}
|
510
|
-
if (line) {
|
511
|
-
console.log(picocolors__default["default"].gray(" " + eslintMessage.line + " |"), line);
|
512
|
-
}
|
513
|
-
// adds ^ below the relevant line:
|
514
|
-
const amountOfColumns = eslintMessage.endColumn && eslintMessage.endColumn - eslintMessage.column > 0 ? eslintMessage.endColumn - eslintMessage.column : 1;
|
515
|
-
if (line) {
|
516
|
-
console.log(picocolors__default["default"].gray(" " + " ".repeat(eslintMessage.line.toString().length) + " |"), " ".repeat(eslintMessage.column - 1) + (eslintMessage.endColumn ? (isError ? picocolors__default["default"].red("^") : picocolors__default["default"].yellow("^")).repeat(amountOfColumns) : ""));
|
517
|
-
}
|
518
|
-
if (lineAfter) {
|
519
|
-
console.log(picocolors__default["default"].gray(" " + (eslintMessage.line + 1) + " |"), lineAfter);
|
520
|
-
}
|
521
|
-
}
|
522
463
|
|
523
464
|
// GPT generated levenshtein distance algorithm:
|
524
465
|
const levenshtein = (a, b) => {
|
@@ -740,7 +681,6 @@ async function main() {
|
|
740
681
|
Options:
|
741
682
|
--root [root], -r [root] Set project root directory (default process.cwd())
|
742
683
|
--fix [fix] Attempt to fix validation errors
|
743
|
-
--noEslint [noEslint] Disable eslint validation during validate
|
744
684
|
|
745
685
|
|
746
686
|
Command: login
|
@@ -812,8 +752,7 @@ async function main() {
|
|
812
752
|
}
|
813
753
|
return validate({
|
814
754
|
root: flags.root,
|
815
|
-
fix: flags.fix
|
816
|
-
noEslint: flags.noEslint
|
755
|
+
fix: flags.fix
|
817
756
|
});
|
818
757
|
default:
|
819
758
|
return error(`Unknown command "${input.join(" ")}"`);
|
@@ -5,7 +5,6 @@ import { createService, getPersonalAccessTokenPath, parsePersonalAccessTokenFile
|
|
5
5
|
import { DEFAULT_VAL_REMOTE_HOST, DEFAULT_CONTENT_HOST, Internal, FILE_REF_PROP, VAL_EXTENSION } from '@valbuild/core';
|
6
6
|
import { glob } from 'fast-glob';
|
7
7
|
import picocolors from 'picocolors';
|
8
|
-
import { ESLint } from 'eslint';
|
9
8
|
import fs from 'fs/promises';
|
10
9
|
import vm from 'node:vm';
|
11
10
|
import ts from 'typescript';
|
@@ -93,16 +92,11 @@ function getFileExt(filePath) {
|
|
93
92
|
const textEncoder = new TextEncoder();
|
94
93
|
async function validate({
|
95
94
|
root,
|
96
|
-
fix
|
97
|
-
noEslint
|
95
|
+
fix
|
98
96
|
}) {
|
99
97
|
const valRemoteHost = process.env.VAL_REMOTE_HOST || DEFAULT_VAL_REMOTE_HOST;
|
100
98
|
const contentHostUrl = process.env.VAL_CONTENT_URL || DEFAULT_CONTENT_HOST;
|
101
99
|
const projectRoot = root ? path.resolve(root) : process.cwd();
|
102
|
-
const eslint = new ESLint({
|
103
|
-
cwd: projectRoot,
|
104
|
-
ignore: false
|
105
|
-
});
|
106
100
|
const valConfigFile = (await evalValConfigFile(projectRoot, "val.config.ts")) || (await evalValConfigFile(projectRoot, "val.config.js"));
|
107
101
|
console.log(picocolors.greenBright(`Validating project${valConfigFile !== null && valConfigFile !== void 0 && valConfigFile.project ? ` '${picocolors.inverse(valConfigFile === null || valConfigFile === void 0 ? void 0 : valConfigFile.project)}'` : ""}...`));
|
108
102
|
const service = await createService(projectRoot, {});
|
@@ -149,34 +143,10 @@ async function validate({
|
|
149
143
|
cwd: projectRoot
|
150
144
|
});
|
151
145
|
let errors = 0;
|
152
|
-
let eslintResults = [];
|
153
|
-
let eslintResultsByFile = {};
|
154
|
-
if (!noEslint) {
|
155
|
-
const lintFiles = await glob("**/*.{js,ts}", {
|
156
|
-
ignore: ["node_modules/**"],
|
157
|
-
cwd: projectRoot
|
158
|
-
});
|
159
|
-
console.log("Running eslint...");
|
160
|
-
eslintResults = await eslint.lintFiles(lintFiles);
|
161
|
-
eslintResultsByFile = eslintResults.reduce((acc, result) => ({
|
162
|
-
...acc,
|
163
|
-
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result
|
164
|
-
}), {});
|
165
|
-
eslintResults.forEach(result => {
|
166
|
-
result.messages.forEach(async m => {
|
167
|
-
if (m.messageId === "val/export-content-must-be-valid") {
|
168
|
-
errors += 1;
|
169
|
-
logEslintMessage(await fs.readFile(result.filePath, "utf-8"), result.filePath, m);
|
170
|
-
}
|
171
|
-
});
|
172
|
-
});
|
173
|
-
console.log(errors === 0 ? picocolors.green("✔") : picocolors.red("✘"), "ESlint complete", lintFiles.length, "files");
|
174
|
-
}
|
175
146
|
console.log(picocolors.greenBright(`Found ${valFiles.length} files...`));
|
176
147
|
let publicProjectId;
|
177
148
|
let didFix = false; // TODO: ugly
|
178
149
|
async function validateFile(file) {
|
179
|
-
var _eslintResultsByFile;
|
180
150
|
const moduleFilePath = `/${file}`; // TODO: check if this always works? (Windows?)
|
181
151
|
const start = Date.now();
|
182
152
|
const valModule = await service.get(moduleFilePath, "", {
|
@@ -184,21 +154,14 @@ async function validate({
|
|
184
154
|
schema: true,
|
185
155
|
validate: true
|
186
156
|
});
|
187
|
-
const fileContent = await fs.readFile(path.join(projectRoot, file), "utf-8");
|
188
|
-
const eslintResult = (_eslintResultsByFile = eslintResultsByFile) === null || _eslintResultsByFile === void 0 ? void 0 : _eslintResultsByFile[file];
|
189
157
|
const remoteFiles = {};
|
190
158
|
let remoteFileBuckets = null;
|
191
159
|
let remoteFilesCounter = 0;
|
192
|
-
|
193
|
-
// display surrounding code
|
194
|
-
logEslintMessage(fileContent, moduleFilePath, m);
|
195
|
-
});
|
196
|
-
if (!valModule.errors && (eslintResult === null || eslintResult === void 0 ? void 0 : eslintResult.errorCount) === 0) {
|
160
|
+
if (!valModule.errors) {
|
197
161
|
console.log(picocolors.green("✔"), moduleFilePath, "is valid (" + (Date.now() - start) + "ms)");
|
198
162
|
return 0;
|
199
163
|
} else {
|
200
|
-
|
201
|
-
let errors = ((_eslintResultsByFile2 = eslintResultsByFile) === null || _eslintResultsByFile2 === void 0 || (_eslintResultsByFile2 = _eslintResultsByFile2[file]) === null || _eslintResultsByFile2 === void 0 ? void 0 : _eslintResultsByFile2.messages.reduce((prev, m) => m.severity >= 2 ? prev + 1 : prev, 0)) || 0;
|
164
|
+
let errors = 0;
|
202
165
|
let fixedErrors = 0;
|
203
166
|
if (valModule.errors) {
|
204
167
|
if (valModule.errors.validation) {
|
@@ -465,28 +428,6 @@ async function validate({
|
|
465
428
|
service.dispose();
|
466
429
|
return;
|
467
430
|
}
|
468
|
-
function logEslintMessage(fileContent, filePath, eslintMessage) {
|
469
|
-
const lines = fileContent.split("\n");
|
470
|
-
const line = lines[eslintMessage.line - 1];
|
471
|
-
const lineBefore = lines[eslintMessage.line - 2];
|
472
|
-
const lineAfter = lines[eslintMessage.line];
|
473
|
-
const isError = eslintMessage.severity >= 2;
|
474
|
-
console.log(isError ? picocolors.red("✘") : picocolors.yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`, eslintMessage.message);
|
475
|
-
if (lineBefore) {
|
476
|
-
console.log(picocolors.gray(" " + (eslintMessage.line - 1) + " |"), lineBefore);
|
477
|
-
}
|
478
|
-
if (line) {
|
479
|
-
console.log(picocolors.gray(" " + eslintMessage.line + " |"), line);
|
480
|
-
}
|
481
|
-
// adds ^ below the relevant line:
|
482
|
-
const amountOfColumns = eslintMessage.endColumn && eslintMessage.endColumn - eslintMessage.column > 0 ? eslintMessage.endColumn - eslintMessage.column : 1;
|
483
|
-
if (line) {
|
484
|
-
console.log(picocolors.gray(" " + " ".repeat(eslintMessage.line.toString().length) + " |"), " ".repeat(eslintMessage.column - 1) + (eslintMessage.endColumn ? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(amountOfColumns) : ""));
|
485
|
-
}
|
486
|
-
if (lineAfter) {
|
487
|
-
console.log(picocolors.gray(" " + (eslintMessage.line + 1) + " |"), lineAfter);
|
488
|
-
}
|
489
|
-
}
|
490
431
|
|
491
432
|
// GPT generated levenshtein distance algorithm:
|
492
433
|
const levenshtein = (a, b) => {
|
@@ -708,7 +649,6 @@ async function main() {
|
|
708
649
|
Options:
|
709
650
|
--root [root], -r [root] Set project root directory (default process.cwd())
|
710
651
|
--fix [fix] Attempt to fix validation errors
|
711
|
-
--noEslint [noEslint] Disable eslint validation during validate
|
712
652
|
|
713
653
|
|
714
654
|
Command: login
|
@@ -780,8 +720,7 @@ async function main() {
|
|
780
720
|
}
|
781
721
|
return validate({
|
782
722
|
root: flags.root,
|
783
|
-
fix: flags.fix
|
784
|
-
noEslint: flags.noEslint
|
723
|
+
fix: flags.fix
|
785
724
|
});
|
786
725
|
default:
|
787
726
|
return error(`Unknown command "${input.join(" ")}"`);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/cli",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.81.0",
|
5
5
|
"description": "Val CLI tools",
|
6
6
|
"bin": {
|
7
7
|
"val": "./bin.js"
|
@@ -18,12 +18,11 @@
|
|
18
18
|
"typecheck": "tsc --noEmit"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
|
-
"@valbuild/core": "~0.80.0",
|
22
|
-
"@valbuild/server": "~0.80.0",
|
23
|
-
"@valbuild/eslint-plugin": "~0.80.0",
|
24
|
-
"eslint": "^8.31.0",
|
25
21
|
"@inquirer/confirm": "^2.0.15",
|
26
22
|
"@inquirer/prompts": "^3.0.2",
|
23
|
+
"@valbuild/core": "~0.81.0",
|
24
|
+
"@valbuild/eslint-plugin": "~0.81.0",
|
25
|
+
"@valbuild/server": "~0.81.0",
|
27
26
|
"chalk": "^4.1.2",
|
28
27
|
"cors": "^2.8.5",
|
29
28
|
"express": "^4.18.2",
|
package/src/cli.ts
CHANGED
@@ -26,7 +26,6 @@ async function main(): Promise<void> {
|
|
26
26
|
Options:
|
27
27
|
--root [root], -r [root] Set project root directory (default process.cwd())
|
28
28
|
--fix [fix] Attempt to fix validation errors
|
29
|
-
--noEslint [noEslint] Disable eslint validation during validate
|
30
29
|
|
31
30
|
|
32
31
|
Command: login
|
@@ -106,7 +105,6 @@ async function main(): Promise<void> {
|
|
106
105
|
return validate({
|
107
106
|
root: flags.root,
|
108
107
|
fix: flags.fix,
|
109
|
-
noEslint: flags.noEslint,
|
110
108
|
});
|
111
109
|
default:
|
112
110
|
return error(`Unknown command "${input.join(" ")}"`);
|
package/src/validate.ts
CHANGED
@@ -21,7 +21,6 @@ import {
|
|
21
21
|
} from "@valbuild/core";
|
22
22
|
import { glob } from "fast-glob";
|
23
23
|
import picocolors from "picocolors";
|
24
|
-
import { ESLint } from "eslint";
|
25
24
|
import fs from "fs/promises";
|
26
25
|
import { evalValConfigFile } from "./utils/evalValConfigFile";
|
27
26
|
import { getFileExt } from "./utils/getFileExt";
|
@@ -30,19 +29,13 @@ const textEncoder = new TextEncoder();
|
|
30
29
|
export async function validate({
|
31
30
|
root,
|
32
31
|
fix,
|
33
|
-
noEslint,
|
34
32
|
}: {
|
35
33
|
root?: string;
|
36
34
|
fix?: boolean;
|
37
|
-
noEslint?: boolean;
|
38
35
|
}) {
|
39
36
|
const valRemoteHost = process.env.VAL_REMOTE_HOST || DEFAULT_VAL_REMOTE_HOST;
|
40
37
|
const contentHostUrl = process.env.VAL_CONTENT_URL || DEFAULT_CONTENT_HOST;
|
41
38
|
const projectRoot = root ? path.resolve(root) : process.cwd();
|
42
|
-
const eslint = new ESLint({
|
43
|
-
cwd: projectRoot,
|
44
|
-
ignore: false,
|
45
|
-
});
|
46
39
|
const valConfigFile =
|
47
40
|
(await evalValConfigFile(projectRoot, "val.config.ts")) ||
|
48
41
|
(await evalValConfigFile(projectRoot, "val.config.js"));
|
@@ -107,42 +100,6 @@ export async function validate({
|
|
107
100
|
});
|
108
101
|
|
109
102
|
let errors = 0;
|
110
|
-
let eslintResults: ESLint.LintResult[] = [];
|
111
|
-
let eslintResultsByFile: Record<string, ESLint.LintResult> = {};
|
112
|
-
if (!noEslint) {
|
113
|
-
const lintFiles = await glob("**/*.{js,ts}", {
|
114
|
-
ignore: ["node_modules/**"],
|
115
|
-
cwd: projectRoot,
|
116
|
-
});
|
117
|
-
console.log("Running eslint...");
|
118
|
-
eslintResults = await eslint.lintFiles(lintFiles);
|
119
|
-
|
120
|
-
eslintResultsByFile = eslintResults.reduce(
|
121
|
-
(acc, result) => ({
|
122
|
-
...acc,
|
123
|
-
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result,
|
124
|
-
}),
|
125
|
-
{} as Record<string, ESLint.LintResult>,
|
126
|
-
);
|
127
|
-
eslintResults.forEach((result) => {
|
128
|
-
result.messages.forEach(async (m) => {
|
129
|
-
if (m.messageId === "val/export-content-must-be-valid") {
|
130
|
-
errors += 1;
|
131
|
-
logEslintMessage(
|
132
|
-
await fs.readFile(result.filePath, "utf-8"),
|
133
|
-
result.filePath,
|
134
|
-
m,
|
135
|
-
);
|
136
|
-
}
|
137
|
-
});
|
138
|
-
});
|
139
|
-
console.log(
|
140
|
-
errors === 0 ? picocolors.green("✔") : picocolors.red("✘"),
|
141
|
-
"ESlint complete",
|
142
|
-
lintFiles.length,
|
143
|
-
"files",
|
144
|
-
);
|
145
|
-
}
|
146
103
|
console.log(picocolors.greenBright(`Found ${valFiles.length} files...`));
|
147
104
|
let publicProjectId: string | undefined;
|
148
105
|
let didFix = false; // TODO: ugly
|
@@ -154,22 +111,13 @@ export async function validate({
|
|
154
111
|
schema: true,
|
155
112
|
validate: true,
|
156
113
|
});
|
157
|
-
const fileContent = await fs.readFile(
|
158
|
-
path.join(projectRoot, file),
|
159
|
-
"utf-8",
|
160
|
-
);
|
161
|
-
const eslintResult = eslintResultsByFile?.[file];
|
162
114
|
const remoteFiles: Record<
|
163
115
|
SourcePath,
|
164
116
|
{ ref: string; metadata?: Record<string, unknown> }
|
165
117
|
> = {};
|
166
118
|
let remoteFileBuckets: string[] | null = null;
|
167
119
|
let remoteFilesCounter = 0;
|
168
|
-
|
169
|
-
// display surrounding code
|
170
|
-
logEslintMessage(fileContent, moduleFilePath, m);
|
171
|
-
});
|
172
|
-
if (!valModule.errors && eslintResult?.errorCount === 0) {
|
120
|
+
if (!valModule.errors) {
|
173
121
|
console.log(
|
174
122
|
picocolors.green("✔"),
|
175
123
|
moduleFilePath,
|
@@ -177,11 +125,7 @@ export async function validate({
|
|
177
125
|
);
|
178
126
|
return 0;
|
179
127
|
} else {
|
180
|
-
let errors =
|
181
|
-
eslintResultsByFile?.[file]?.messages.reduce(
|
182
|
-
(prev, m) => (m.severity >= 2 ? prev + 1 : prev),
|
183
|
-
0,
|
184
|
-
) || 0;
|
128
|
+
let errors = 0;
|
185
129
|
let fixedErrors = 0;
|
186
130
|
if (valModule.errors) {
|
187
131
|
if (valModule.errors.validation) {
|
@@ -666,59 +610,6 @@ export async function validate({
|
|
666
610
|
return;
|
667
611
|
}
|
668
612
|
|
669
|
-
function logEslintMessage(
|
670
|
-
fileContent: string,
|
671
|
-
filePath: string,
|
672
|
-
eslintMessage: ESLint.LintResult["messages"][number],
|
673
|
-
) {
|
674
|
-
const lines = fileContent.split("\n");
|
675
|
-
const line = lines[eslintMessage.line - 1];
|
676
|
-
const lineBefore = lines[eslintMessage.line - 2];
|
677
|
-
const lineAfter = lines[eslintMessage.line];
|
678
|
-
const isError = eslintMessage.severity >= 2;
|
679
|
-
console.log(
|
680
|
-
isError ? picocolors.red("✘") : picocolors.yellow("⚠"),
|
681
|
-
isError ? "Found eslint error:" : "Found eslint warning:",
|
682
|
-
`${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`,
|
683
|
-
eslintMessage.message,
|
684
|
-
);
|
685
|
-
if (lineBefore) {
|
686
|
-
console.log(
|
687
|
-
picocolors.gray(" " + (eslintMessage.line - 1) + " |"),
|
688
|
-
lineBefore,
|
689
|
-
);
|
690
|
-
}
|
691
|
-
if (line) {
|
692
|
-
console.log(picocolors.gray(" " + eslintMessage.line + " |"), line);
|
693
|
-
}
|
694
|
-
// adds ^ below the relevant line:
|
695
|
-
const amountOfColumns =
|
696
|
-
eslintMessage.endColumn &&
|
697
|
-
eslintMessage.endColumn - eslintMessage.column > 0
|
698
|
-
? eslintMessage.endColumn - eslintMessage.column
|
699
|
-
: 1;
|
700
|
-
|
701
|
-
if (line) {
|
702
|
-
console.log(
|
703
|
-
picocolors.gray(
|
704
|
-
" " + " ".repeat(eslintMessage.line.toString().length) + " |",
|
705
|
-
),
|
706
|
-
" ".repeat(eslintMessage.column - 1) +
|
707
|
-
(eslintMessage.endColumn
|
708
|
-
? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(
|
709
|
-
amountOfColumns,
|
710
|
-
)
|
711
|
-
: ""),
|
712
|
-
);
|
713
|
-
}
|
714
|
-
if (lineAfter) {
|
715
|
-
console.log(
|
716
|
-
picocolors.gray(" " + (eslintMessage.line + 1) + " |"),
|
717
|
-
lineAfter,
|
718
|
-
);
|
719
|
-
}
|
720
|
-
}
|
721
|
-
|
722
613
|
// GPT generated levenshtein distance algorithm:
|
723
614
|
const levenshtein = (a: string, b: string): number => {
|
724
615
|
const [m, n] = [a.length, b.length];
|