-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customize JSON output & general script improvements (#20)
- Customize JSON output: it's now possible to choose which keys should be saved in the output JSON file, both from the console and from the extension (#19 (comment)) - Changed how the extension handles older Firefox versions that don't support the "chrome" namespace - Now a "source.zip" file is built for the extension release, that contains everything necessary for building the extension - Improved the usage of variables in the script: only the global values are stored with "var" so that they can be re-written in Gecko and WebKit, but there is no need to use them in the functions - Improved the script documentation, by adding descriptions directly tied to functions and variables
- Loading branch information
1 parent
32a55fb
commit 998bba9
Showing
11 changed files
with
161 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
const fs = require("fs"); | ||
const zip = require("jszip"); | ||
const sep = require("path").sep; | ||
// BUILDING OUTPUT | ||
(fs.existsSync("output")) && fs.rmSync("output", { recursive: true }); | ||
fs.mkdirSync("output"); | ||
require("child_process").execSync("cd code/vite && npm i && npx vite build --base=ui"); | ||
require("fs-extra").moveSync(`./code/vite/dist`, `./output/ui`); | ||
fs.mkdirSync("output/icons"); | ||
for (let item of ["manifest.json", "icons/16.png", "icons/48.png", "icons/128.png"]) fs.copyFileSync(`./code/${item}`, `./output/${item}`); | ||
let firstScript = fs.readFileSync(`../script.js`, "utf-8"); | ||
require("child_process").execSync(`cd code${sep}vite && npm i && npx vite build --base=ui`); | ||
require("fs-extra").moveSync(`.${sep}code${sep}vite${sep}dist`, `.${sep}output${sep}ui`); | ||
fs.mkdirSync(`output${sep}icons`); | ||
for (let item of ["manifest.json", `icons${sep}16.png`, `icons${sep}48.png`, `icons${sep}128.png`]) fs.copyFileSync(`code${sep}${item}`, `output${sep}${item}`); | ||
let firstScript = fs.readFileSync(`..${sep}script.js`, "utf-8"); | ||
firstScript = firstScript.substring(0, firstScript.indexOf("nodeElaborateCustomArgs();")); | ||
fs.writeFileSync(`./output/extensionHandler.js`, `${firstScript}${fs.readFileSync("./code/extensionHandler.js", "utf-8")}`); | ||
fs.writeFileSync(`output${sep}extensionHandler.js`, `${firstScript}${fs.readFileSync(`code${sep}extensionHandler.js`, "utf-8")}`); | ||
const zipFile = new zip(); | ||
for (let file of fs.readdirSync("./output", { recursive: true })) if (fs.statSync(`./output/${file}`).isFile()) zipFile.file(file, fs.readFileSync(`./output/${file}`), { createFolders: true }); | ||
for (let file of fs.readdirSync("output", { recursive: true })) if (fs.statSync(`output${sep}${file}`).isFile()) zipFile.file(file, fs.readFileSync(`output${sep}${file}`), { createFolders: true }); | ||
zipFile.generateAsync({ type: "nodebuffer" }).then((buffer) => fs.writeFileSync("output.zip", buffer)); | ||
// BUILDING SOURCE CODE ZIP | ||
const sourceCode = new zip(); | ||
sourceCode.file(`README.md`, `# Build instrutions\n\nYou can find instructions to build this extension in the "extension" folder.\n\nRequirements: Node JS 20; NPM. Tested only on macOS and Linux.`); | ||
sourceCode.file("script.js", fs.readFileSync(`..${sep}script.js`)); | ||
for (const item of ["build.js", "package.json", "package-lock.json", "README.md"]) sourceCode.file(`extension${sep}${item}`, fs.readFileSync(item)); | ||
for (const item of fs.readdirSync("code", { recursive: true }).filter(item => item.indexOf("node_modules") === -1)) if (fs.statSync(`code${sep}${item}`).isFile()) sourceCode.file(`extension${sep}code${sep}${item}`, fs.readFileSync(`code${sep}${item}`)); | ||
sourceCode.generateAsync({ type: "nodebuffer" }).then((buffer) => fs.writeFileSync("source.zip", buffer)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script lang="ts"> | ||
import { slide } from "svelte/transition"; | ||
import Card from "../Card.svelte"; | ||
import Settings from "./SettingsContainer"; | ||
function changeJson(e: Event, str: string) { | ||
(e.target as HTMLInputElement).checked | ||
? $Settings.exclude_from_json.push(str) | ||
: $Settings.exclude_from_json.splice( | ||
$Settings.exclude_from_json.indexOf(str), | ||
1, | ||
); | ||
$Settings.exclude_from_json = $Settings.exclude_from_json; | ||
} | ||
</script> | ||
|
||
<div in:slide={{ duration: 500 }} out:slide={{ duration: 500 }}> | ||
<Card> | ||
<h2>JSON output:</h2> | ||
<p> | ||
Choose which elements will be deleted from the JSON output. If you | ||
keep only one item, the output will be a string array. | ||
</p> | ||
<br /> | ||
{#each ["url", "views", "caption"] as item} | ||
<label class="flex hcenter autoGap"> | ||
<input | ||
type="checkbox" | ||
checked={$Settings.exclude_from_json.indexOf(item) !== -1} | ||
on:change={(e) => changeJson(e, item)} | ||
/> | ||
Exclude {item} from the output JSON | ||
</label><br /> | ||
{/each} | ||
</Card> | ||
</div> | ||
|
||
<style> | ||
input { | ||
background-color: var(--input); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.