Skip to content

Commit

Permalink
apply prettier to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
cloverich committed Jan 19, 2024
1 parent 7c4bd55 commit 6fd190f
Show file tree
Hide file tree
Showing 62 changed files with 1,488 additions and 1,256 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"deno.enable": false,
"typescript.tsdk": "node_modules/typescript/lib",
}
"typescript.tsdk": "node_modules/typescript/lib"
}
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Chronicles
Electron based markdown journaling application, in the spirit of [incremental note taking][incr-notes].

**Status**: Hobby project, prototyping and re-working UX to try out various concepts with little regard for usability, stability, or appearances. Will remove this clause when I can guarantee your notes won't *poof* and the experience isn't confusing. Reach out if you are interested in journaling concepts and I'll provide a tour.
Electron based markdown journaling application, in the spirit of [incremental note taking][incr-notes].

**Status**: Hobby project, prototyping and re-working UX to try out various concepts with little regard for usability, stability, or appearances. Will remove this clause when I can guarantee your notes won't _poof_ and the experience isn't confusing. Reach out if you are interested in journaling concepts and I'll provide a tour.

Tech stack:

- Electron and esbuild
- Typescript
- React and mobx
- Slate and Plate (Notion style WSYIWYG)


## Development
The app is a typical Electron dev setup, excepting the use of [esbuild][1].

The app is a typical Electron dev setup, excepting the use of [esbuild][1].

```bash
# install dependencies
Expand All @@ -24,20 +26,21 @@ yarn start
yarn run electron-rebuild
```

See scripts/dev.js for specifics on how the source files are compiled and re-loaded in development.
See scripts/dev.js for specifics on how the source files are compiled and re-loaded in development.

## Build and release

- Read and use the `build.sh` script
- Make a Github release

At a high level, the build is comprised of:

- generate bundles ([esbuild][1]) from source files
- install production dependencies
- [re-build][2] native dependencies for the targeted electron version
- [package][3] the app


[1]: https://esbuild.github.io
[2]: https://github.com/electron/electron-rebuild
[3]: https://github.com/electron/electron-packager
[incr-notes]: https://thesephist.com/posts/inc/
[incr-notes]: https://thesephist.com/posts/inc/
55 changes: 28 additions & 27 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
/**
* See https://github.com/electron/electron-rebuild
* and https://www.electronjs.org/docs/tutorial/using-native-node-modules
*
*
* This file was created specifically to handle re-building sqlite3
* That is, sqlite3 is a _native_ dependency, and where there is a mis-match
* between the development nodejs version, and the target electron version of nodejs (v8?),
* native dependencies need to be re-compiled for the target platform.
*
* This is required anytime the app is built and packaged for distribution, so it
* should be run as part of the build script.
*
* The build.sh script could handle this functionality, but it would need to
*
* This is required anytime the app is built and packaged for distribution, so it
* should be run as part of the build script.
*
* The build.sh script could handle this functionality, but it would need to
* run after node_modules are installed IN the packaged directory
*
*
* This is also true for any additional architecture beyond whatever macos supports.
*/
const packager = require('electron-packager');
const { rebuild } = require('@electron/rebuild');
const packager = require("electron-packager");
const { rebuild } = require("@electron/rebuild");

// These arguments are provided by build.sh
const srcDir = process.argv[2];
const outDir = process.argv[3];

if (!srcDir || !outDir) {
console.error('srcDir and outDir are required arguments to package.js');
console.error("srcDir and outDir are required arguments to package.js");
process.exit(1);
}

// sanity
console.log(
'Electron packager and rebuild, using source directory',
"Electron packager and rebuild, using source directory",
srcDir,
'and outputting to',
outDir
"and outputting to",
outDir,
);


packager({
dir: srcDir,
out: outDir,
// … other options
// Documentation does this in afterCopy. Why did I do this in afterPrune?
afterPrune: [(buildPath, electronVersion, platform, arch, callback) => {
console.log('rebuilding...', buildPath, electronVersion, platform, arch);

// Previously, and after they are fixed:
rebuild({ buildPath, electronVersion, arch })
.then(() => callback())
.catch((error) => {
console.error('Error rebuilding native dependencies!');
console.error(error);
callback(error)
});
}],
});
afterPrune: [
(buildPath, electronVersion, platform, arch, callback) => {
console.log("rebuilding...", buildPath, electronVersion, platform, arch);

// Previously, and after they are fixed:
rebuild({ buildPath, electronVersion, arch })
.then(() => callback())
.catch((error) => {
console.error("Error rebuilding native dependencies!");
console.error(error);
callback(error);
});
},
],
});
114 changes: 62 additions & 52 deletions scripts/dev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const esbuild = require('esbuild');
const cp = require('child_process');
const electron = require('electron')
const lodash = require('lodash')
const esbuild = require("esbuild");
const cp = require("child_process");
const electron = require("electron");
const lodash = require("lodash");

// After successful rebuild, log results
function afterRebuild(name, cb) {
Expand All @@ -10,9 +10,9 @@ function afterRebuild(name, cb) {
console.error(`${name} bundle completed with error`, error);
} else {
console.log(`${name} bundle completed`);
restartElectron()
restartElectron();
}
}
};
}

// After successful build, log results
Expand All @@ -27,44 +27,50 @@ function afterBuild(name) {
}

// note: until I see errors or warnings, unsure if I should have any special behavior...
startElectron()
}
startElectron();
};
}

