Skip to content

Commit 53af12e

Browse files
Merge pull request #3 from 3mp3ri0r/feature/update-foam-cli
Update foam cli to foam-core 0.17.6
2 parents 9a1b02b + 740b9c3 commit 53af12e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+11942
-2009
lines changed

.eslintrc

-6
This file was deleted.

.eslintrc.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"env": { "node": true, "es6": true },
9+
"plugins": ["@typescript-eslint", "import", "jest"],
10+
"extends": [
11+
"eslint:recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"plugin:import/recommended",
14+
"plugin:import/typescript",
15+
"plugin:jest/recommended"
16+
],
17+
"rules": {
18+
"no-use-before-define": "off",
19+
"@typescript-eslint/no-use-before-define": "off",
20+
"@typescript-eslint/no-explicit-any": "off",
21+
"@typescript-eslint/no-non-null-assertion": "off",
22+
"@typescript-eslint/explicit-function-return-type": "off",
23+
"@typescript-eslint/interface-name-prefix": "off",
24+
"import/no-extraneous-dependencies": [
25+
"error",
26+
{
27+
"devDependencies": ["**/src/test/**", "**/src/**/*{test,spec}.ts"]
28+
}
29+
]
30+
},
31+
"settings": {
32+
"import/parsers": {
33+
"@typescript-eslint/parser": [".ts", ".tsx"]
34+
},
35+
"import/resolver": {
36+
"typescript": {
37+
"alwaysTryTypes": true
38+
}
39+
}
40+
},
41+
"ignorePatterns": ["**/core/common/**", "*.js"],
42+
"reportUnusedDisableDirectives": true
43+
}

.github/workflows/integration.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
3+
name: integration
4+
5+
on:
6+
push:
7+
branches:
8+
- master
9+
pull_request:
10+
branches:
11+
- master
12+
13+
jobs:
14+
lint:
15+
name: Lint
16+
runs-on: ubuntu-20.04
17+
steps:
18+
- uses: actions/checkout@v1
19+
- name: Setup Node
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: '16'
23+
- name: Install Dependencies
24+
run: yarn
25+
- name: Check Lint Rules
26+
run: yarn lint
27+
28+
test:
29+
name: Build and Test
30+
strategy:
31+
matrix:
32+
os: [macos-10.15, ubuntu-20.04, windows-2019]
33+
runs-on: ${{ matrix.os }}
34+
env:
35+
OS: ${{ matrix.os }}
36+
steps:
37+
- uses: actions/checkout@v1
38+
- name: Setup Node
39+
uses: actions/setup-node@v1
40+
with:
41+
node-version: '16'
42+
- name: Install Dependencies
43+
run: yarn
44+
- name: Build Packages
45+
run: yarn build
46+
- name: Run Tests
47+
run: yarn test

.github/workflows/publish.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Publish Package to npmjs
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-20.04
8+
steps:
9+
- uses: actions/checkout@v2
10+
# Setup .npmrc file to publish to npm
11+
- uses: actions/setup-node@v2
12+
with:
13+
node-version: '16.x'
14+
registry-url: 'https://registry.npmjs.org'
15+
# Defaults to the user or organization that owns the workflow file
16+
scope: '@octocat'
17+
- run: yarn install --frozen-lockfile
18+
- run: yarn publish
19+
env:
20+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

