Skip to content

Commit a29016e

Browse files
authored
Merge pull request #118 from waymondrang/tab-opener
tab api link opener, scss cleanup, and build script update
2 parents 5c4042a + fc7f235 commit a29016e

File tree

13 files changed

+293
-243
lines changed

13 files changed

+293
-243
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"homepage": "https://docsafterdark.com/",
3636
"scripts": {
37-
"build": "webpack --mode=production && sass src/scss/docs.scss build/docs.bundle.css && sass src/scss/frame.scss build/frame.bundle.css && sass src/scss/global.scss build/global.bundle.css && web-ext lint --source-dir=build && ts-node package.ts",
37+
"build": "webpack --mode=production && ts-node package.ts --check && sass src/scss/docs.scss build/docs.bundle.css && sass src/scss/frame.scss build/frame.bundle.css && sass src/scss/global.scss build/global.bundle.css && web-ext lint --source-dir=build && ts-node package.ts",
3838
"check": "prettier --check . && eslint src && stylelint '**/*.scss'",
3939
"dev": "concurrently --names 'webpack,sass,sass,sass' --prefix-colors 'magenta,red,blue,yellow' 'webpack --watch' 'sass --watch src/scss/docs.scss build/docs.bundle.css' 'sass --watch src/scss/frame.scss build/frame.bundle.css' 'sass --watch src/scss/global.scss build/global.bundle.css'",
4040
"firefox": "web-ext run --source-dir build/ --keep-profile-changes",

package.ts

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ class Logger {
8080
}
8181
}
8282

83+
function getManifest(): Manifest {
84+
const manifestPath = resolve(CONFIG.manifestPath);
85+
if (!existsSync(manifestPath)) {
86+
Logger.error(`Manifest file not found at: ${manifestPath}`);
87+
process.exit(1);
88+
}
89+
90+
const manifestContent = readFileSync(manifestPath, "utf-8");
91+
const manifest = JSON.parse(manifestContent) as Manifest;
92+
93+
if (!manifest.version) {
94+
Logger.error("Version not found in manifest.json");
95+
process.exit(1);
96+
}
97+
98+
return manifest;
99+
}
100+
101+
function getZipFileName(version: string): string {
102+
return `${CONFIG.extensionName}_${version}.zip`;
103+
}
104+
105+
function getZipFilePath(version: string): string {
106+
return join(resolve(CONFIG.releaseDir), getZipFileName(version));
107+
}
108+
83109
///////////////
84110
// PACKAGING //
85111
///////////////
@@ -89,30 +115,23 @@ interface Manifest {
89115
[key: string]: unknown;
90116
}
91117