// build renderer bundle
esbuild.build({
entryPoints: ['src/index.tsx'],
outfile: 'src/renderer.bundle.js',
bundle: true,
platform: 'browser',
watch: {
onRebuild: afterRebuild('renderer')
},
}).then(afterBuild('renderer'), console.error);
esbuild
.build({
entryPoints: ["src/index.tsx"],
outfile: "src/renderer.bundle.js",
bundle: true,
platform: "browser",
watch: {
onRebuild: afterRebuild("renderer"),
},
})
.then(afterBuild("renderer"), console.error);

// build preload bundle
esbuild.build({
entryPoints: ['src/preload/index.ts'],
outfile: 'src/preload.bundle.js',
bundle: true,
platform: 'node',
external: ['knex', 'electron', 'electron-store', 'better-sqlite3'],
watch: {
onRebuild: afterRebuild('preload')
},
}).then(afterBuild('preload'), console.error);
esbuild
.build({
entryPoints: ["src/preload/index.ts"],
outfile: "src/preload.bundle.js",
bundle: true,
platform: "node",
external: ["knex", "electron", "electron-store", "better-sqlite3"],
watch: {
onRebuild: afterRebuild("preload"),
},
})
.then(afterBuild("preload"), console.error);

// build electron main bundle
esbuild.build({
entryPoints: ['src/electron/index.js'],
outfile: 'src/main.bundle.js',
bundle: true,
platform: 'node',
external: ['electron', 'electron-store', 'better-sqlite3'],
watch: {
onRebuild: afterRebuild('main')
},
}).then(afterBuild('main'), console.error);
esbuild
.build({
entryPoints: ["src/electron/index.js"],
outfile: "src/main.bundle.js",
bundle: true,
platform: "node",
external: ["electron", "electron-store", "better-sqlite3"],
watch: {
onRebuild: afterRebuild("main"),
},
})
.then(afterBuild("main"), console.error);

// For holding the spawned Electron main process, so it can
// be .kill()'ed on re-start
Expand All @@ -77,27 +83,31 @@ let startCounter = 0;
function startElectron() {
// Naive way to wait for all three bundles before starting the first time, since
// main bundle completes quickest
startCounter++
startCounter++;
if (startCounter < 3) return;

console.log('starting electron')
eprocess = cp.spawn(`${electron}`, ['src/main.bundle.js'], { stdio: 'inherit' });
console.log("starting electron");
eprocess = cp.spawn(`${electron}`, ["src/main.bundle.js"], {
stdio: "inherit",
});

eprocess.on('error', (error) => {
console.error('electron error', error, error.message)
process.exit(1)
})
eprocess.on("error", (error) => {
console.error("electron error", error, error.message);
process.exit(1);
});
}

// Re-start the main process
const restartElectron = lodash.debounce(function startElectron() {
if (eprocess) eprocess.kill('SIGTERM');
if (eprocess) eprocess.kill("SIGTERM");

console.log('starting electron')
eprocess = cp.spawn(`${electron}`, ['src/main.bundle.js'], { stdio: 'inherit' });
console.log("starting electron");
eprocess = cp.spawn(`${electron}`, ["src/main.bundle.js"], {
stdio: "inherit",
});

eprocess.on('error', (error) => {
console.error('electron error', error, error.message)
process.exit(1)
})
}, 200)
eprocess.on("error", (error) => {
console.error("electron error", error, error.message);
process.exit(1);
});
}, 200);
20 changes: 11 additions & 9 deletions scripts/migrate-uuidv7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
// against a target electron version, rather than the local node version. So
// I run it in the preload/client/index.ts file; keeping here for reference.
import { V7Generator } from "uuidv7";
import Knex from 'knex';
import Knex from "knex";

const knex = Knex({
client: 'better-sqlite3',
client: "better-sqlite3",
connection: {
filename: '/Users/my/sqlite3database.db'
}
filename: "/Users/my/sqlite3database.db",
},
});

function uuidV7FromTimestamp(ts: string) {
Expand All @@ -23,10 +23,12 @@ function uuidV7FromTimestamp(ts: string) {
}

async function validateSortOrder() {
const journals = await knex('journals');
const journals = await knex("journals");

// All documents sorted by date; sort is for fudging the timestamp (see below)
const documents = await knex('documents').select('id', 'title', 'createdAt', 'journalId').orderBy('createdAt', 'desc');
const documents = await knex("documents")
.select("id", "title", "createdAt", "journalId")
.orderBy("createdAt", "desc");

// Adding a UUIDv7 based on createdAt to each document
documents.forEach((doc, idx) => {
Expand All @@ -43,14 +45,14 @@ async function validateSortOrder() {
// For now only updating id, not createdAt, b/c I can't definitely say
// I want to discard the old createdAt value. This is only relevant for
// my personal documents anyways.
await knex('documents').where({ id: doc.id }).update({ id: doc.uuid })
await knex("documents").where({ id: doc.id }).update({ id: doc.uuid });
}

// now update journals
for (const j of journals) {
const uuid = uuidV7FromTimestamp(j.createdAt);
await knex('journals').where({ id: j.id }).update({ id: uuid })
await knex("journals").where({ id: j.id }).update({ id: uuid });
}
}

validateSortOrder()
validateSortOrder();
Loading

0 comments on commit 6fd190f

Please sign in to comment.