Skip to content

Commit fbcaaed

Browse files
committed
feat: ESM, update to multiformats, auto-release etc.
1 parent 9dfdb05 commit fbcaaed

File tree

7 files changed

+216
-85
lines changed

7 files changed

+216
-85
lines changed

.github/dependabot.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'github-actions'
4+
directory: '/'
5+
schedule:
6+
interval: 'daily'
7+
commit-message:
8+
prefix: 'chore'
9+
include: 'scope'
10+
- package-ecosystem: 'npm'
11+
directory: '/'
12+
schedule:
13+
interval: 'daily'
14+
commit-message:
15+
prefix: 'chore'
16+
include: 'scope'

.github/workflows/mikeals-workflow.yml

-50
This file was deleted.
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Test & Maybe Release
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
strategy:
6+
fail-fast: false
7+
matrix:
8+
node: [14.x, 16.x]
9+
os: [macos-latest, ubuntu-latest]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v3
14+
- name: Use Node.js ${{ matrix.node }}
15+
uses: actions/[email protected]
16+
with:
17+
node-version: ${{ matrix.node }}
18+
- name: Install Dependencies
19+
run: |
20+
npm install --no-progress
21+
- name: Run tests
22+
run: |
23+
npm test
24+
test-windows:
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
node: [14.x, 16.x]
29+
os: [windows-latest]
30+
runs-on: ${{ matrix.os }}
31+
steps:
32+
- name: Checkout Repository
33+
uses: actions/checkout@v3
34+
- name: Use Node.js ${{ matrix.node }}
35+
uses: actions/[email protected]
36+
with:
37+
node-version: ${{ matrix.node }}
38+
- name: Install Dependencies
39+
run: |
40+
npm install --no-progress
41+
- name: Run tests
42+
run: |
43+
npm run test:node
44+
release:
45+
name: Release
46+
needs: [test, test-windows]
47+
runs-on: ubuntu-latest
48+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
with:
53+
fetch-depth: 0
54+
- name: Setup Node.js
55+
uses: actions/[email protected]
56+
with:
57+
node-version: 14
58+
- name: Install dependencies
59+
run: |
60+
npm install --no-progress --no-package-lock --no-save
61+
- name: Build
62+
run: |
63+
npm run build
64+
- name: Install plugins
65+
run: |
66+
npm install \
67+
@semantic-release/commit-analyzer \
68+
conventional-changelog-conventionalcommits \
69+
@semantic-release/release-notes-generator \
70+
@semantic-release/npm \
71+
@semantic-release/github \
72+
@semantic-release/git \
73+
@semantic-release/changelog \
74+
--no-progress --no-package-lock --no-save
75+
- name: Release
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
79+
run: npx semantic-release
80+

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
Convert a decoded IPLD value to a colored printable string
44

55
```javascript
6-
const printify = require('@ipld/printify')
7-
const CID = require('cids')
6+
import printify from '@ipld/printify'
7+
import { CID } from 'multiformats/cid'
88

99
console.log(printify({
1010
one: 1,
1111
two: 'two',
1212
three: {
13-
link: new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'),
14-
binary: Buffer.from('hello world')
13+
link: CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'),
14+
binary: new TextEncoder().encode('hello world')
1515
}
1616
}))
1717
```

index.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const chalk = require('chalk')
2-
const CID = require('cids')
1+
import chalk from 'chalk'
2+
import { CID } from 'multiformats/cid'
33

