Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
feat: add commands directly on settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Aug 22, 2022
1 parent b3cc6ba commit 1cc042f
Show file tree
Hide file tree
Showing 10 changed files with 4,140 additions and 181 deletions.
168 changes: 83 additions & 85 deletions .github/workflows/npm_release.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,89 @@
name: Manually release
name: Release Obsidian plugin

on:
workflow_dispatch

workflow_dispatch:
push:
tags:
- "*"
env:
PLUGIN_NAME: obsidian-snippet-downloader # Change this to match the id of your plugin.

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "14.x"
- name: Release
id: release
run: |
git config --global user.name 'github-release'
git config --global user.email 'github-release@users.noreply.github.com'
npm install
npm run release
git push --follow-tags origin master
build:
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Latest-tag
id: get-latest-tag
uses: actions-ecosystem/action-get-latest-tag@v1
- name: Build
id: build
run: |
npm install
npm run build
mkdir ${{ env.PLUGIN_NAME }}
cp main.js manifest.json ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
npx rexreplace "^.*?#+\s\[.*?\n.*?(?=\s*#+\s\[)" "_" -s -M -G -m -o "CHANGELOG.md" > CHANGELOG-LATEST.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.ref }}
with:
tag_name: ${{ steps.get-latest-tag.outputs.tag }}
release_name: ${{ steps.get-latest-tag.outputs.tag }}
body_path: CHANGELOG-LATEST.md
draft: false
prerelease: false
- name: Upload zip file
id: upload-zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.PLUGIN_NAME }}.zip
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
asset_content_type: application/zip
- name: Upload main.js
id: upload-main
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./main.js
asset_name: main.js
asset_content_type: text/javascript
- name: Upload manifest.json
id: upload-manifest
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./manifest.json
asset_name: manifest.json
asset_content_type: application/json
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Build
id: build
run: |
npm install
npm run build
mkdir ${{ env.PLUGIN_NAME }}
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
npx rexreplace "^.*?#+\s\[.*?\n.*?(?=\s*#+\s\[)" "_" -s -M -G -m -o "CHANGELOG.md" > CHANGELOG-LATEST.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.ref }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body_path: CHANGELOG-LATEST.md
draft: false
prerelease: false

- name: Upload zip file
id: upload-zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.PLUGIN_NAME }}.zip
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
asset_content_type: application/zip

- name: Upload main.js
id: upload-main
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./main.js
asset_name: main.js
asset_content_type: text/javascript

- name: Upload manifest.json
id: upload-manifest
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./manifest.json
asset_name: manifest.json
asset_content_type: application/json

- name: Upload styles.css
id: upload-css
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./styles.css
asset_name: styles.css
asset_content_type: text/css

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ In setting, you can :

So, the commands added by the plugins are :
- **Adding new Snippet** : Use `https://github.com/username/repo` or `username/repo` to add a new repository and download the present css snippet.
- **Update All snippet** : Update all repository and their snippet (unless you exclude them).
- **Update all snippet** : Update all repository and their snippet (unless you exclude them).
- **Update Specific snippet** : You can just update one snippet using its name.
- **Update Specific Repository** : You can just update one repository using its name.

💡Note : The file will be updated only if there is a new commit ! It's not based on the file contents.

Also, alternatively, you can use the settings tab to add a repository, delete a repository, exclude a snippets, etc.

<table>
<tbody>
<tr>
Expand Down
1 change: 1 addition & 0 deletions Snippet-downloader/addSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function updateRepo(repoPath: string, snippetList: SnippetRepo[], v
}
snippetList = removeSnippetFromExcluded(repoPath,snippetList, errorSnippets, excludedSnippets);
new Notice(`${repoPath} successfully updated 🎉`);
console.log(errorSnippets, snippetList);
return [errorSnippets, snippetList];
}

Expand Down
1 change: 1 addition & 0 deletions Snippet-downloader/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export async function downloadSnippet(repoPath: string, snippetName: string, vau
repo: repoName,
path: snippetName
});
console.log(file.status)
if (file.status === 200) {
// @ts-ignore
const fileContent = Base64.decode(file.data.content);
Expand Down
17 changes: 17 additions & 0 deletions Snippet-downloader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ import {addSnippet, updateRepo} from "./addSnippets";
export default class snippetDownloader extends Plugin {
settings: SnippetDownloaderSettings;

async updateAllSnippets() {
if (this.settings.snippetList.length > 0) {
const snippetList = this.settings.snippetList;
const errorSnippet = this.settings.errorSnippet;
const excludedSnippet = this.settings.excludedSnippet;
let updatedSettings = [errorSnippet, snippetList];
for (const repoName of snippetList) {
//@ts-ignore
updatedSettings= await updateRepo(repoName.repo, snippetList, this.app.vault, excludedSnippet, errorSnippet);
this.settings.snippetList = <SnippetRepo[]>updatedSettings[1];
this.settings.errorSnippet = <string>updatedSettings[0];
}
await this.saveSettings();
}
}

async onload() {
await this.loadSettings();

Expand All @@ -33,6 +49,7 @@ export default class snippetDownloader extends Plugin {
this.addCommand({
id: 'update-all-snippets',
name: 'Update all snippets',
//@ts-ignore
checkCallback: async (checking: boolean) => {
if (this.settings.snippetList.length > 0) {
if (!checking) {
Expand Down
8 changes: 4 additions & 4 deletions Snippet-downloader/modals/excludeSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import snippetDownloader from "../main";
import {basename, searchExcluded} from "../utils";
import {removeSnippetFromExcluded} from "../removeSnippet";

interface SnippetExclude {
export interface SnippetExclude {
repo: string;
snippetPath: string;
}

function getAllSnippet(settings: SnippetDownloaderSettings) {
export function getExcludedSnippets(settings: SnippetDownloaderSettings) {
const allSnippet: SnippetExclude[] = [];
for (const snippet of settings.snippetList) {
for (const snippetContent of snippet.snippetsContents) {
Expand All @@ -24,7 +24,7 @@ function getAllSnippet(settings: SnippetDownloaderSettings) {
return allSnippet
}

async function addExcludedSnippet(item: SnippetExclude, settings: SnippetDownloaderSettings){
export async function addExcludedSnippet(item: SnippetExclude, settings: SnippetDownloaderSettings){
let excludedSnippet = settings.excludedSnippet;
excludedSnippet = excludedSnippet + ', ' + item.snippetPath;
const snippetList = removeSnippetFromExcluded(item.repo, settings.snippetList, settings.errorSnippet, excludedSnippet);
Expand All @@ -47,7 +47,7 @@ export class ExcludeSnippet extends FuzzySuggestModal<SnippetExclude> {
}

getItems(): SnippetExclude[] {
return getAllSnippet(this.settings)
return getExcludedSnippets(this.settings)
}

async onChooseItem(item: SnippetExclude, evt: MouseEvent | KeyboardEvent) {
Expand Down
2 changes: 1 addition & 1 deletion Snippet-downloader/modals/updateSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getAllRepo(settings: SnippetDownloaderSettings){
return repoAll
}

function getAllSnippet(settings: SnippetDownloaderSettings) {
export function getAllSnippet(settings: SnippetDownloaderSettings) {
const allSnippet: SnippetUpdate[] = [];
for (const snippet of settings.snippetList) {
for (const snippetContent of snippet.snippetsContents) {
Expand Down
Loading

0 comments on commit 1cc042f

Please sign in to comment.