mirror of
https://github.com/foambubble/foam.git
synced 2026-01-11 06:58:11 -05:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83afa873dc | ||
|
|
69c3f5fb25 | ||
|
|
6152e89590 | ||
|
|
9f17b1f7b9 | ||
|
|
8f1327337c | ||
|
|
b15f27aea6 | ||
|
|
b8a16cc5ed | ||
|
|
168ef5edb4 |
@@ -424,7 +424,8 @@
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/15343819?v=4",
|
||||
"profile": "http://jmg-duarte.github.io",
|
||||
"contributions": [
|
||||
"code"
|
||||
"code",
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
14
.github/CONTRIBUTING.md
vendored
14
.github/CONTRIBUTING.md
vendored
@@ -1,14 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
Hello, friend.
|
||||
|
||||
This repository is a [monorepo](https://en.wikipedia.org/wiki/Monorepo) managed by [Yarn Workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).
|
||||
|
||||
- The [packages](packages/) directory contains all Foam core code packages
|
||||
- The [docs](docs/) directory contains a Foam workspace that hosts the official [documentation site](https://foambubble.github.io/foam)
|
||||
|
||||
The foam starter template lives outside of this repository at [foambubble/foam-template](https://github.com/foambubble/foam-template).
|
||||
|
||||
See [Foam Contribution Guide](https://foambubble.github.io/foam/contribution-guide) on the rendered Foam workspace for more information on how to contribute to Foam.
|
||||
|
||||
Thank you for your interest!
|
||||
7
.github/workflows/foam-cli.yml
vendored
7
.github/workflows/foam-cli.yml
vendored
@@ -19,8 +19,11 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: yarn
|
||||
|
||||
# - name: Lint foam-lint
|
||||
# run: yarn workspace foam-cli lint
|
||||
- name: Lint foam-lint
|
||||
run: yarn workspace foam-cli lint
|
||||
|
||||
- name: Build foam-core
|
||||
run: yarn workspace foam-core build
|
||||
|
||||
- name: Test foam-cli
|
||||
run: yarn workspace foam-cli test
|
||||
|
||||
4
.github/workflows/foam-vscode.yml
vendored
4
.github/workflows/foam-vscode.yml
vendored
@@ -22,6 +22,10 @@ jobs:
|
||||
|
||||
- name: Lint foam-vscode
|
||||
run: yarn workspace foam-vscode lint
|
||||
|
||||
- name: Build foam-core
|
||||
run: yarn workspace foam-core build
|
||||
|
||||
- name: Test foam-vscode
|
||||
run: yarn workspace foam-vscode test
|
||||
# - name: Publish foam-vscode
|
||||
|
||||
21
docs/architecture.md
Normal file
21
docs/architecture.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
tags: architecture
|
||||
---
|
||||
# Architecture
|
||||
|
||||
This document aims to provide a quick overview of the Foam architecture!
|
||||
|
||||
Foam code and documentation live in the monorepo at [foambubble/foam](https://github.com/foambubble/foam/).
|
||||
- [/docs](https://github.com/foambubble/foam/docs): documentation and [[recipes]].
|
||||
- [/packages/foam-core](https://github.com/foambubble/foam/tree/master/packages/foam-core) - Powers the core functionality in Foam across all platforms.
|
||||
- [/packages/foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode) - The core VSCode plugin.
|
||||
- [/packages/foam-cli](https://github.com/foambubble/foam/tree/master/packages/foam-cli) - The Foam CLI tool.
|
||||
|
||||
Exceptions to the monorepo are:
|
||||
- The starter template at [foambubble/foam-template](https://github.com/foambubble/)
|
||||
- All other [[recommended-extensions]] live in their respective GitHub repos.
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[recipes]: recipes.md "Recipes"
|
||||
[recommended-extensions]: recommended-extensions.md "Recommended Extensions"
|
||||
[//end]: # "Autogenerated link references"
|
||||
@@ -1,7 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
Head over to the [[contribution-guide]]. `CONTRIBUTING.md` file name is blocklisted on GitHub pages, and doesn't appear in the [rendered output](https://foambubble.github.io/foam).
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[contribution-guide]: contribution-guide.md "Contribution Guide"
|
||||
[//end]: # "Autogenerated link references"
|
||||
@@ -1,25 +1,28 @@
|
||||
---
|
||||
tags: todo, good-first-task
|
||||
---
|
||||
# Contribution Guide
|
||||
Foam is open to contributions of any kind, including but not limited to code, documentation, ideas, and feedback.
|
||||
This guide aims to help guide new and seasoned contributors getting around the Foam codebase.
|
||||
|
||||
> [[todo]] [[good-first-task]] This contribution guide itself could be improved 😅
|
||||
## Getting Up To Speed
|
||||
Before you start contributing we recommend that you read the following links:
|
||||
|
||||
Foam is open to contributions of any kind, including but not limited to code, documentation, ideas, and feedback. Here are some general tips on how to get started on contributing to Foam:
|
||||
- [[principles]] - This document describes the guiding principles behind Foam.
|
||||
- [[code-of-conduct]] - Rules we hope every contributor aims to follow, allowing everyone to participate in our community!
|
||||
|
||||
- Use Foam for yourself, figure out what could be improved.
|
||||
- Check out [[roadmap]] to see what's already in the plans. I have thoughts about how to implement some of these, but open to ideas and code contributions!
|
||||
- Read about our [[principles]] to understand Foam's philosophy and direction
|
||||
- Read and act in accordance with our [[code-of-conduct]].
|
||||
- Feel free to open [GitHub issues](https://github.com/foambubble/foam/issues) to give me feedback and ideas for new features.
|
||||
- Foam code and documentation live in the monorepo at [foambubble/foam](https://github.com/foambubble/foam/)
|
||||
- [/docs](https://github.com/foambubble/foam/docs): documentation and [[recipes]]
|
||||
- [/packages/foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode): the core VSCode plugin
|
||||
- [/packages/foam-core](https://github.com/foambubble/foam/tree/master/packages/foam-core): powers the core functionality in Foam across all platforms
|
||||
- Exceptions to the monorepo are:
|
||||
- The starter template at [foambubble/foam-template](https://github.com/foambubble/)
|
||||
- All other [[recommended-extensions]] live in their respective GitHub repos.
|
||||
## Diving In
|
||||
We understand that diving in an unfamiliar codebase may seem scary,
|
||||
to make it easier for new contributors we provide some resources:
|
||||
- [[roadmap]] - You can read our roadmap to see what is coming to Foam, many of these are open to suggestions!
|
||||
- [[architecture]] - This document describes the architecture of Foam and how the repository is structured.
|
||||
|
||||
## Contributing to the VS Code Extension
|
||||
You can also see [existing issues](https://github.com/foambubble/foam/issues) and help out!
|
||||
Finally, the easiest way to help, is to use it and provide feedback by [submitting issues](https://github.com/foambubble/foam/issues/new/choose) or participating in the [Foam Community Discord](https://discord.gg/rtdZKgj)!
|
||||
|
||||
If you're interested in contributing to the VS Code extension (aka `foam-vscode`), this guide will help you get things set up locally.
|
||||
## Contributing
|
||||
|
||||
If you're interested in contributing, this short guide will help you get things set up locally.
|
||||
|
||||
1. Clone the repo locally:
|
||||
|
||||
@@ -29,25 +32,36 @@ If you're interested in contributing to the VS Code extension (aka `foam-vscode`
|
||||
|
||||
`yarn install`
|
||||
|
||||
3. This project uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).`foam-vscode` relies on `foam-core`. This means we need to compile it before we do any extension development. From the root, run the command:
|
||||
3. This project uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/). `foam-vscode` relies on `foam-core`. This means we need to compile it before we do any extension development. From the root, run the command:
|
||||
|
||||
`yarn workspace foam-core build`
|
||||
`yarn build`
|
||||
|
||||
4. Now we'll use the launch configuration defined at [`.vscode/launch.json`](https://github.com/foambubble/foam/blob/master/.vscode/launch.json) to start a new extension host of VS Code. From the root, or the `foam-vscode` workspace, press f5.
|
||||
5. In the new extension host of VS Code that launched, open a Foam workspace (e.g. your personal one, or a test-specific one created from foam-template). This is strictly not necessary, but the extension won't auto-run unless it's in a workspace with a `.vscode/foam.json` file.
|
||||
6. Test a command to make sure it's working as expected. Open the Command Palette (Ctrl/Cmd + Shift + P) and select "Foam: Update Markdown Reference List". If you see no errors, it's good to go!
|
||||
You should now be ready to start working!
|
||||
|
||||
### The VS Code Extension
|
||||
|
||||
This guide assumes you read the previous instructions and you're set up to work on Foam.
|
||||
|
||||
1. Now we'll use the launch configuration defined at [`.vscode/launch.json`](https://github.com/foambubble/foam/blob/master/.vscode/launch.json) to start a new extension host of VS Code. From the root, or the `foam-vscode` workspace, press f5.
|
||||
|
||||
2. In the new extension host of VS Code that launched, open a Foam workspace (e.g. your personal one, or a test-specific one created from [foam-template](https://github.com/foambubble/foam-template)). This is strictly not necessary, but the extension won't auto-run unless it's in a workspace with a `.vscode/foam.json` file.
|
||||
|
||||
3. Test a command to make sure it's working as expected. Open the Command Palette (Ctrl/Cmd + Shift + P) and select "Foam: Update Markdown Reference List". If you see no errors, it's good to go!
|
||||
|
||||
For more resources related to the VS Code Extension, check out the links below:
|
||||
|
||||
- [[tutorial-adding-a-new-command-to-the-vs-code-extension]]
|
||||
|
||||
---
|
||||
|
||||
Feel free to modify and submit a PR if this guide is out-of-date or contains errors!
|
||||
|
||||
---
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[todo]: todo.md "Todo"
|
||||
[good-first-task]: good-first-task.md "Good First Task"
|
||||
[roadmap]: roadmap.md "Roadmap"
|
||||
[principles]: principles.md "Principles"
|
||||
[code-of-conduct]: code-of-conduct.md "Code of Conduct"
|
||||
[recipes]: recipes.md "Recipes"
|
||||
[recommended-extensions]: recommended-extensions.md "Recommended Extensions"
|
||||
[roadmap]: roadmap.md "Roadmap"
|
||||
[architecture]: architecture.md "Architecture"
|
||||
[tutorial-adding-a-new-command-to-the-vs-code-extension]: tutorial-adding-a-new-command-to-the-vs-code-extension.md "Tutorial: Adding a New Command to the VS Code Extension"
|
||||
[//end]: # "Autogenerated link references"
|
||||
|
||||
@@ -166,7 +166,7 @@ If that sounds like something you're interested in, I'd love to have you along o
|
||||
<tr>
|
||||
<td align="center"><a href="https://spencerwoo.com"><img src="https://avatars2.githubusercontent.com/u/32114380?v=4" width="60px;" alt=""/><br /><sub><b>Spencer Woo</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=spencerwooo" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://ingalless.com"><img src="https://avatars3.githubusercontent.com/u/22981941?v=4" width="60px;" alt=""/><br /><sub><b>ingalless</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=ingalless" title="Code">💻</a> <a href="https://github.com/foambubble/foam/commits?author=ingalless" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="http://jmg-duarte.github.io"><img src="https://avatars2.githubusercontent.com/u/15343819?v=4" width="60px;" alt=""/><br /><sub><b>José Duarte</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=jmg-duarte" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://jmg-duarte.github.io"><img src="https://avatars2.githubusercontent.com/u/15343819?v=4" width="60px;" alt=""/><br /><sub><b>José Duarte</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=jmg-duarte" title="Code">💻</a> <a href="https://github.com/foambubble/foam/commits?author=jmg-duarte" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://www.yenly.wtf"><img src="https://avatars1.githubusercontent.com/u/6759658?v=4" width="60px;" alt=""/><br /><sub><b>Yenly</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=yenly" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://www.hikerpig.cn"><img src="https://avatars1.githubusercontent.com/u/2259688?v=4" width="60px;" alt=""/><br /><sub><b>hikerpig</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=hikerpig" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://sigfried.org"><img src="https://avatars1.githubusercontent.com/u/1586931?v=4" width="60px;" alt=""/><br /><sub><b>Sigfried Gold</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Sigfried" title="Documentation">📖</a></td>
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
],
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"version": "0.7.0"
|
||||
"version": "0.7.1"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ $ npm install -g foam-cli
|
||||
$ foam COMMAND
|
||||
running command...
|
||||
$ foam (-v|--version|version)
|
||||
foam-cli/0.7.0 darwin-x64 node-v12.18.2
|
||||
foam-cli/0.7.1 darwin-x64 node-v12.18.2
|
||||
$ foam --help [COMMAND]
|
||||
USAGE
|
||||
$ foam COMMAND
|
||||
@@ -29,6 +29,8 @@ USAGE
|
||||
# Commands
|
||||
<!-- commands -->
|
||||
* [`foam help [COMMAND]`](#foam-help-command)
|
||||
* [`foam janitor [WORKSPACEPATH]`](#foam-janitor-workspacepath)
|
||||
* [`foam migrate [WORKSPACEPATH]`](#foam-migrate-workspacepath)
|
||||
|
||||
## `foam help [COMMAND]`
|
||||
|
||||
@@ -46,6 +48,43 @@ OPTIONS
|
||||
```
|
||||
|
||||
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.1.0/src/commands/help.ts)_
|
||||
|
||||
## `foam janitor [WORKSPACEPATH]`
|
||||
|
||||
Updates link references and heading across all the markdown files in the given workspaces
|
||||
|
||||
```
|
||||
USAGE
|
||||
$ foam janitor [WORKSPACEPATH]
|
||||
|
||||
OPTIONS
|
||||
-h, --help show CLI help
|
||||
-w, --without-extensions generate link reference definitions without extensions (for legacy support)
|
||||
|
||||
EXAMPLE
|
||||
$ foam-cli janitor path-to-foam-workspace
|
||||
```
|
||||
|
||||
_See code: [src/commands/janitor.ts](https://github.com/foambubble/foam/blob/v0.7.1/src/commands/janitor.ts)_
|
||||
|
||||
## `foam migrate [WORKSPACEPATH]`
|
||||
|
||||
Updates file names, link references and heading across all the markdown files in the given workspaces
|
||||
|
||||
```
|
||||
USAGE
|
||||
$ foam migrate [WORKSPACEPATH]
|
||||
|
||||
OPTIONS
|
||||
-h, --help show CLI help
|
||||
-w, --without-extensions generate link reference definitions without extensions (for legacy support)
|
||||
|
||||
EXAMPLE
|
||||
$ foam-cli migrate path-to-foam-workspace
|
||||
Successfully generated link references and heading!
|
||||
```
|
||||
|
||||
_See code: [src/commands/migrate.ts](https://github.com/foambubble/foam/blob/v0.7.1/src/commands/migrate.ts)_
|
||||
<!-- commandsstop -->
|
||||
|
||||
## Development
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "foam-cli",
|
||||
"description": "Foam CLI",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"author": "Jani Eväkallio @jevakallio",
|
||||
"bin": {
|
||||
"foam": "./bin/run"
|
||||
@@ -11,7 +11,7 @@
|
||||
"@oclif/command": "^1",
|
||||
"@oclif/config": "^1",
|
||||
"@oclif/plugin-help": "^3",
|
||||
"foam-core": "^0.7.0",
|
||||
"foam-core": "^0.7.1",
|
||||
"ora": "^4.0.4",
|
||||
"tslib": "^1"
|
||||
},
|
||||
|
||||
@@ -42,7 +42,6 @@ export default class Janitor extends Command {
|
||||
if (isValidDirectory(workspacePath)) {
|
||||
const config = createConfigFromFolders([workspacePath]);
|
||||
const services: Services = {
|
||||
logger: console,
|
||||
dataStore: new FileDataStore(config),
|
||||
};
|
||||
const graph = (await bootstrap(config, services)).notes;
|
||||
|
||||
@@ -46,7 +46,6 @@ Successfully generated link references and heading!
|
||||
|
||||
if (isValidDirectory(workspacePath)) {
|
||||
const services: Services = {
|
||||
logger: console,
|
||||
dataStore: new FileDataStore(config),
|
||||
};
|
||||
let graph = (await bootstrap(config, services)).notes;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "foam-core",
|
||||
"author": "Jani Eväkallio",
|
||||
"repository": "https://github.com/foambubble/foam",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -2,10 +2,11 @@ import { Note, NoteLink, URI } from './types';
|
||||
import { NoteGraph, NoteGraphAPI } from './note-graph';
|
||||
import { FoamConfig } from './config';
|
||||
import { IDataStore, FileDataStore } from './services/datastore';
|
||||
import { ILogger } from './services/logger';
|
||||
import { ILogger } from './utils/log';
|
||||
|
||||
export { IDataStore, FileDataStore };
|
||||
export { ILogger };
|
||||
export { LogLevel, LogLevelThreshold, Logger, BaseLogger } from './utils/log';
|
||||
export { IDisposable, isDisposable } from './common/lifecycle';
|
||||
export { Event, Emitter } from './common/event';
|
||||
export { FoamConfig };
|
||||
@@ -37,7 +38,6 @@ export {
|
||||
|
||||
export interface Services {
|
||||
dataStore: IDataStore;
|
||||
logger: ILogger;
|
||||
}
|
||||
|
||||
export interface Foam {
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
} from './utils';
|
||||
import { ID } from './types';
|
||||
import { ParserPlugin } from './plugins';
|
||||
import { Logger } from './utils/log';
|
||||
|
||||
const tagsPlugin: ParserPlugin = {
|
||||
name: 'tags',
|
||||
@@ -87,7 +88,7 @@ const handleError = (
|
||||
e: Error
|
||||
): void => {
|
||||
const name = plugin.name || '';
|
||||
console.warn(
|
||||
Logger.warn(
|
||||
`Error while executing [${fnName}] in plugin [${name}] for file [${uri}]`,
|
||||
e
|
||||
);
|
||||
@@ -117,6 +118,7 @@ export function createMarkdownParser(extraPlugins: ParserPlugin[]): NoteParser {
|
||||
|
||||
const foamParser: NoteParser = {
|
||||
parse: (uri: string, markdown: string): Note => {
|
||||
Logger.debug('Parsing:', uri);
|
||||
markdown = plugins.reduce((acc, plugin) => {
|
||||
try {
|
||||
return plugin.onWillParseMarkdown?.(acc) || acc;
|
||||
@@ -176,7 +178,7 @@ export function createMarkdownParser(extraPlugins: ParserPlugin[]): NoteParser {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`Error while parsing YAML for [${uri}]`, e);
|
||||
Logger.warn(`Error while parsing YAML for [${uri}]`, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +197,7 @@ export function createMarkdownParser(extraPlugins: ParserPlugin[]): NoteParser {
|
||||
handleError(plugin, 'onDidVisitTree', uri, e);
|
||||
}
|
||||
});
|
||||
Logger.debug('Result:', note);
|
||||
return note;
|
||||
},
|
||||
};
|
||||
@@ -260,7 +263,7 @@ export function createMarkdownReferences(
|
||||
if (!target) {
|
||||
const candidates = graph.getNotes({ slug: link.link.slug });
|
||||
if (candidates.length > 1) {
|
||||
console.log(
|
||||
Logger.info(
|
||||
`Warning: Slug ${link.link.slug} matches ${candidates.length} documents. Picking one.`
|
||||
);
|
||||
}
|
||||
@@ -269,7 +272,7 @@ export function createMarkdownReferences(
|
||||
// We are dropping links to non-existent notes here,
|
||||
// but int the future we may want to surface these too
|
||||
if (!target) {
|
||||
console.log(
|
||||
Logger.info(
|
||||
`Warning: Link '${link.to}' in '${noteId}' points to a non-existing note.`
|
||||
);
|
||||
return null;
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Middleware } from '../note-graph';
|
||||
import { Note } from '../types';
|
||||
import unified from 'unified';
|
||||
import { FoamConfig } from '../config';
|
||||
import { Logger } from '../utils/log';
|
||||
|
||||
export interface FoamPlugin {
|
||||
name: string;
|
||||
@@ -47,10 +48,11 @@ export async function loadPlugins(config: FoamConfig): Promise<FoamPlugin[]> {
|
||||
try {
|
||||
const pluginFile = path.join(dir, 'index.js');
|
||||
fs.accessSync(pluginFile);
|
||||
Logger.info(`Found plugin at [${pluginFile}]. Loading..`);
|
||||
const plugin = validate(await import(pluginFile));
|
||||
return plugin;
|
||||
} catch (e) {
|
||||
console.error(`Error while loading plugin at [${dir}] - skipping`, e);
|
||||
Logger.error(`Error while loading plugin at [${dir}] - skipping`, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import fs from 'fs';
|
||||
import { Event, Emitter } from '../common/event';
|
||||
import { URI } from '../types';
|
||||
import { FoamConfig } from '../config';
|
||||
import { Logger } from '../utils/log';
|
||||
|
||||
const findAllFiles = promisify(glob);
|
||||
|
||||
@@ -83,6 +84,10 @@ export class FileDataStore implements IDataStore {
|
||||
ignoreGlobs.push(...config.ignoreGlobs.map(withFolder));
|
||||
});
|
||||
|
||||
Logger.debug('Glob patterns', {
|
||||
includeGlobs,
|
||||
ignoreGlobs,
|
||||
});
|
||||
this.match = (files: URI[]) => {
|
||||
return micromatch(files, includeGlobs, {
|
||||
ignore: ignoreGlobs,
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
export interface ILogger {
|
||||
log(message?: any, ...optionalParams: any[]): void;
|
||||
debug(message?: any, ...optionalParams: any[]): void;
|
||||
info(message?: any, ...optionalParams: any[]): void;
|
||||
warn(message?: any, ...optionalParams: any[]): void;
|
||||
error(message?: any, ...optionalParams: any[]): void;
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
import { isSome, isNumeric } from './core';
|
||||
|
||||
const HASHTAG_REGEX = /(^|[ ])#([\w_-]+\b)/gm;
|
||||
const WORD_REGEX = /(^|[ ])([\w_-]+\b)/gm;
|
||||
const HASHTAG_REGEX = /(^|[ ])#([\w_-]*[a-zA-Z][\w_-]*\b)/gm;
|
||||
const WORD_REGEX = /(^|[ ])([\w_-]*[a-zA-Z][\w_-]*\b)/gm;
|
||||
|
||||
export const extractHashtags = (text: string): Set<string> => {
|
||||
return isSome(text)
|
||||
? new Set(
|
||||
Array.from([...text.matchAll(HASHTAG_REGEX)])
|
||||
.map(m => m[2].trim())
|
||||
.filter(tag => !isNumeric(tag))
|
||||
)
|
||||
? new Set(Array.from(text.matchAll(HASHTAG_REGEX), m => m[2].trim()))
|
||||
: new Set();
|
||||
};
|
||||
|
||||
|
||||
89
packages/foam-core/src/utils/log.ts
Normal file
89
packages/foam-core/src/utils/log.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
export interface ILogger {
|
||||
debug(message?: any, ...params: any[]): void;
|
||||
info(message?: any, ...params: any[]): void;
|
||||
warn(message?: any, ...params: any[]): void;
|
||||
error(message?: any, ...params: any[]): void;
|
||||
getLevel(): LogLevelThreshold;
|
||||
setLevel(level: LogLevelThreshold): void;
|
||||
}
|
||||
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
||||
export type LogLevelThreshold = LogLevel | 'off';
|
||||
|
||||
export abstract class BaseLogger implements ILogger {
|
||||
private static severity = {
|
||||
debug: 1,
|
||||
info: 2,
|
||||
warn: 3,
|
||||
error: 4,
|
||||
};
|
||||
|
||||
constructor(private level: LogLevelThreshold = 'info') {}
|
||||
|
||||
abstract log(lvl: LogLevel, msg?: any, ...extra: any[]): void;
|
||||
|
||||
doLog(msgLevel: LogLevel, message?: any, ...params: any[]): void {
|
||||
if (this.level === 'off') {
|
||||
return;
|
||||
}
|
||||
if (BaseLogger.severity[msgLevel] >= BaseLogger.severity[this.level]) {
|
||||
this.log(msgLevel, message, ...params);
|
||||
}
|
||||
}
|
||||
|
||||
debug(message?: any, ...params: any[]): void {
|
||||
this.doLog('debug', message, ...params);
|
||||
}
|
||||
info(message?: any, ...params: any[]): void {
|
||||
this.doLog('info', message, ...params);
|
||||
}
|
||||
warn(message?: any, ...params: any[]): void {
|
||||
this.doLog('warn', message, ...params);
|
||||
}
|
||||
error(message?: any, ...params: any[]): void {
|
||||
this.doLog('error', message, ...params);
|
||||
}
|
||||
getLevel(): LogLevelThreshold {
|
||||
return this.level;
|
||||
}
|
||||
setLevel(level: LogLevelThreshold): void {
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
|
||||
export class ConsoleLogger extends BaseLogger {
|
||||
log(level: LogLevel, msg?: string, ...params: any[]): void {
|
||||
console[level](`[${level}] ${msg}`, ...params);
|
||||
}
|
||||
}
|
||||
|
||||
export class NoOpLogger extends BaseLogger {
|
||||
log(_l: LogLevel, _m?: string, ..._p: any[]): void {}
|
||||
}
|
||||
|
||||
export class Logger {
|
||||
static debug(message?: any, ...params: any[]): void {
|
||||
Logger.defaultLogger.debug(message, ...params);
|
||||
}
|
||||
static info(message?: any, ...params: any[]): void {
|
||||
Logger.defaultLogger.info(message, ...params);
|
||||
}
|
||||
static warn(message?: any, ...params: any[]): void {
|
||||
Logger.defaultLogger.warn(message, ...params);
|
||||
}
|
||||
static error(message?: any, ...params: any[]): void {
|
||||
Logger.defaultLogger.error(message, ...params);
|
||||
}
|
||||
static getLevel(): LogLevelThreshold {
|
||||
return Logger.defaultLogger.getLevel();
|
||||
}
|
||||
static setLevel(level: LogLevelThreshold): void {
|
||||
Logger.defaultLogger.setLevel(level);
|
||||
}
|
||||
|
||||
private static defaultLogger: ILogger = new ConsoleLogger();
|
||||
|
||||
static setDefaultLogger(logger: ILogger) {
|
||||
Logger.defaultLogger = logger;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ describe('generateHeadings', () => {
|
||||
]);
|
||||
const services: Services = {
|
||||
dataStore: new FileDataStore(config),
|
||||
logger: console,
|
||||
};
|
||||
const foam = await bootstrap(config, services);
|
||||
_graph = foam.notes;
|
||||
|
||||
@@ -15,7 +15,6 @@ describe('generateLinkReferences', () => {
|
||||
]);
|
||||
const services: Services = {
|
||||
dataStore: new FileDataStore(config),
|
||||
logger: console,
|
||||
};
|
||||
_graph = await bootstrap(config, services).then(foam => foam.notes);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,16 @@ All notable changes to the "foam-vscode" extension will be documented in this fi
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
|
||||
## [0.7.1] - 2020-11-27
|
||||
|
||||
New Feature:
|
||||
- Foam logging can now be inspected in VsCode Output panel (#377)
|
||||
|
||||
Fixes and Improvements:
|
||||
- Foam model: Fixed bug in tags parsing (#382)
|
||||
- Dataviz: Graph canvas now resizes with window (#383, #375)
|
||||
- Dataviz: Limit label length for placeholder nodes (#381)
|
||||
|
||||
## [0.7.0] - 2020-11-25
|
||||
|
||||
New Features:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "git"
|
||||
},
|
||||
"homepage": "https://github.com/foambubble/foam",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"license": "MIT",
|
||||
"publisher": "foam",
|
||||
"engines": {
|
||||
@@ -40,6 +40,10 @@
|
||||
]
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "foam-vscode.set-log-level",
|
||||
"title": "Foam: Set log level"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.show-graph",
|
||||
"title": "Foam: Show graph"
|
||||
@@ -80,6 +84,17 @@
|
||||
],
|
||||
"description": "Specifies the list of globs that will be ignored by Foam (e.g. they will not be considered when creating the graph). To ignore the all the content of a given folder, use `<folderName>/**/*`"
|
||||
},
|
||||
"foam.logging.level": {
|
||||
"type": "string",
|
||||
"default": "info",
|
||||
"enum": [
|
||||
"off",
|
||||
"debug",
|
||||
"info",
|
||||
"warn",
|
||||
"error"
|
||||
]
|
||||
},
|
||||
"foam.edit.linkReferenceDefinitions": {
|
||||
"type": "string",
|
||||
"default": "withoutExtensions",
|
||||
@@ -185,6 +200,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"foam-core": "^0.7.0"
|
||||
"foam-core": "^0.7.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,24 @@ import {
|
||||
Foam,
|
||||
FileDataStore,
|
||||
Services,
|
||||
isDisposable
|
||||
isDisposable,
|
||||
Logger
|
||||
} from "foam-core";
|
||||
|
||||
import { features } from "./features";
|
||||
import { getConfigFromVscode } from "./services/config";
|
||||
import { VsCodeOutputLogger, exposeLogger } from "./services/logging";
|
||||
|
||||
let foam: Foam | null = null;
|
||||
|
||||
export async function activate(context: ExtensionContext) {
|
||||
const logger = new VsCodeOutputLogger();
|
||||
Logger.setDefaultLogger(logger);
|
||||
exposeLogger(context, logger);
|
||||
|
||||
try {
|
||||
Logger.info("Starting Foam");
|
||||
|
||||
const config: FoamConfig = getConfigFromVscode();
|
||||
const dataStore = new FileDataStore(config);
|
||||
|
||||
@@ -39,7 +47,6 @@ export async function activate(context: ExtensionContext) {
|
||||
});
|
||||
|
||||
const services: Services = {
|
||||
logger: console,
|
||||
dataStore: dataStore
|
||||
};
|
||||
const foamPromise: Promise<Foam> = bootstrap(config, services);
|
||||
@@ -49,8 +56,9 @@ export async function activate(context: ExtensionContext) {
|
||||
});
|
||||
|
||||
foam = await foamPromise;
|
||||
Logger.info(`Loaded ${foam.notes.getNotes().length} notes`);
|
||||
} catch (e) {
|
||||
console.log("An error occurred while bootstrapping Foam", e);
|
||||
Logger.error("An error occurred while bootstrapping Foam", e);
|
||||
window.showErrorMessage(
|
||||
`An error occurred while bootstrapping Foam. ${e.stack}`
|
||||
);
|
||||
|
||||
@@ -66,7 +66,7 @@ function generateGraphData(foam: Foam) {
|
||||
id: link.to,
|
||||
type: "nonExistingNote",
|
||||
uri: `virtual:${link.to}`,
|
||||
title: link.link.slug
|
||||
title: cutTitle(link.link.slug)
|
||||
};
|
||||
}
|
||||
graph.edges.add({
|
||||
|
||||
56
packages/foam-vscode/src/services/logging.ts
Normal file
56
packages/foam-vscode/src/services/logging.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { window, commands, ExtensionContext } from "vscode";
|
||||
import { ILogger, IDisposable, LogLevel, BaseLogger } from "foam-core";
|
||||
import { getFoamLoggerLevel } from "../settings";
|
||||
|
||||
export interface VsCodeLogger extends ILogger, IDisposable {
|
||||
show();
|
||||
}
|
||||
|
||||
export class VsCodeOutputLogger extends BaseLogger implements VsCodeLogger {
|
||||
private channel = window.createOutputChannel("Foam");
|
||||
|
||||
constructor() {
|
||||
super(getFoamLoggerLevel());
|
||||
this.channel.appendLine("Foam Logging: " + getFoamLoggerLevel());
|
||||
}
|
||||
|
||||
log(lvl: LogLevel, msg?: any, ...extra: any[]): void {
|
||||
if (msg) {
|
||||
this.channel.appendLine(
|
||||
`[${lvl} - ${new Date().toLocaleTimeString()}] ${msg}`
|
||||
);
|
||||
}
|
||||
extra?.forEach(param => {
|
||||
if (param?.stack) {
|
||||
this.channel.appendLine(JSON.stringify(param.stack, null, 2));
|
||||
} else {
|
||||
this.channel.appendLine(JSON.stringify(param, null, 2));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
show() {
|
||||
this.channel.show();
|
||||
}
|
||||
dispose(): void {
|
||||
this.channel.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export const exposeLogger = (
|
||||
context: ExtensionContext,
|
||||
logger: VsCodeLogger
|
||||
): void => {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand("foam-vscode.set-log-level", async () => {
|
||||
const items: LogLevel[] = ["debug", "info", "warn", "error"];
|
||||
const level = await window.showQuickPick(
|
||||
items.map(item => ({
|
||||
label: item,
|
||||
description: item === logger.getLevel() && "Current"
|
||||
}))
|
||||
);
|
||||
logger.setLevel(level.label);
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { workspace } from "vscode";
|
||||
import { LogLevel } from "foam-core";
|
||||
|
||||
export enum LinkReferenceDefinitionsSetting {
|
||||
withExtensions = "withExtensions",
|
||||
@@ -24,3 +25,7 @@ export function getIgnoredFilesSetting(): string[] {
|
||||
export function getTitleMaxLength(): number {
|
||||
return workspace.getConfiguration("foam.graph").get("titleMaxLength");
|
||||
}
|
||||
|
||||
export function getFoamLoggerLevel(): LogLevel {
|
||||
return workspace.getConfiguration("foam.logging").get("level") ?? "info";
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Selection
|
||||
} from "vscode";
|
||||
import * as fs from "fs";
|
||||
import { Logger } from "foam-core";
|
||||
|
||||
interface Point {
|
||||
line: number;
|
||||
@@ -28,7 +29,7 @@ export function loadDocConfig() {
|
||||
// Load workspace config
|
||||
let activeEditor = window.activeTextEditor;
|
||||
if (!activeEditor) {
|
||||
console.log("Failed to load config, no active editor");
|
||||
Logger.debug("Failed to load config, no active editor");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
<meta charset="utf-8" />
|
||||
<script data-replace src="./d3.v6.min.js"></script>
|
||||
<script data-replace src="./force-graph.1.34.1.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="graph" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0;"></div>
|
||||
|
||||
@@ -283,6 +283,10 @@ try {
|
||||
console.log("VsCode not detected");
|
||||
}
|
||||
|
||||
window.addEventListener("resize", () => {
|
||||
graph.width(window.innerWidth).height(window.innerHeight);
|
||||
});
|
||||
|
||||
// For testing
|
||||
if (window.data) {
|
||||
console.log("Test mode");
|
||||
|
||||
@@ -114,7 +114,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<tr>
|
||||
<td align="center"><a href="https://spencerwoo.com"><img src="https://avatars2.githubusercontent.com/u/32114380?v=4" width="60px;" alt=""/><br /><sub><b>Spencer Woo</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=spencerwooo" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://ingalless.com"><img src="https://avatars3.githubusercontent.com/u/22981941?v=4" width="60px;" alt=""/><br /><sub><b>ingalless</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=ingalless" title="Code">💻</a> <a href="https://github.com/foambubble/foam/commits?author=ingalless" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="http://jmg-duarte.github.io"><img src="https://avatars2.githubusercontent.com/u/15343819?v=4" width="60px;" alt=""/><br /><sub><b>José Duarte</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=jmg-duarte" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://jmg-duarte.github.io"><img src="https://avatars2.githubusercontent.com/u/15343819?v=4" width="60px;" alt=""/><br /><sub><b>José Duarte</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=jmg-duarte" title="Code">💻</a> <a href="https://github.com/foambubble/foam/commits?author=jmg-duarte" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://www.yenly.wtf"><img src="https://avatars1.githubusercontent.com/u/6759658?v=4" width="60px;" alt=""/><br /><sub><b>Yenly</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=yenly" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://www.hikerpig.cn"><img src="https://avatars1.githubusercontent.com/u/2259688?v=4" width="60px;" alt=""/><br /><sub><b>hikerpig</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=hikerpig" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://sigfried.org"><img src="https://avatars1.githubusercontent.com/u/1586931?v=4" width="60px;" alt=""/><br /><sub><b>Sigfried Gold</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Sigfried" title="Documentation">📖</a></td>
|
||||
|
||||
Reference in New Issue
Block a user