diff --git a/.gitignore b/.gitignore index 2e81726..fe6f7c5 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ typings/ # while testing npm5 package-lock.json yarn.lock +types \ No newline at end of file diff --git a/package.json b/package.json index 38727fa..3359db8 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,32 @@ "description": "Creates an HTTP response from an IPFS Hash", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", + "types": "./types/src/index.d.ts", + "type": "module", + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } + }, + "exports": { + ".": { + "import": "./src/index.js" + } + }, "scripts": { - "lint": "aegir lint", + "prepare": "aegir build --no-bundle && cp -R types dist", + "lint": "aegir ts -p check && aegir lint", "build": "aegir build", "release": "aegir release --target node", "release-minor": "aegir release --type minor --target node", + "pretest": "aegir build --esm-tests", "test": "aegir test -t node", "test:node": "aegir test -t node" }, "browser": { - "file-type": "file-type/browser" + "file-type": "file-type/browser", + "fs": false }, "repository": { "type": "git", @@ -32,8 +48,9 @@ "homepage": "https://github.com/ipfs/js-ipfs-http-response#readme", "dependencies": { "debug": "^4.3.1", + "ejs": "^3.1.6", "file-type": "^16.0.0", - "filesize": "^7.0.0", + "filesize": "^8.0.0", "it-buffer": "^0.1.1", "it-concat": "^2.0.0", "it-reader": "^3.0.0", @@ -43,13 +60,14 @@ "p-try-each": "^1.0.1" }, "devDependencies": { - "aegir": "^34.0.2", + "@types/ejs": "^3.1.0", + "aegir": "^35.0.3", "get-stream": "^6.0.0", - "ipfs-core": "^0.9.1", + "ipfs-core": "^0.10.5", "ipfsd-ctl": "^10.0.1", "it-all": "^1.0.5", "path": "^0.12.7", - "uint8arrays": "^2.0.5", + "uint8arrays": "^3.0.0", "util": "^0.12.3" }, "contributors": [ diff --git a/src/dir-view/index.js b/src/dir-view/index.js index aa42020..61afe89 100644 --- a/src/dir-view/index.js +++ b/src/dir-view/index.js @@ -1,12 +1,13 @@ -'use strict' - -const filesize = require('filesize') - -const mainStyle = require('./style') -const pathUtil = require('../utils/path') +import filesize from 'filesize' +import style from './style.js' +import { cidArray } from '../utils/path.js' +import ejs from 'ejs' +/** + * @param {string} path + */ function getParentHref (path) { - const parts = pathUtil.cidArray(path).slice() + const parts = cidArray(path).slice() if (parts.length > 1) { // drop the last segment in a safe way that works for both paths and urls return path.replace(`/${parts.pop()}`, '') @@ -14,68 +15,62 @@ function getParentHref (path) { return path } -function buildFilesList (path, links) { - const rows = links.map((link) => { - let row = [ - '
 
', - `${link.Name}`, - filesize(link.Tsize) - ] - - row = row.map((cell) => `${cell}`).join('') - - return `${row}` - }) - - return rows.join('') -} - -function buildTable (path, links) { - return ` - - - - - - - - ${buildFilesList(path, links)} - -
-
 
-
- .. -
- ` -} - -function render (path, links) { - return ` - - - - - ${path} - - - -