92-
async function packageExtension(force: boolean = false): Promise<void> {
118+
async function packageExtension(
119+
manifest: Manifest,
120+
force: boolean = false
121+
): Promise<void> {
93122
try {
94123
///////////////////
95124
// READ MANIFEST //
96125
///////////////////
97126

98-
Logger.step("Reading manifest.json");
127+
Logger.step("Processing manifest.json");
99128

100-
const manifestPath = resolve(CONFIG.manifestPath);
101-
if (!existsSync(manifestPath)) {
102-
Logger.error(`Manifest file not found at: ${manifestPath}`);
103-
process.exit(1);
104-
}
105-
106-
const manifestContent = readFileSync(manifestPath, "utf-8");
107-
const manifest = JSON.parse(manifestContent) as Manifest;
108129
const version = manifest.version;
109130

110-
if (!version) {
111-
Logger.error("Version not found in manifest.json");
112-
process.exit(1);
113-
}
131+
const zipFilePath = getZipFilePath(version);
132+
const zipFileName = getZipFileName(version);
114133

115-
Logger.info(`Found manifest version: ${version}`);
134+
Logger.info(`Manifest version: ${version}`);
116135

117136
///////////////
118137
// BUILD DIR //
@@ -125,23 +144,22 @@ async function packageExtension(force: boolean = false): Promise<void> {
125144
}
126145

127146
//////////////////////
128-
// EXISTING RELEASE //
147+
// EXISTING PACKAGE //
129148
//////////////////////
130149

131-
Logger.step("Checking for existing release");
150+
// Sanity check, do not print step
132151

133-
const zipFileName = `${CONFIG.extensionName}_${version}.zip`;
134-
const zipFilePath = join(resolve(CONFIG.releaseDir), zipFileName);
152+
const packageExists = existsSync(zipFilePath);
135153

136-
if (existsSync(zipFilePath) && !force) {
154+
if (packageExists && !force) {
137155
Logger.warn(
138-
`Release already exists: ${zipFilePath}. Use --force flag to overwrite existing release.`
156+
`Package already exists: ${zipFilePath}. Use --force flag to overwrite existing package.`
139157
);
140158
process.exit(2);
141159
}
142160

143-
if (existsSync(zipFilePath) && force) {
144-
Logger.info(`Overwriting existing release: ${zipFilePath}`);
161+
if (packageExists && force) {
162+
Logger.info(`Overwriting existing package: ${zipFilePath}`);
145163
}
146164

147165
//////////////
@@ -216,5 +234,22 @@ async function packageExtension(force: boolean = false): Promise<void> {
216234

217235
const args = process.argv.slice(2);
218236
const withForce = args.includes("--force") || args.includes("-f");
237+
const onlyPackageCheck = args.includes("--check") || args.includes("-c");
238+
239+
const manifest = getManifest();
240+
const version = manifest.version;
241+
242+
if (onlyPackageCheck) {
243+
const zipFilePath = getZipFilePath(version);
244+
245+
if (existsSync(zipFilePath)) {
246+
Logger.warn(
247+
`Package already exists: ${zipFilePath}. Use --force flag to overwrite existing package.`
248+
);
249+
process.exit(1);
250+
}
251+
252+
process.exit(0);
253+
}
219254

220-
packageExtension(withForce);
255+
packageExtension(manifest, withForce);

src/docs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
documentBorder,
66
documentInvert,
77
enabledClass,
8+
links,
89
replacements,
910
themeClasses,
10-
updateLink,
1111
} from "./values";
1212
import { Logger } from "./logger";
1313
import {
@@ -519,7 +519,7 @@ class DocsAfterDark {
519519
messageElement.appendChild(textElement);
520520

521521
const linkElement = document.createElement("a");
522-
linkElement.href = updateLink;
522+
linkElement.href = links.update;
523523
linkElement.target = "_blank";
524524
linkElement.textContent = "GitHub";
525525

src/popup.html

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ <h3 class="sectionTitle">Accent Color</h3>
101101
min="0"
102102
max="360"
103103
placeholder="0"
104-
maxlength="3"
105104
/>
106105
</div>
107106
</div>
@@ -203,10 +202,10 @@ <h3 class="sectionTitle">Border</h3>
203202
name="documentBorder"
204203
/>
205204

206-
<div class="checkbox"></div>
207-
<div class="content">
205+
<span class="checkbox"></span>
206+
<span class="content">
208207
<span>Show</span>
209-
</div>
208+
</span>
210209
</label>
211210
</div>
212211
</div>
@@ -257,10 +256,10 @@ <h3 class="sectionTitle">Toggle Button</h3>
257256
name="showButton"
258257
/>
259258

260-
<div class="checkbox"></div>
261-
<div class="content">
259+
<span class="checkbox"></span>
260+
<span class="content">
262261
<span>Show</span>
263-
</div>
262+
</span>
264263
</label>
265264
</div>
266265
</div>
@@ -286,18 +285,11 @@ <h3 class="sectionTitle">Invert</h3>
286285
<span id="version">v0.0.0</span>
287286

288287
<div class="flexRow gap">
289-
<a
290-
id="donate"
291-
class="button rounded accented"
292-
href="https://www.buymeacoffee.com/waymondrang"
293-
>Donate</a
294-
>
288+
<button id="donateLink" class="rounded accented">
289+
Donate
290+
</button>
295291

296-
<a
297-
id="github"
298-
class="button rounded accented"
299-
href="https://github.com/waymondrang/docsafterdark"
300-
>
292+
<button id="githubLink" class="rounded accented">
301293
<svg
302294
viewBox="0 0 98 96"
303295
fill="none"
@@ -315,7 +307,7 @@ <h3 class="sectionTitle">Invert</h3>
315307
</clipPath>
316308
</defs>
317309
</svg>
318-
</a>
310+
</button>
319311
</div>
320312
</footer>
321313
</main>

src/popup.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
setStorage,
1515
setStyleProperty,
1616
} from "./util";
17-
import { defaultExtensionData } from "./values";
17+
import { defaultExtensionData, links } from "./values";
1818

1919
const browser_ns = getBrowserNamespace();
2020
const VERSION = browser_ns.runtime.getManifest().version;
@@ -572,6 +572,29 @@ class StyleManager extends StateSubscriber {
572572
}
573573
}
574574

575+
class LinkManager {
576+
private githubLink = document.querySelector(
577+
"#githubLink"
578+
) as HTMLButtonElement;
579+
private donateLink = document.querySelector(
580+
"#donateLink"
581+
) as HTMLButtonElement;
582+
583+
initialize(): void {
584+
this.githubLink.addEventListener("click", () => {
585+
browser_ns.tabs.create({
586+
url: links.github,
587+
});
588+
});
589+
590+
this.donateLink.addEventListener("click", () => {
591+
browser_ns.tabs.create({
592+
url: links.donate,
593+
});
594+
});
595+
}
596+
}
597+
575598
class Popup extends PopupState {
576599
private modeComponent: ModeComponent = new ModeComponent(this);
577600
private darkModeComponent: DarkModeComponent = new DarkModeComponent(this);
@@ -585,6 +608,7 @@ class Popup extends PopupState {
585608
private versionComponent: VersionComponent = new VersionComponent();
586609

587610
private styleManager: StyleManager = new StyleManager(this);
611+
private linkManager: LinkManager = new LinkManager();
588612

589613
private advancedCategoryComponent: toggleCategoryComponent =
590614
new toggleCategoryComponent("advancedCategory");
@@ -607,6 +631,7 @@ class Popup extends PopupState {
607631
this.invertComponent.initialize();
608632
this.versionComponent.initialize();
609633
this.styleManager.initialize();
634+
this.linkManager.initialize();
610635
this.advancedCategoryComponent.initialize();
611636

612637
this.updateSubscribers();

0 commit comments

Comments
 (0)