Skip to content

Commit

Permalink
Enhancement: Implement ConvertCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Nov 15, 2022
1 parent 51cb875 commit ffe0783
Show file tree
Hide file tree
Showing 141 changed files with 6,059 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.github/ export-ignore
/.phive/ export-ignore
/demo/ export-ignore
/test/ export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: "Collect code coverage with Xdebug and phpunit/phpunit"
env:
XDEBUG_MODE: "coverage"
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml"

- name: "Send code coverage report to codecov.io"
uses: "codecov/codecov-action@v3.1.1"
Expand Down Expand Up @@ -319,4 +319,7 @@ jobs:
dependencies: "${{ matrix.dependencies }}"

- name: "Run unit tests with phpunit/phpunit"
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml vendor/bin/phpunit -testsuite=unit"

- name: "Run unit tests with phpunit/phpunit"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml vendor/bin/phpunit -testsuite=integration"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.build/
/.notes/
/demo/obsidian/
!/demo/obsidian/.gitkeep
/vendor/
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
])
->ignoreDotFiles(false)
->in(__DIR__)
->name('day-one-to-obsidian-converter')
->name('.php-cs-fixer.php');

$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ it: coding-standards static-code-analysis tests ## Runs the coding-standards, st
.PHONY: code-coverage
code-coverage: vendor ## Collects coverage from running unit tests with phpunit/phpunit
mkdir -p .build/phpunit
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml --coverage-text
vendor/bin/phpunit --configuration=test/phpunit.xml --coverage-text --testsuite=unit,integration

.PHONY: coding-standards
coding-standards: vendor ## Normalizes composer.json with ergebnis/composer-normalize, lints YAML files with yamllint and fixes code style issues with friendsofphp/php-cs-fixer
Expand Down Expand Up @@ -41,7 +41,8 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
.PHONY: tests
tests: vendor ## Runs unit tests with phpunit/phpunit
mkdir -p .build/phpunit
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml
vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=unit
vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=integration

vendor: composer.json composer.lock
composer validate --strict
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ composer require ergebnis/day-one-to-obsidian-converter

## Usage

:bulb: This is a great place for showing a few usage examples!
Run

```sh
bin/day-one-to-obsidian-converter <day-one-directory> <obsidian-vault-directory>
```

The command will

- look for JSON files in `<day-one-directory>`
- convert JSON files that match the JSON Schema in [`resource/day-one/schema.json`](resource/day-one/schema.json) to Markdown files in `<obsidian-vault-directory>`

Ideally, the `<obsidian-vault-directory>` should not exist yet.

## Changelog

Expand Down
43 changes: 43 additions & 0 deletions bin/day-one-to-obsidian-converter
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/php
<?php

declare(strict_types=1);

/**
* Copyright (c) 2022 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/day-one-to-obsidian-converter
*/

use Ergebnis\DayOneToObsidianConverter\Outside;
use Ergebnis\Json\SchemaValidator;
use Symfony\Component\Console;
use Symfony\Component\Filesystem;

require __DIR__ . '/../vendor/autoload.php';

$schemaValidator = new SchemaValidator\SchemaValidator();
$schema = SchemaValidator\Json::fromFile(__DIR__ . '/../resource/day-one/schema.json');

$convertCommand = new Outside\Adapter\Primary\Console\ConvertCommand(
new Outside\Adapter\Secondary\DayOne\JournalFinder(new Outside\Adapter\Secondary\DayOne\JournalReader(
$schemaValidator,
$schema,
new Outside\Infrastructure\DataNormalizer(),
)),
new Outside\Adapter\Secondary\Obsidian\NoteWriter(),
new Filesystem\Filesystem(),
);

$application = new Console\Application();

$application->add($convertCommand);
$application->setDefaultCommand(
$convertCommand->getName(),
true,
);

$application->run();
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"Ergebnis\\DayOneToObsidianConverter\\Test\\": "test/"
}
},
"bin": [
"bin/day-one-to-obsidian-converter"
],
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
Expand Down
11 changes: 11 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# README

The files in [`json-export-example/`](json-export-example/) are taken from https://bloom-documentation.s3.amazonaws.com/JSON+Export+example.zip (shared on https://dayoneapp.com/guides/settings/importing-data-to-day-one/).

Run

```sh
php bin/day-one-to-obsidian-converter demo/day-one/ demo/obsidian
```

to see the converter in action.
Loading

0 comments on commit ffe0783

Please sign in to comment.