Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update foam cli #3

Merged
merged 6 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

43 changes: 43 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": { "node": true, "es6": true },
"plugins": ["@typescript-eslint", "import", "jest"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:jest/recommended"
],
"rules": {
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/interface-name-prefix": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["**/src/test/**", "**/src/**/*{test,spec}.ts"]
}
]
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
},
"ignorePatterns": ["**/core/common/**", "*.js"],
"reportUnusedDisableDirectives": true
}
47 changes: 47 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


name: integration

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '16'
- name: Install Dependencies
run: yarn
- name: Check Lint Rules
run: yarn lint

test:
name: Build and Test
strategy:
matrix:
os: [macos-10.15, ubuntu-20.04, windows-2019]
runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '16'
- name: Install Dependencies
run: yarn
- name: Build Packages
run: yarn build
- name: Run Tests
run: yarn test
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish Package to npmjs
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
# Defaults to the user or organization that owns the workflow file
scope: '@octocat'
- run: yarn install --frozen-lockfile
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
61 changes: 39 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
{
"name": "foam-cli",
"description": "Foam CLI",
"version": "0.11.0",
"version": "0.17.6",
"bin": {
"foam": "./bin/run"
},
"bugs": "https://github.com/foambubble/foam/issues",
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^3",
"foam-core": "^0.11.0",
"@oclif/command": "^1.8.16",
"@oclif/config": "^1.18.3",
"@oclif/plugin-help": "^5.1.12",
"detect-newline": "^3.1.0",
"fast-array-diff": "^1.0.1",
"github-slugger": "^1.4.0",
"glob": "^7.1.6",
"lodash": "^4.17.21",
"micromatch": "^4.0.2",
"ora": "^4.0.4",
"tslib": "^1"
"remark-frontmatter": "^2.0.0",
"remark-parse": "^8.0.2",
"remark-wiki-link": "^0.0.4",
"title-case": "^3.0.2",
"unified": "^9.0.0",
"unist-util-visit": "^2.0.2",
"yaml": "^1.10.0"
},
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@oclif/dev-cli": "^1",
"@types/node": "^10",
"babel-jest": "^26.1.0",
"@babel/core": "^7.17.8",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@oclif/dev-cli": "^1.26.10",
"@types/github-slugger": "^1.3.0",
"@types/glob": "^7.1.1",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.157",
"@types/micromatch": "^4.0.1",
"@types/node": "^13.11.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"babel-jest": "^27.5.1",
"chai": "^4",
"eslint": "^5.13",
"eslint-config-oclif": "^3.1",
"eslint-config-oclif-typescript": "^0.1",
"eslint": "^8.12.0",
"eslint-import-resolver-typescript": "^2.7.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.3",
"globby": "^10",
"jest": "^26.1.0",
"mock-fs": "^4.12.0",
"ts-node": "^8",
"ts-node": "^10.7.0",
"tslib": "^2.3.1",
"typescript": "^3.3"
},
"peerDependencies": {
"foam-core": "*"
},
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"files": [
"/bin",
Expand All @@ -56,12 +73,12 @@
"@oclif/plugin-help"
]
},
"repository": "foambubble/foam",
"repository": "foambubble/foam-cli",
"scripts": {
"clean": "rimraf tmp",
"build": "tsc -b",
"test": "jest",
"lint": "echo Missing lint task in CLI package",
"lint": "eslint --quiet --ext .js,.ts,.tsx src",
"cli": "yarn build && ./bin/run",
"postpack": "rm -f oclif.manifest.json",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
Expand Down
29 changes: 17 additions & 12 deletions src/commands/janitor.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Command, flags } from '@oclif/command';
import ora from 'ora';
import {
bootstrap,
createConfigFromFolders,
generateLinkReferences,
generateHeading,
applyTextEdit,
FileDataStore,
URI,
isNote,
} from 'foam-core';
import { MarkdownResourceProvider } from "../core/markdown-provider";
import { bootstrap } from '../core/model/foam';
import { URI } from '../core/model/uri';
import { Resource } from '../core/model/note';
import { generateHeading, generateLinkReferences } from '../core/janitor';
import { applyTextEdit } from '../core/janitor/apply-text-edit';
import { FileDataStore, Matcher } from '../core/services/datastore';
import { writeFileToDisk } from '../utils/write-file-to-disk';
import { isValidDirectory } from '../utils';