+39-22
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,58 @@
11
{
22
"name": "foam-cli",
33
"description": "Foam CLI",
4-
"version": "0.11.0",
4+
"version": "0.17.6",
55
"bin": {
66
"foam": "./bin/run"
77
},
88
"bugs": "https://github.com/foambubble/foam/issues",
99
"dependencies": {
10-
"@oclif/command": "^1",
11-
"@oclif/config": "^1",
12-
"@oclif/plugin-help": "^3",
13-
"foam-core": "^0.11.0",
10+
"@oclif/command": "^1.8.16",
11+
"@oclif/config": "^1.18.3",
12+
"@oclif/plugin-help": "^5.1.12",
13+
"detect-newline": "^3.1.0",
14+
"fast-array-diff": "^1.0.1",
15+
"github-slugger": "^1.4.0",
16+
"glob": "^7.1.6",
17+
"lodash": "^4.17.21",
18+
"micromatch": "^4.0.2",
1419
"ora": "^4.0.4",
15-
"tslib": "^1"
20+
"remark-frontmatter": "^2.0.0",
21+
"remark-parse": "^8.0.2",
22+
"remark-wiki-link": "^0.0.4",
23+
"title-case": "^3.0.2",
24+
"unified": "^9.0.0",
25+
"unist-util-visit": "^2.0.2",
26+
"yaml": "^1.10.0"
1627
},
1728
"devDependencies": {
18-
"@babel/core": "^7.10.4",
19-
"@babel/preset-env": "^7.10.4",
20-
"@babel/preset-typescript": "^7.10.4",
21-
"@oclif/dev-cli": "^1",
22-
"@types/node": "^10",
23-
"babel-jest": "^26.1.0",
29+
"@babel/core": "^7.17.8",
30+
"@babel/preset-env": "^7.16.11",
31+
"@babel/preset-typescript": "^7.16.7",
32+
"@oclif/dev-cli": "^1.26.10",
33+
"@types/github-slugger": "^1.3.0",
34+
"@types/glob": "^7.1.1",
35+
"@types/jest": "^27.4.1",
36+
"@types/lodash": "^4.14.157",
37+
"@types/micromatch": "^4.0.1",
38+
"@types/node": "^13.11.0",
39+
"@typescript-eslint/eslint-plugin": "^5.16.0",
40+
"@typescript-eslint/parser": "^5.16.0",
41+
"babel-jest": "^27.5.1",
2442
"chai": "^4",
25-
"eslint": "^5.13",
26-
"eslint-config-oclif": "^3.1",
27-
"eslint-config-oclif-typescript": "^0.1",
43+
"eslint": "^8.12.0",
44+
"eslint-import-resolver-typescript": "^2.7.0",
45+
"eslint-plugin-import": "^2.25.4",
46+
"eslint-plugin-jest": "^26.1.3",
2847
"globby": "^10",
2948
"jest": "^26.1.0",
3049
"mock-fs": "^4.12.0",
31-
"ts-node": "^8",
50+
"ts-node": "^10.7.0",
51+
"tslib": "^2.3.1",
3252
"typescript": "^3.3"
3353
},
34-
"peerDependencies": {
35-
"foam-core": "*"
36-
},
3754
"engines": {
38-
"node": ">=12.0.0"
55+
"node": ">=16.0.0"
3956
},
4057
"files": [
4158
"/bin",
@@ -56,12 +73,12 @@
5673
"@oclif/plugin-help"
5774
]
5875
},
59-
"repository": "foambubble/foam",
76+
"repository": "foambubble/foam-cli",
6077
"scripts": {
6178
"clean": "rimraf tmp",
6279
"build": "tsc -b",
6380
"test": "jest",
64-
"lint": "echo Missing lint task in CLI package",
81+
"lint": "eslint --quiet --ext .js,.ts,.tsx src",
6582
"cli": "yarn build && ./bin/run",
6683
"postpack": "rm -f oclif.manifest.json",
6784
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",

src/commands/janitor.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Command, flags } from '@oclif/command';
22
import ora from 'ora';
3-
import {
4-
bootstrap,
5-
createConfigFromFolders,
6-
generateLinkReferences,
7-
generateHeading,
8-
applyTextEdit,
9-
FileDataStore,
10-
URI,
11-
isNote,
12-
} from 'foam-core';
3+
import { MarkdownResourceProvider } from "../core/markdown-provider";
4+
import { bootstrap } from '../core/model/foam';
5+
import { URI } from '../core/model/uri';
6+
import { Resource } from '../core/model/note';
7+
import { generateHeading, generateLinkReferences } from '../core/janitor';
8+
import { applyTextEdit } from '../core/janitor/apply-text-edit';
9+
import { FileDataStore, Matcher } from '../core/services/datastore';
1310
import { writeFileToDisk } from '../utils/write-file-to-disk';
1411
import { isValidDirectory } from '../utils';
1512

