Skip to content

Commit

Permalink
Merge pull request #446 from gemal/20241101
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
gemal authored Nov 1, 2024
2 parents 159975a + 25a4a54 commit 6584d17
Show file tree
Hide file tree
Showing 7 changed files with 2,281 additions and 4,305 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
docker:
# Use node image
- image: circleci/node
- image: cimg/node:lts

# code folder
working_directory: ~/repo
Expand Down
20 changes: 0 additions & 20 deletions .eslintrc.json

This file was deleted.

17 changes: 17 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import globals from "globals";
import js from "@eslint/js";


export default [
{
languageOptions: {
globals: {
process: "readonly",
describe: "readonly",
it: "readonly",
...globals.browser
}
}
},
js.configs.recommended,
];
41 changes: 19 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

'use strict';

const recursive = require('recursive-readdir-sync');
const parseCssUrls = require('css-url-parser');
const fs = require('fs');
const path = require('path');
const isurl = require('is-url');
const {program} = require('commander');
import fs from 'fs';
import path from 'path';
import { program } from 'commander';
import recursive from 'recursive-readdir-sync';
import isUrl from 'is-url-superb';
import parseCssUrls from 'css-url-parser';

/**
* Check a folder.
* @return {number}
*/
function checkFolder() {
// Load package.json data
const packageJson = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url)));

async function checkFolder() {
let errors = 0;
const files = recursive(options.folder);

files.forEach(function(file) {
const ext = path.extname(file);
if (ext === '.css') {
const filePath = path.dirname(file) + path.sep;
const filecontent = fs.readFileSync(file, {encoding: 'utf-8'});
const filecontent = fs.readFileSync(file, { encoding: 'utf-8' });
const cssUrls = parseCssUrls(filecontent);
cssUrls.forEach(function(cssUrl) {
if (!isurl(cssUrl)) {
if (!isUrl(cssUrl)) {
const cssReal = cssUrl.replace(/(\?|#).*$/, '');
let fullPath = filePath + cssReal;
if (cssReal.charAt(0) === '/') {
Expand Down Expand Up @@ -52,8 +52,8 @@ function checkFolder() {
}

program
.version(require('./package.json').version)
.description('Checks if all images in CSS files exists')
.version(packageJson.version) // Use loaded JSON version
.description('Checks if all images in CSS files exist')
.option('-f, --folder <folder>', 'Folder with CSS files to check')
.option('-v, --verbose', 'Add more output')
.parse(process.argv);
Expand All @@ -63,18 +63,15 @@ if (options.folder) {
if (fs.existsSync(options.folder)) {
const stats = fs.statSync(options.folder);
if (stats.isDirectory()) {
const err = checkFolder();
if (err > 0) {
process.exitCode = 1;
} else {
process.exitCode = 0;
}
checkFolder().then((err) => {
process.exitCode = err > 0 ? 1 : 0;
});
} else {
console.log('Oops! Folder is not a real folder: ' + options.folder);
process.exitCode = 4;
}
} else {
console.log('Oops! Folder does not exists: ' + options.folder);
console.log('Oops! Folder does not exist: ' + options.folder);
process.exitCode = 3;
}
} else {
Expand Down
Loading

0 comments on commit 6584d17

Please sign in to comment.