mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
refactor(jsdoc-util): remove @jsdoc/util.fs
It was barely used. We now use `fast-glob` instead.
This commit is contained in:
parent
6bb9d58f9e
commit
39c0fde216
5
package-lock.json
generated
5
package-lock.json
generated
@ -5941,7 +5941,8 @@
|
|||||||
"node_modules/graceful-fs": {
|
"node_modules/graceful-fs": {
|
||||||
"version": "4.2.11",
|
"version": "4.2.11",
|
||||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
|
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/graphemer": {
|
"node_modules/graphemer": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
@ -7568,6 +7569,7 @@
|
|||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz",
|
||||||
"integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==",
|
"integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"graceful-fs": "^4.1.11"
|
"graceful-fs": "^4.1.11"
|
||||||
}
|
}
|
||||||
@ -13534,7 +13536,6 @@
|
|||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"klaw-sync": "^6.0.0",
|
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"ow": "^1.1.1"
|
"ow": "^1.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -19,17 +19,15 @@ import path from 'node:path';
|
|||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
import salty from '@jsdoc/salty';
|
import salty from '@jsdoc/salty';
|
||||||
import { fs as jsdocFs, log } from '@jsdoc/util';
|
import { log } from '@jsdoc/util';
|
||||||
import commonPathPrefix from 'common-path-prefix';
|
import commonPathPrefix from 'common-path-prefix';
|
||||||
import fastGlob from 'fast-glob';
|
import glob from 'fast-glob';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { Template } from './lib/template.js';
|
import { Template } from './lib/template.js';
|
||||||
import * as helper from './lib/templateHelper.js';
|
import * as helper from './lib/templateHelper.js';
|
||||||
|
|
||||||
const { htmlsafe, linkto, resolveAuthorLinks } = helper;
|
const { htmlsafe, linkto, resolveAuthorLinks } = helper;
|
||||||
const { lsSync } = jsdocFs;
|
|
||||||
const { sync: glob } = fastGlob;
|
|
||||||
const { resolve } = createRequire(import.meta.url);
|
const { resolve } = createRequire(import.meta.url);
|
||||||
const { taffy } = salty;
|
const { taffy } = salty;
|
||||||
|
|
||||||
@ -415,6 +413,8 @@ function buildNav(members, dependencies) {
|
|||||||
function sourceToDestination(parentDir, sourcePath, destDir) {
|
function sourceToDestination(parentDir, sourcePath, destDir) {
|
||||||
const relativeSource = path.relative(parentDir, sourcePath);
|
const relativeSource = path.relative(parentDir, sourcePath);
|
||||||
|
|
||||||
|
console.log(`sourcePath: ${sourcePath}\nrelativeSource: ${relativeSource}`);
|
||||||
|
|
||||||
return path.resolve(path.join(destDir, relativeSource));
|
return path.resolve(path.join(destDir, relativeSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,6 +453,9 @@ export function publish(docletStore, dependencies) {
|
|||||||
templateConfig = config.templates || {};
|
templateConfig = config.templates || {};
|
||||||
templateConfig.default = templateConfig.default || {};
|
templateConfig.default = templateConfig.default || {};
|
||||||
outdir = path.normalize(opts.destination);
|
outdir = path.normalize(opts.destination);
|
||||||
|
if (!path.isAbsolute(outdir)) {
|
||||||
|
outdir = path.resolve(process.cwd(), outdir);
|
||||||
|
}
|
||||||
templatePath = __dirname;
|
templatePath = __dirname;
|
||||||
view = new Template(path.join(templatePath, 'tmpl'));
|
view = new Template(path.join(templatePath, 'tmpl'));
|
||||||
|
|
||||||
@ -523,26 +526,30 @@ export function publish(docletStore, dependencies) {
|
|||||||
|
|
||||||
// copy the template's static files to outdir
|
// copy the template's static files to outdir
|
||||||
fromDir = path.join(templatePath, 'static');
|
fromDir = path.join(templatePath, 'static');
|
||||||
staticFiles = lsSync(fromDir);
|
staticFiles = glob.sync('**/*', {
|
||||||
|
cwd: fromDir,
|
||||||
|
onlyFiles: true,
|
||||||
|
});
|
||||||
|
|
||||||
staticFiles.forEach((fileName) => {
|
staticFiles.forEach((fileName) => {
|
||||||
const toPath = sourceToDestination(fromDir, fileName, outdir);
|
const toPath = path.join(outdir, fileName);
|
||||||
|
|
||||||
mkdirpSync(path.dirname(toPath));
|
mkdirpSync(path.dirname(toPath));
|
||||||
fs.copyFileSync(fileName, toPath);
|
fs.copyFileSync(path.join(fromDir, fileName), toPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
// copy the fonts used by the template to outdir
|
// copy the fonts used by the template to outdir
|
||||||
staticFiles = lsSync(path.join(resolve('@fontsource-variable/open-sans'), '..', 'files'));
|
fromDir = path.join(resolve('@fontsource-variable/open-sans'), '..', 'files');
|
||||||
|
staticFiles = glob.sync('**/*standard-{normal,italic}*', {
|
||||||
|
cwd: fromDir,
|
||||||
|
onlyFiles: true,
|
||||||
|
});
|
||||||
|
|
||||||
staticFiles.forEach((fileName) => {
|
staticFiles.forEach((fileName) => {
|
||||||
const toPath = path.join(outdir, 'fonts', path.basename(fileName));
|
const toPath = path.join(outdir, 'fonts', path.basename(fileName));
|
||||||
const name = path.parse(fileName).name;
|
|
||||||
|
|
||||||
if (name.includes('standard-normal') || name.includes('standard-italic')) {
|
mkdirpSync(path.dirname(toPath));
|
||||||
mkdirpSync(path.dirname(toPath));
|
fs.copyFileSync(path.join(fromDir, fileName), toPath);
|
||||||
fs.copyFileSync(fileName, toPath);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// copy the font CSS to outdir
|
// copy the font CSS to outdir
|
||||||
@ -591,7 +598,7 @@ export function publish(docletStore, dependencies) {
|
|||||||
// with a bug in JSDoc 3.2.x.
|
// with a bug in JSDoc 3.2.x.
|
||||||
staticFilePaths =
|
staticFilePaths =
|
||||||
templateConfig.default.staticFiles.include || templateConfig.default.staticFiles.paths || [];
|
templateConfig.default.staticFiles.include || templateConfig.default.staticFiles.paths || [];
|
||||||
staticFilePaths = glob(staticFilePaths, {
|
staticFilePaths = glob.sync(staticFilePaths, {
|
||||||
absolute: true,
|
absolute: true,
|
||||||
onlyFiles: true,
|
onlyFiles: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,8 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
import EventBus from './lib/bus.js';
|
import EventBus from './lib/bus.js';
|
||||||
import cast from './lib/cast.js';
|
import cast from './lib/cast.js';
|
||||||
import * as fs from './lib/fs.js';
|
|
||||||
import log from './lib/log.js';
|
import log from './lib/log.js';
|
||||||
|
|
||||||
export { cast, EventBus, fs, log };
|
export { cast, EventBus, log };
|
||||||
export default { cast, EventBus, fs, log };
|
export default { cast, EventBus, log };
|
||||||
|
|||||||
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 the JSDoc Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @alias @jsdoc/util.fs
|
|
||||||
*/
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import klawSync from 'klaw-sync';
|
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
export function lsSync(dir, opts = {}) {
|
|
||||||
const depth = _.has(opts, 'depth') ? opts.depth : -1;
|
|
||||||
|
|
||||||
const files = klawSync(dir, {
|
|
||||||
depthLimit: depth,
|
|
||||||
filter: (f) => !path.basename(f.path).startsWith('.'),
|
|
||||||
nodir: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return files.map((f) => f.path);
|
|
||||||
}
|
|
||||||
@ -31,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"klaw-sync": "^6.0.0",
|
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"ow": "^1.1.1"
|
"ow": "^1.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
import util from '../../index.js';
|
import util from '../../index.js';
|
||||||
import bus from '../../lib/bus.js';
|
import bus from '../../lib/bus.js';
|
||||||
import cast from '../../lib/cast.js';
|
import cast from '../../lib/cast.js';
|
||||||
import * as fs from '../../lib/fs.js';
|
|
||||||
|
|
||||||
describe('@jsdoc/util', () => {
|
describe('@jsdoc/util', () => {
|
||||||
it('is an object', () => {
|
it('is an object', () => {
|
||||||
@ -34,10 +33,4 @@ describe('@jsdoc/util', () => {
|
|||||||
expect(util.EventBus).toEqual(bus);
|
expect(util.EventBus).toEqual(bus);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fs', () => {
|
|
||||||
it('is lib/fs', () => {
|
|
||||||
expect(util.fs).toEqual(fs);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 the JSDoc Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import mockFs from 'mock-fs';
|
|
||||||
|
|
||||||
import * as fsUtil from '../../../lib/fs.js'; // eslint-disable-line sort-imports
|
|
||||||
|
|
||||||
describe('@jsdoc/util/lib/fs', () => {
|
|
||||||
afterEach(() => mockFs.restore());
|
|
||||||
|
|
||||||
it('has an lsSync method', () => {
|
|
||||||
expect(fsUtil.lsSync).toBeFunction();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('lsSync', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockFs({
|
|
||||||
head: {
|
|
||||||
eyes: '',
|
|
||||||
ears: '',
|
|
||||||
mouth: '',
|
|
||||||
nose: '',
|
|
||||||
shoulders: {
|
|
||||||
knees: {
|
|
||||||
meniscus: '',
|
|
||||||
toes: {
|
|
||||||
phalanx: '',
|
|
||||||
'.big-toe-phalanx': '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const cwd = process.cwd();
|
|
||||||
|
|
||||||
function resolvePaths(files) {
|
|
||||||
return files.map((f) => path.join(cwd, f)).sort();
|
|
||||||
}
|
|
||||||
|
|
||||||
const allFiles = resolvePaths([
|
|
||||||
'head/eyes',
|
|
||||||
'head/ears',
|
|
||||||
'head/mouth',
|
|
||||||
'head/nose',
|
|
||||||
'head/shoulders/knees/meniscus',
|
|
||||||
'head/shoulders/knees/toes/phalanx',
|
|
||||||
]);
|
|
||||||
|
|
||||||
it('gets all non-hidden files from all levels by default', () => {
|
|
||||||
const files = fsUtil.lsSync(cwd).sort();
|
|
||||||
|
|
||||||
expect(files).toEqual(allFiles);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('limits recursion depth when asked', () => {
|
|
||||||
const files = fsUtil.lsSync(cwd, { depth: 1 }).sort();
|
|
||||||
|
|
||||||
expect(files).toEqual(resolvePaths(['head/eyes', 'head/ears', 'head/mouth', 'head/nose']));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('treats a depth of -1 as infinite', () => {
|
|
||||||
const files = fsUtil.lsSync('head', { depth: -1 }).sort();
|
|
||||||
|
|
||||||
expect(files).toEqual(allFiles);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user