44
const _pre = obj => {
55
if (Array.isArray(obj)) return '['
@@ -10,26 +10,28 @@ const _post = obj => {
1010
return '}'
1111
}
1212

13-
module.exports = (obj, indent = 0, threshold = 80) => {
14-
let pre = Array.from({ length: indent }).map(() => ' ').join('')
15-
let lines = []
16-
for (let key in obj) {
17-
let value = obj[key]
13+
function printify (obj, indent = 0, threshold = 80) {
14+
const pre = Array.from({ length: indent }).map(() => ' ').join('')
15+
const lines = []
16+
for (const key in obj) {
17+
const value = obj[key]
1818
let line
1919
if (Array.isArray(obj)) {
2020
line = ''
2121
} else {
2222
line = chalk.green(key) + ': '
2323
}
24-
if (CID.isCID(value)) lines.push(line + 'CID(' + chalk.red(value.toString()) + ')')
25-
else if (Buffer.isBuffer(value)) lines.push(line + 'Bytes(' + `{${chalk.green('size')}: ${chalk.red(value.length)}})`)
24+
if (CID.asCID(value)) lines.push(line + 'CID(' + chalk.red(value.toString()) + ')')
25+
else if (value instanceof Uint8Array) lines.push(line + 'Bytes(' + `{${chalk.green('size')}: ${chalk.red(value.length)}})`)
2626
else if (typeof value === 'object' && value !== null) {
27-
lines.push(line + module.exports(value, indent + 2, threshold - line.length))
27+
lines.push(line + printify(value, indent + 2, threshold - line.length))
2828
} else {
2929
lines.push(line + chalk.red(JSON.stringify(value)))
3030
}
3131
}
3232
if (lines.join(', ').length < threshold) return _pre(obj) + ' ' + lines.join(', ') + ' ' + _post(obj)
33-
let ipre = '\n' + pre + ' '
33+
const ipre = '\n' + pre + ' '
3434
return _pre(obj) + ipre + lines.join(ipre) + '\n' + pre + _post(obj)
3535
}
36+
37+
export default printify

package.json

+94-8
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
"version": "0.0.0",
44
"description": "Convert a decoded IPLD value to a colored printable string",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
8+
"build": "npm run lint",
9+
"lint": "standard",
710
"test": "mocha test/*.spec.js"
811
},
912
"keywords": [],
1013
"author": "Mikeal Rogers <[email protected]> (https://www.mikealrogers.com/)",
1114
"license": "(Apache-2.0 AND MIT)",
1215
"dependencies": {
13-
"chalk": "^2.4.2",
14-
"cids": "^0.7.1"
16+
"chalk": "^5.0.1",
17+
"multiformats": "^9.6.5"
1518
},
1619
"devDependencies": {
17-
"mocha": "^6.1.4",
18-
"standard": "^12.0.1",
19-
"tsame": "^2.0.1"
20+
"chai": "^4.3.6",
21+
"mocha": "^10.0.0",
22+
"standard": "^17.0.0"
2023
},
21-
"directories": {
22-
"test": "test"
24+
"exports": {
25+
".": {
26+
"import": "./index.js"
27+
}
2328
},
2429
"repository": {
2530
"type": "git",
@@ -28,5 +33,86 @@
2833
"bugs": {
2934
"url": "https://github.com/ipld/js-printify/issues"
3035
},
31-
"homepage": "https://github.com/ipld/js-printify#readme"
36+
"homepage": "https://github.com/ipld/js-printify#readme",
37+
"release": {
38+
"branches": [
39+
"master"
40+
],
41+
"plugins": [
42+
[
43+
"@semantic-release/commit-analyzer",
44+
{
45+
"preset": "conventionalcommits",
46+
"releaseRules": [
47+
{
48+
"breaking": true,
49+
"release": "major"
50+
},
51+
{
52+
"revert": true,
53+
"release": "patch"
54+
},
55+
{
56+
"type": "feat",
57+
"release": "minor"
58+
},
59+
{
60+
"type": "fix",
61+
"release": "patch"
62+
},
63+
{
64+
"type": "chore",
65+
"release": "patch"
66+
},
67+
{
68+
"type": "docs",
69+
"release": "patch"
70+
},
71+
{
72+
"type": "test",
73+
"release": "patch"
74+
},
75+
{
76+
"scope": "no-release",
77+
"release": false
78+
}
79+
]
80+
}
81+
],
82+
[
83+
"@semantic-release/release-notes-generator",
84+
{
85+
"preset": "conventionalcommits",
86+
"presetConfig": {
87+
"types": [
88+
{
89+
"type": "feat",
90+
"section": "Features"
91+
},
92+
{
93+
"type": "fix",
94+
"section": "Bug Fixes"
95+
},
96+
{
97+
"type": "chore",
98+
"section": "Trivial Changes"
99+
},
100+
{
101+
"type": "docs",
102+
"section": "Trivial Changes"
103+
},
104+
{
105+
"type": "test",
106+
"section": "Tests"
107+
}
108+
]
109+
}
110+
}
111+
],
112+
"@semantic-release/changelog",
113+
"@semantic-release/npm",
114+
"@semantic-release/github",
115+
"@semantic-release/git"
116+
]
117+
}
32118
}

test/basics.spec.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
const CID = require('cids')
2-
const assert = require('assert')
3-
const tsame = require('tsame')
4-
const printify = require('../')
1+
/* eslint-env mocha */
52

6-
const same = (...args) => assert.ok(tsame(...args))
7-
const test = it
3+
import { CID } from 'multiformats/cid'
4+
import { assert } from 'chai'
5+
import printify from '../index.js'
86

9-
test('all', done => {
10-
let str = printify({
7+
it('all', () => {
8+
const str = printify({
119
one: 1,
1210
two: 'two',
1311
three: {
1412
sub: 1,
15-
cid: new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'),
16-
binary: Buffer.from('asdf'),
13+
cid: CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'),
14+
binary: new TextEncoder().encode('asdf'),
1715
array: [
1816
'one',
1917
'two',
2018
3
2119
]
2220
}
2321
})
24-
same(str, "{\n \u001b[32mone\u001b[39m: \u001b[31m1\u001b[39m\n \u001b[32mtwo\u001b[39m: \u001b[31m\"two\"\u001b[39m\n \u001b[32mthree\u001b[39m: {\n \u001b[32msub\u001b[39m: \u001b[31m1\u001b[39m\n \u001b[32mcid\u001b[39m: CID(\u001b[31mQmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u\u001b[39m)\n \u001b[32mbinary\u001b[39m: Bytes({\u001b[32msize\u001b[39m: \u001b[31m4\u001b[39m})\n \u001b[32marray\u001b[39m: [ \u001b[31m\"one\"\u001b[39m, \u001b[31m\"two\"\u001b[39m, \u001b[31m3\u001b[39m ]\n }\n}")
25-
done()
22+
assert.equal(str, '{\n \u001b[32mone\u001b[39m: \u001b[31m1\u001b[39m\n \u001b[32mtwo\u001b[39m: \u001b[31m"two"\u001b[39m\n \u001b[32mthree\u001b[39m: {\n \u001b[32msub\u001b[39m: \u001b[31m1\u001b[39m\n \u001b[32mcid\u001b[39m: CID(\u001b[31mQmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u\u001b[39m)\n \u001b[32mbinary\u001b[39m: Bytes({\u001b[32msize\u001b[39m: \u001b[31m4\u001b[39m})\n \u001b[32marray\u001b[39m: [ \u001b[31m"one"\u001b[39m, \u001b[31m"two"\u001b[39m, \u001b[31m3\u001b[39m ]\n }\n}')
2623
})

0 commit comments

Comments
 (0)