Comparing version 1.1.0 to 1.2.0
#!/usr/bin/env node | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { generateBookmarks, mergeBookmarks } from "../src/index.js"; | ||
import { | ||
generateBookmarks, | ||
mergeBookmarks, | ||
convertBookmarks, | ||
} from "../src/index.js"; | ||
@@ -43,2 +47,24 @@ const getCommand = { | ||
const convertCommand = { | ||
command: "convert <bookmarks>", | ||
desc: "Local path of exported browser bookmarks", | ||
builder: (yargs) => { | ||
yargs.option("f", { | ||
alias: "filename", | ||
default: "converted-bookmarks.yaml", | ||
demandOption: false, | ||
describe: "The name you want to fice the converted YAML", | ||
type: "string", | ||
}); | ||
}, | ||
handler: (argv) => { | ||
console.log("COVERTING BOOKMARKS"); | ||
convertBookmarks.createBookmarks( | ||
argv.bookmarks, | ||
argv.directory, | ||
argv.filename | ||
); | ||
}, | ||
}; | ||
yargs(hideBin(process.argv)) | ||
@@ -58,2 +84,3 @@ .option("d", { | ||
.command(mergeCommand) | ||
.command(convertCommand) | ||
.help().argv; |
@@ -35,2 +35,2 @@ | ||
_These bookmarks were last updated on 06/01/2022, 14:13:55 using [Bookworms](https://github.com/thearegee/bookworms)_ | ||
_These bookmarks were last updated on 07/01/2022, 19:06:52 using [Bookworms](https://github.com/thearegee/bookworms)_ |
@@ -16,3 +16,2 @@ # Advanced usage | ||
```BASH | ||
$ cd output | ||
$ ls | ||
@@ -30,3 +29,3 @@ browsers.html readme.md | ||
`merge` works the same as `get` with the same options but it allows you to create bookmarks from multiple local or remote `YAML`. | ||
`merge` works in a similar way to `get` with the same options but it allows you to create bookmarks from multiple local or remote `YAML`. | ||
@@ -42,1 +41,25 @@ ```BASH | ||
``` | ||
## Covert | ||
`covert` works in a similar way to `get` with the same options. | ||
```BASH | ||
$ npx convert ./browsers.html -d="./output" | ||
``` | ||
```BASH | ||
$ ls | ||
converted-bookmarks.yaml | ||
``` | ||
You can also override the default filname. | ||
```BASH | ||
$ npx convert ./browsers.html -f="./my-bookmarks.yaml" | ||
``` | ||
```BASH | ||
$ ls | ||
my-bookmarks.yaml | ||
``` |
@@ -75,2 +75,12 @@ # Developers | ||
#### `convertBookmarks` | ||
A collection of helpers for converting browsers `HTML` export of bookmarks into `YAML`. | ||
- `parseHTMLtoJSON(path)` - browsers `HTML` export of bookmarks into JSON, this data is not normalised for Bookworms | ||
- `generateBookwormJSON(json)` - takes the `JSON` from `parseHTMLtoJSON` and normalises it into a format Bookworms understands | ||
- `traverseStructure(json)` - traverses `parseHTMLtoJSON` JSON to return a deep `JSON` structure for `generateBookwormJSON` | ||
- `convertHTMLtoYAML(path)` - Pass `HTML` to this function and it will return `YAML` that matches Bookmarks schema | ||
- `createBookmarks(path, directory, filename)` - Generate `YAML` from browsers `HTML` export of bookmarks and store to disk based on option | ||
## Contributing to Bookworms | ||
@@ -77,0 +87,0 @@ |
{ | ||
"name": "bookworms", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A cli tool for centralising and generating bookmarks", | ||
@@ -35,2 +35,5 @@ "main": "./src/index.js", | ||
"js-yaml": "^4.1.0", | ||
"json-stringify-safe": "^5.0.1", | ||
"uuid": "^8.3.2", | ||
"xml2json-light": "^1.0.6", | ||
"yargs": "^17.2.1" | ||
@@ -37,0 +40,0 @@ }, |
<p align="center"> | ||
<img width="50%" src="./docs/img/logo.png"> | ||
<a href="https://www.jamesbarryillustration.com/"> | ||
<img width="25%" src="./docs/img/logo.png"> | ||
</a> | ||
</p> | ||
> Centralise your bookmarks as `YAML` configuration and export them into different formats that can be used with your existing tools. | ||
> Centralise your bookmarks as `YAML` configuration and export files that can be used in your projects or imported into your browser. | ||
@@ -54,2 +56,5 @@ In a large company there are literally thousands of tools, environments and HR system URLs to remember. In a start up there maybe many less but in both scenarios there is probably no authority of truth and if there is, it is often out of date. | ||
If you already have bookmarks in your browser you can speed up the process of converting them into `YAML` using the `convert` tool, read more about that here: | ||
[Exporting existing bookmarks](./docs/EXPORTING-EXISTING-BOOKMARKS.md). | ||
Once this is ready you can pass it to Bookworms using [`npx`](https://nodejs.dev/learn/the-npx-nodejs-package-runner). | ||
@@ -75,3 +80,3 @@ | ||
For more information about how to use these files see: [Using your bookmarks](./docs/USING-YOUR-BOOKMARKS.md) or if you want to see other options available to you see: [Advanced usage](./docs/ADVANCED-USAGE.md). | ||
You can then import the `browsers.html` to display your bookmarks in your browser or the `readme.md` into your projects, for more information on how to use these files see [Using your bookmarks](./docs/USING-YOUR-BOOKMARKS.md) or if you want to see other options available to you see [Advanced usage](./docs/ADVANCED-USAGE.md). | ||
@@ -90,2 +95,3 @@ ## Help | ||
- [Using your bookmarks](./docs/USING-YOUR-BOOKMARKS.md) | ||
- [Exporting existing bookmarks](./docs/EXPORTING-EXISTING-BOOKMARKS.md) | ||
- [For developers](./docs/DEVELOPERS.md) | ||
@@ -95,3 +101,3 @@ | ||
- Convert existing exported bookmarks HTML into YAML | ||
- Test `convert` with browsers other than Chrome | ||
- Bug fix markdown generator header folder depth | ||
@@ -102,3 +108,3 @@ - Improve documentation for using bookworms modules | ||
## Future | ||
### Future | ||
@@ -110,1 +116,5 @@ - Create GitHub action to update bookmark repos without `npx` | ||
- Rewrite in TS | ||
## Credits | ||
The Bookworms logo was created by [James Barry Illustrations](https://www.jamesbarryillustration.com/). |
@@ -6,2 +6,3 @@ import { | ||
mergeBookmarks, | ||
convertBookmarks, | ||
} from "../index"; | ||
@@ -22,2 +23,5 @@ | ||
}); | ||
test("should return convertBookmarks", () => { | ||
expect(convertBookmarks).toBeDefined(); | ||
}); | ||
}); |
@@ -1,32 +0,48 @@ | ||
import { rmSync, readFileSync } from 'fs'; | ||
import {writeBookmarks, trimTrailingSlash} from '../save-bookmarks'; | ||
import { rmSync, readFileSync } from "fs"; | ||
import { | ||
writeBookmarks, | ||
writeBookmark, | ||
trimTrailingSlash, | ||
} from "../save-bookmarks"; | ||
describe('saving bookmarks', () => { | ||
describe('writeBookmarks', () => { | ||
test('should write bookmark files', () => { | ||
const path = './tmp' | ||
const bookmarks = [{ | ||
filename: 'browser.html', | ||
body: '<div>hello world</div>' | ||
}, | ||
{ | ||
filename: 'readme.md', | ||
body: '_hello world_' | ||
}]; | ||
writeBookmarks(path, bookmarks); | ||
bookmarks.forEach(({filename})=> { | ||
const bookmark = readFileSync(`${path}/${filename}`, 'utf8') | ||
expect(bookmark).toMatchSnapshot(); | ||
}); | ||
rmSync(path, { recursive: true }); | ||
}) | ||
}) | ||
describe('trimTrailingSlash', () => { | ||
test('should not change path without trailing slash', () => { | ||
expect(trimTrailingSlash('./demo/config')).toEqual('./demo/config') | ||
}) | ||
test('should change path removing trailing slash', () => { | ||
expect(trimTrailingSlash('./demo/config/')).toEqual('./demo/config') | ||
}) | ||
}) | ||
}) | ||
describe("saving bookmarks", () => { | ||
describe("writeBookmarks", () => { | ||
test("should write bookmark files", () => { | ||
const path = "./tmp"; | ||
const bookmarks = [ | ||
{ | ||
filename: "browser.html", | ||
body: "<div>hello world</div>", | ||
}, | ||
{ | ||
filename: "readme.md", | ||
body: "_hello world_", | ||
}, | ||
]; | ||
writeBookmarks(path, bookmarks); | ||
bookmarks.forEach(({ filename }) => { | ||
const bookmark = readFileSync(`${path}/${filename}`, "utf8"); | ||
expect(bookmark).toMatchSnapshot(); | ||
}); | ||
rmSync(path, { recursive: true }); | ||
}); | ||
}); | ||
describe("writeBookmark", () => { | ||
test("should write bookmark file", () => { | ||
const path = "./tmp"; | ||
const filename = "browser.html"; | ||
writeBookmark("<div>hello world</div>", "./tmp", "browser.html"); | ||
const bookmark = readFileSync(`${path}/${filename}`, "utf8"); | ||
expect(bookmark).toMatchSnapshot(); | ||
rmSync(path, { recursive: true }); | ||
}); | ||
}); | ||
describe("trimTrailingSlash", () => { | ||
test("should not change path without trailing slash", () => { | ||
expect(trimTrailingSlash("./demo/config")).toEqual("./demo/config"); | ||
}); | ||
test("should change path removing trailing slash", () => { | ||
expect(trimTrailingSlash("./demo/config/")).toEqual("./demo/config"); | ||
}); | ||
}); | ||
}); |
@@ -5,3 +5,10 @@ import * as loadBookmarks from "./load-bookmarks.js"; | ||
import * as mergeBookmarks from "./merge-bookmarks.js"; | ||
import * as convertBookmarks from "./convert-bookmarks.js"; | ||
export { loadBookmarks, generateBookmarks, saveBookmarks, mergeBookmarks }; | ||
export { | ||
loadBookmarks, | ||
generateBookmarks, | ||
saveBookmarks, | ||
mergeBookmarks, | ||
convertBookmarks, | ||
}; |
@@ -1,19 +0,23 @@ | ||
import { mkdirSync, writeFileSync } from 'fs'; | ||
import { mkdirSync, writeFileSync } from "fs"; | ||
const writeBookmarks = (directory, bookmarks) => { | ||
bookmarks.forEach(({filename, body})=> { | ||
try { | ||
mkdirSync(directory, { recursive: true}); | ||
writeFileSync(`${trimTrailingSlash(directory)}/${filename}`, body) | ||
} catch (error) { | ||
// todo write test for this error condition | ||
console.error(error.message) | ||
} | ||
}) | ||
} | ||
bookmarks.forEach(({ filename, body }) => { | ||
writeBookmark(body, directory, filename); | ||
}); | ||
}; | ||
const writeBookmark = (content, directory, filename) => { | ||
try { | ||
mkdirSync(directory, { recursive: true }); | ||
writeFileSync(`${trimTrailingSlash(directory)}/${filename}`, content); | ||
} catch (error) { | ||
// todo write test for this error condition | ||
console.error(error.message); | ||
} | ||
}; | ||
const trimTrailingSlash = (directory) => { | ||
return directory.replace(/\/$/, ""); | ||
} | ||
return directory.replace(/\/$/, ""); | ||
}; | ||
export {writeBookmarks, trimTrailingSlash} | ||
export { writeBookmarks, writeBookmark, trimTrailingSlash }; |
@@ -81,3 +81,3 @@ import { | ||
test("should return description comment", () => { | ||
expect(addDescription("hello world")).toEqual("hello world"); | ||
expect(addDescription("hello world")).toEqual("- hello world"); | ||
}); | ||
@@ -84,0 +84,0 @@ test("should return empty string", () => { |
@@ -28,3 +28,3 @@ const bookmark = (timeDate, label, description, children) => { | ||
return ` | ||
* [${label}](${href}) - ${addDescription(description)} | ||
* [${label}](${href}) ${addDescription(description)} | ||
`; | ||
@@ -43,3 +43,3 @@ }; | ||
if (description) { | ||
return `${description}`; | ||
return `- ${description}`; | ||
} else { | ||
@@ -46,0 +46,0 @@ return ``; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
286428
37
1191
115
6
5
+ Addedjson-stringify-safe@^5.0.1
+ Addeduuid@^8.3.2
+ Addedxml2json-light@^1.0.6
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedxml2json-light@1.0.6(transitive)