Skip to content

Commit

Permalink
bring in tools used by other lightward repos
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacbowen committed Jul 3, 2023
1 parent 5514652 commit f501ea4
Show file tree
Hide file tree
Showing 8 changed files with 1,378 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm test
npm test && npx lint-staged
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.tabSize": 2,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": ["source.formatDocument"]
}
6 changes: 3 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const util = require('./util')
const util = require('./util');

util.formatJsonFiles()
util.buildDocs()
util.formatJsonFiles();
util.buildDocs();
57 changes: 32 additions & 25 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
const dirCompare = require('dir-compare')
const fs = require('fs')
const glob = require('glob')
const dirCompare = require('dir-compare');
const fs = require('fs');
const glob = require('glob');

const util = require('./util')
const util = require('./util');

const tasksFiles = glob.sync('tasks/*')
const tasksFiles = glob.sync('tasks/*');

const invalidFilenames = tasksFiles.filter(f => !f.match(/^tasks\/[0-9a-z-]+\.json$/))
const invalidFilenames = tasksFiles.filter(
(f) => !f.match(/^tasks\/[0-9a-z-]+\.json$/),
);

if (invalidFilenames.length > 0) {
console.error(`Invalid filenames in tasks/:\n${invalidFilenames.join("\n")}`)
throw `Found ${invalidFilenames.length} unexpected file(s) in tasks/`
console.error(`Invalid filenames in tasks/:\n${invalidFilenames.join('\n')}`);
throw `Found ${invalidFilenames.length} unexpected file(s) in tasks/`;
}

tasksFiles.forEach(path => {
const json = fs.readFileSync(path, 'UTF-8')
tasksFiles.forEach((path) => {
const json = fs.readFileSync(path, 'UTF-8');

let data;

try {
data = JSON.parse(json)
data = JSON.parse(json);
} catch (error) {
throw `Found invalid JSON in ${path}`
throw `Found invalid JSON in ${path}`;
}

if (!json.match(/^ "/m)) {
throw `Found a JSON file that appears to not be formatted with two-space indentation: ${path}`
throw `Found a JSON file that appears to not be formatted with two-space indentation: ${path}`;
}

if (!json.match(/\n$/)) {
throw `Found a JSON file that does not have a trailing newline: ${path}`
throw `Found a JSON file that does not have a trailing newline: ${path}`;
}

if (data.script.match(/^\s*\t/m)) {
throw `Found a task that appears to use literal tab characters for indentation (only two-space indentation is allowed): ${path}`
throw `Found a task that appears to use literal tab characters for indentation (only two-space indentation is allowed): ${path}`;
}
})
});

util.validateTasks()
util.validateTasks();

try {
util.buildDocs('.test-docs', {silent: true, validate: false})
util.buildDocs('.test-docs', {silent: true, validate: false});
} catch (error) {
fs.rmSync('.test-docs', {recursive: true})
fs.rmSync('.test-docs', {recursive: true});

throw `Caught an error while building to .test-docs: ${error}`
throw `Caught an error while building to .test-docs: ${error}`;
}

const comparison = dirCompare.compareSync('docs', '.test-docs', {compareContent: true})
fs.rmSync('.test-docs', {recursive: true})
const comparison = dirCompare.compareSync('docs', '.test-docs', {
compareContent: true,
});
fs.rmSync('.test-docs', {recursive: true});

if (!comparison.same) {
console.error(`Differing content:`, comparison.diffSet.filter(d => d.state !== 'equal'))
console.error(
`Differing content:`,
comparison.diffSet.filter((d) => d.state !== 'equal'),
);

throw './docs directory appears to not be up to date; please run `npm run build`'
throw './docs directory appears to not be up to date; please run `npm run build`';
}

console.log('Everything looks good! 🚀')
console.log('Everything looks good! 🚀');
Loading

0 comments on commit f501ea4

Please sign in to comment.