const isNote = (resource: Resource): resource is Resource => resource.type === 'note'

export default class Janitor extends Command {
static description =
'Updates link references and heading across all the markdown files in the given workspaces';
Expand Down Expand Up @@ -41,8 +40,14 @@ export default class Janitor extends Command {
const { workspacePath = './' } = args;

if (isValidDirectory(workspacePath)) {
const config = createConfigFromFolders([URI.file(workspacePath)]);
const workspace = (await bootstrap(config, { dataStore: new FileDataStore(config)}))
const matcher = new Matcher(
[URI.file(workspacePath)],
['**/*'],
[]
);
const dataStore = new FileDataStore();
const markdownProvider = new MarkdownResourceProvider(matcher);
const workspace = (await bootstrap(matcher, dataStore, [markdownProvider]))
.workspace;

const notes = workspace.list().filter(isNote);
Expand Down
41 changes: 27 additions & 14 deletions src/commands/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import GithubSlugger from 'github-slugger';
import { Command, flags } from '@oclif/command';
import ora from 'ora';
import {
bootstrap,
createConfigFromFolders,
generateLinkReferences,
generateHeading,
getKebabCaseFileName,
applyTextEdit,
FileDataStore,
isNote,
} from 'foam-core';
import { MarkdownResourceProvider } from "../core/markdown-provider";
import { bootstrap } from '../core/model/foam';
import { URI } from '../core/model/uri';
import { Resource } from '../core/model/note';
import { generateHeading, generateLinkReferences } from '../core/janitor';
import { applyTextEdit } from '../core/janitor/apply-text-edit';
import { FileDataStore, Matcher } from '../core/services/datastore';
import { writeFileToDisk } from '../utils/write-file-to-disk';
import { renameFile } from '../utils/rename-file';
import { isValidDirectory } from '../utils';

const slugger = new GithubSlugger();

const isNote = (resource: Resource): resource is Resource => resource.type === 'note'

const getKebabCaseFileName = (fileName: string) => {
const kebabCasedFileName = slugger.slug(fileName);
return kebabCasedFileName === fileName ? null : kebabCasedFileName;
};

// @todo: Refactor 'migrate' and 'janitor' commands and avoid repeatition
export default class Migrate extends Command {
static description =
Expand Down Expand Up @@ -42,11 +49,17 @@ Successfully generated link references and heading!
const { args, flags } = this.parse(Migrate);

const { workspacePath = './' } = args;
const config = createConfigFromFolders([workspacePath]);

const matcher = new Matcher(
[URI.file(workspacePath)],
['**/*'],
[]
);
const dataStore = new FileDataStore();
const markdownProvider = new MarkdownResourceProvider(matcher);

if (isValidDirectory(workspacePath)) {
const dataStore = new FileDataStore(config);
let workspace = (await bootstrap(config, { dataStore: dataStore})).workspace;
let workspace = (await bootstrap(matcher, dataStore, [markdownProvider])).workspace;

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

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

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

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

Expand Down
36 changes: 36 additions & 0 deletions src/core/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"rules": {
"no-restricted-imports": [
"error",
{
"name": "vscode",
"message": "Core submodule must not depend on VS Code."
}
]
// Ideally we would also prevent the core module from depending on other modules
// but I have been struggling to get it to work.
// For future reference, below are some configurations I think should achieve this
// (but I couldn't manage to get working).
//
// "import/no-internal-modules": [
// "error",
// {
// "allow": ["./src/core"]
// }
// ]
// "import/no-restricted-paths": [
// "error",
// {
// "zones": [
// {
// "target": "./src/core",
// "from": "./src/(!core)",
// "message": "Core module can't have outside dependencies."
// }
// ]
// }
// ]
// "import/no-relative-parent-imports": "error"
// note: https://github.com/import-js/eslint-plugin-import/issues/1610
}
}
Loading