From 630d5c71abc0c15950d27d25bd8941167001c26a Mon Sep 17 00:00:00 2001 From: divyabshiva Date: Wed, 8 Nov 2023 14:28:39 -0500 Subject: [PATCH] release workflow --- .github/workflows/release.yml | 34 ++++++++++++++++++++++++++++++++++ src/hunchly.ts | 31 +++++++++++++++++-------------- src/main.ts | 2 +- 3 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e2f27c3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release Hunchly plugin + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + + - name: Build plugin + run: | + npm install + npm run build + + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + tag="${GITHUB_REF#refs/tags/}" + + gh release create "$tag" \ + --title="$tag" \ + --draft \ + main.js manifest.json \ No newline at end of file diff --git a/src/hunchly.ts b/src/hunchly.ts index 81ab376..f450de0 100644 --- a/src/hunchly.ts +++ b/src/hunchly.ts @@ -1,6 +1,6 @@ import * as fs_promise from 'fs/promises'; import * as fs from 'fs'; -import { FileSystemAdapter, Plugin, TFile, Vault } from 'obsidian'; +import { FileSystemAdapter, Plugin, TFile, Vault, Notice } from 'obsidian'; import * as path from 'path' import * as unzipper from 'unzipper'; import * as tmp from 'tmp'; @@ -67,6 +67,11 @@ export class Hunchly{ // Pipe the read stream through unzipper to extract the contents. await readStream.pipe(unzipper.Extract({ path: extractionPath })).promise(); + + if (!await this.checkFileOrFolderExistence(extractionPath, "case_data")){ + new Notice("Not a valid hunchly case file. Use Export > Export Case in the hunchly dashboard.", 5000) + return + } const pages = await extractPages(extractionPath) const notes = await extractNotes(extractionPath) @@ -80,8 +85,8 @@ export class Hunchly{ setTimeout(()=>{tempDir.removeCallback();}, 3000); } catch (error) { - this.updateStatus("Error processing hunchly zip file"); - console.error(`Error processing hunchly zip file": ${error}`); + new Notice("Not a valid hunchly case zip file.", 5000) + console.log(`Error processing hunchly zip file: ${error}`); } } @@ -91,8 +96,6 @@ export class Hunchly{ await fs_promise.access(filePath); return true; } catch (err) { - // This adds a status bar saying invalid note path - this.updateStatus(filePath + " does not exist"); return false; } } @@ -185,7 +188,7 @@ export class Hunchly{ try { await this.vault.createFolder(path.join(this.hunchlyLocation, directoryPath)) } catch (error) { - console.error(`Error creating the directory: ${error}`); + console.log(error); } } @@ -214,7 +217,7 @@ export class Hunchly{ const notepath = path.join(this.hunchlyLocation, "hunchly_notes", filename) await this.vault.create(notepath, content) } catch (error) { - console.error(`Error creating the file in ${filename}: ${error}`); + console.log(`Error creating the file in ${filename}: ${error}`); } } @@ -227,7 +230,7 @@ export class Hunchly{ this.vault.append(notefile, content) } } catch (error) { - console.error(`Error appending the file in ${filename}: ${error}`); + console.log(`Error appending the file in ${filename}: ${error}`); } } @@ -267,7 +270,7 @@ async function extractSelectorsHits(zipFilePath: string): Promise> }); } } catch (error) { - console.error(`Error parsing the tagged_photos.JSON file: ${error}`); + console.log(`Error parsing the tagged_photos.JSON file: ${error}`); } return results @@ -338,7 +341,7 @@ async function extractNotes(zipFilePath: string): Promise> { }); } } catch (error) { - console.error(`Error parsing the notes JSON file: ${error}`); + console.log(`Error parsing the notes JSON file: ${error}`); } return results @@ -362,7 +365,7 @@ async function extractPages(zipFilePath: string): Promise> { }); } } catch (error) { - console.error(`Error parsing the pages JSON file: ${error}`); + console.log(`Error parsing the pages JSON file: ${error}`); } return results } @@ -372,7 +375,7 @@ async function copyImages(sourcePath: string, destinationPath: string): Promise< const fileContent = await fs_promise.readFile(sourcePath); await fs_promise.writeFile(destinationPath, fileContent); } catch (error) { - console.error(`Error copying the file: ${error}`); + console.log(`Error copying the file: ${error}`); } } diff --git a/src/main.ts b/src/main.ts index 13ff917..be8e78e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,7 +25,7 @@ export default class HunchlyObsidianPlugin extends Plugin { // Called when the user clicks the icon. new FileModal(this.app, "Select the exported hunchly case file (zip format).", (result) => { if (result.zipPath){ - new Notice('Processing the hunchly notes and images in path ' + result.zipPath, 5000); + new Notice('Processing the hunchly notes and images in path ' + result.zipPath, 3000); const hunchly = new Hunchly(result.zipPath, result.location, result.consolidate, this) hunchly.process() }