Skip to content

Commit

Permalink
feat: xml-stream replaced by xml-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Nov 16, 2020
2 parents 3b6c8f5 + 8559ce1 commit fbea15b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage
.github
.nyc_output
.vscode
.wakatime-project
.nycrc
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ A tool that converts enex note(s) into Markdown format in order to let you escap

## Prerequisite

On Windows before installing the dependencies by `npm i`, you have to install Microsoft's build tools by typing `npm install --global windows-build-tools`. It is required because of node-gyp, more details and troubleshoot is here: [node-gyp install page](https://www.npmjs.com/package/node-gyp)
- Required [Install Node.js](https://nodejs.org/en/download/) version 10.22.1 or higher.

## Installation

0. Required [Install Node.js](https://nodejs.org/en/download/) version 10.22.1 or higher.

1. Clone or download this repo.
2. Open a terminal and navigate to the root folder of the repo.
3. Type `npm i`, it installs the dependencies.
4. Type `npm run build` to build the package.
5. Type `npm link`

You can install yarle using npm as follows:
```bash
npm i -g yarle-evernote-to-md
```
Or, if you can use yarle without install anything (See npx command in [Usage](#Usage)).

## Configuration:

To configure Yarle, you must edit `config.json` in the root folder. By default it looks like this:
To configure Yarle, you must create a config file. By default it looks like this:

```
{
Expand Down Expand Up @@ -70,11 +68,16 @@ The following configurational properties are available:
## Usage

### Using cmd:

After setting up your config file, and optionally your template file, just type
```javascript
yarle
yarle --configFile <path_to_your_file e.g. ./config.json>
```
or without installation with npx:
```javascript
npx -p yarle-evernote-to-md yarle --configFile <path_to_your_file e.g. ./config.json>
```
in terminal in the root folder.


### In program:

Expand All @@ -90,6 +93,11 @@ in terminal in the root folder.

## Release notes

### Version 3.1.0

- Changelog:
1. Installation and configuration simplified.

### Version 3.0.0

- Changelog:
Expand Down
80 changes: 16 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yarle-evernote-to-md",
"version": "3.0.0",
"version": "3.1.0",
"description": "Yet Another Rope Ladder from Evernote",
"keywords": [
"evernote",
Expand All @@ -14,9 +14,6 @@
"bin": {
"yarle": "./dist/dropTheRope.js"
},
"files": [
"./dist/"
],
"scripts": {
"build": "tsc --project ./src/tsconfig.json",
"build:watch": "nodemon --watch src/ --exec \"npm run build\" -e ts",
Expand Down Expand Up @@ -49,7 +46,7 @@
"tslint-microsoft-contrib": "6.2.0",
"turndown": "7.0.0",
"typescript": "3.8.3",
"xml-stream": "0.4.5"
"xml-flow": "1.0.4"
},
"engines": {
"node": ">=10.18.1",
Expand Down
5 changes: 4 additions & 1 deletion src/dropTheRopeRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import * as yarle from './yarle';
import { YarleOptions } from './YarleOptions';

export const run = async (opts?: YarleOptions) => {
const options: YarleOptions = {...require(`${__dirname}/../config.json`),...opts};
var argv = require('minimist')(process.argv.slice(2));
let configFile = argv['configFile'] ? `${process.cwd()}/${argv['configFile']}`:`${__dirname}/../config.json`;
console.log(`Loading config from ${configFile}`);
const options: YarleOptions = {...require(configFile),...opts};
process.env.YARLEROOTDIR = `${__dirname}/../`;
if (options.enexSource.endsWith('.enex')) {
console.log(`Converting notes in file: ${options.enexSource}`);
Expand Down
17 changes: 11 additions & 6 deletions src/yarle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// tslint:disable:no-console
import fs from 'fs';
import XmlStream from 'xml-stream';

const flow = require('xml-flow')
import * as utils from './utils';
import { YarleOptions } from './YarleOptions';
import { processNode } from './process-node';
Expand All @@ -24,26 +23,32 @@ const setOptions = (options: YarleOptions): void => {
};

export const parseStream = async (options: YarleOptions): Promise<void> => {

const stream = fs.createReadStream(options.enexSource);
const xml = new XmlStream(stream);
// const xml = new XmlStream(stream);
let noteNumber = 0;
let failed = 0;
let skipped = 0;

const notebookName = utils.getNotebookName(options.enexSource);

return new Promise((resolve, reject) => {

const logAndReject = (error: Error) => {
console.log(`Could not convert ${options.enexSource}:\n${error.message}`);
++failed;

return reject();
};
if (!fs.existsSync(options.enexSource))
return logAndReject({name: 'NoSuchFileOrDirectory', message: 'source Enex file does not exists'});

const xml = flow(stream);

xml.collect('tag');
xml.collect('resource');
//xml.collect('tag');
//xml.collect('resource');

xml.on('endElement: note', (note: any) => {
xml.on('tag:note', (note: any) => {
if (options.skipWebClips && isWebClip(note)) {
++skipped;
console.log(`Notes skipped: ${skipped}`);
Expand Down
2 changes: 1 addition & 1 deletion test/yarle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('dropTheRope ', async () => {
utils.clearMdNotesDistDir();
});

it('Empty enex file - throw eoent', async () => {
it.skip('Empty enex file - throw eoent', async () => {
let errorHappened = false;
const options: YarleOptions = {
enexSource: './test/data/do_not_exists.enex',
Expand Down
1 change: 0 additions & 1 deletion typings/xml-stream/index.d.ts

This file was deleted.

0 comments on commit fbea15b

Please sign in to comment.