13+
const isNote = (resource: Resource): resource is Resource => resource.type === 'note'
14+
1615
export default class Janitor extends Command {
1716
static description =
1817
'Updates link references and heading across all the markdown files in the given workspaces';
@@ -41,8 +40,14 @@ export default class Janitor extends Command {
4140
const { workspacePath = './' } = args;
4241

4342
if (isValidDirectory(workspacePath)) {
44-
const config = createConfigFromFolders([URI.file(workspacePath)]);
45-
const workspace = (await bootstrap(config, { dataStore: new FileDataStore(config)}))
43+
const matcher = new Matcher(
44+
[URI.file(workspacePath)],
45+
['**/*'],
46+
[]
47+
);
48+
const dataStore = new FileDataStore();
49+
const markdownProvider = new MarkdownResourceProvider(matcher);
50+
const workspace = (await bootstrap(matcher, dataStore, [markdownProvider]))
4651
.workspace;
4752

4853
const notes = workspace.list().filter(isNote);

src/commands/migrate.ts

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1+
import GithubSlugger from 'github-slugger';
12
import { Command, flags } from '@oclif/command';
23
import ora from 'ora';
3-
import {
4-
bootstrap,
5-
createConfigFromFolders,
6-
generateLinkReferences,
7-
generateHeading,
8-
getKebabCaseFileName,
9-
applyTextEdit,
10-
FileDataStore,
11-
isNote,
12-
} from 'foam-core';
4+
import { MarkdownResourceProvider } from "../core/markdown-provider";
5+
import { bootstrap } from '../core/model/foam';
6+
import { URI } from '../core/model/uri';
7+
import { Resource } from '../core/model/note';
8+
import { generateHeading, generateLinkReferences } from '../core/janitor';
9+
import { applyTextEdit } from '../core/janitor/apply-text-edit';
10+
import { FileDataStore, Matcher } from '../core/services/datastore';
1311
import { writeFileToDisk } from '../utils/write-file-to-disk';
1412
import { renameFile } from '../utils/rename-file';
1513
import { isValidDirectory } from '../utils';
1614

15+
const slugger = new GithubSlugger();
16+
17+
const isNote = (resource: Resource): resource is Resource => resource.type === 'note'
18+
19+
const getKebabCaseFileName = (fileName: string) => {
20+
const kebabCasedFileName = slugger.slug(fileName);
21+
return kebabCasedFileName === fileName ? null : kebabCasedFileName;
22+
};
23+
1724
// @todo: Refactor 'migrate' and 'janitor' commands and avoid repeatition
1825
export default class Migrate extends Command {
1926
static description =
@@ -42,11 +49,17 @@ Successfully generated link references and heading!
4249
const { args, flags } = this.parse(Migrate);
4350

4451
const { workspacePath = './' } = args;
45-
const config = createConfigFromFolders([workspacePath]);
52+
53+
const matcher = new Matcher(
54+
[URI.file(workspacePath)],
55+
['**/*'],
56+
[]
57+
);
58+
const dataStore = new FileDataStore();
59+
const markdownProvider = new MarkdownResourceProvider(matcher);
4660

4761
if (isValidDirectory(workspacePath)) {
48-
const dataStore = new FileDataStore(config);
49-
let workspace = (await bootstrap(config, { dataStore: dataStore})).workspace;
62+
let workspace = (await bootstrap(matcher, dataStore, [markdownProvider])).workspace;
5063

5164
let notes = workspace.list().filter(isNote);
5265

@@ -75,7 +88,7 @@ Successfully generated link references and heading!
7588
spinner.text = 'Renaming files';
7689

7790
// Reinitialize the graph after renaming files
78-
workspace = (await bootstrap(config, { dataStore: dataStore})).workspace;
91+
workspace = (await bootstrap(matcher, dataStore, [markdownProvider])).workspace;
7992

8093
notes = workspace.list().filter(isNote);
8194

src/core/.eslintrc.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"rules": {
3+
"no-restricted-imports": [
4+
"error",
5+
{
6+
"name": "vscode",
7+
"message": "Core submodule must not depend on VS Code."
8+
}
9+
]
10+
// Ideally we would also prevent the core module from depending on other modules
11+
// but I have been struggling to get it to work.
12+
// For future reference, below are some configurations I think should achieve this
13+
// (but I couldn't manage to get working).
14+
//
15+
// "import/no-internal-modules": [
16+
// "error",
17+
// {
18+
// "allow": ["./src/core"]
19+
// }
20+
// ]
21+
// "import/no-restricted-paths": [
22+
// "error",
23+
// {
24+
// "zones": [
25+
// {
26+
// "target": "./src/core",
27+
// "from": "./src/(!core)",
28+
// "message": "Core module can't have outside dependencies."
29+
// }
30+
// ]
31+
// }
32+
// ]
33+
// "import/no-relative-parent-imports": "error"
34+
// note: https://github.com/import-js/eslint-plugin-import/issues/1610
35+
}
36+
}

0 commit comments

Comments
 (0)