- Sheets: CSV export and save support, Excel-matching data validation - Docs: image, shape, WordArt, and chart rendering fixes - Slides: downloadable font catalog with a missing-font banner - Slides: better AI text layout and a speaker-notes tool Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
507 lines
19 KiB
JavaScript
507 lines
19 KiB
JavaScript
/**
|
|
* electron-builder configuration (moved out of package.json "build" so the
|
|
* auto-update feed URL can be injected at build time instead of living in
|
|
* the repo).
|
|
*
|
|
* GENOFFICE_UPDATE_URL — public base URL of the update channel (the generic
|
|
* provider prefix that serves latest.yml / latest-mac.yml). Required for
|
|
* release builds; CI provides it as a repository secret. For local release
|
|
* builds put it in apps/shell/electron-builder.env (gitignored) — the
|
|
* electron-builder CLI loads that file automatically.
|
|
*
|
|
* When the variable is unset (forks, PR smoke builds, plain local packaging)
|
|
* the publish config is omitted: electron-builder then bakes no
|
|
* app-update.yml into the app and in-app auto-update stays disabled.
|
|
*
|
|
* GENOFFICE_GA4_MEASUREMENT_ID / GENOFFICE_GA4_API_SECRET — GA4 Measurement
|
|
* Protocol credentials for anonymous usage analytics, injected the same way
|
|
* (CI secrets, or apps/shell/electron-builder.env locally). They are written
|
|
* into the packaged app's package.json via extraMetadata and read back by
|
|
* src/main/analytics.ts. When either is unset — every source/fork build —
|
|
* nothing is injected and the app runs with analytics fully disabled.
|
|
*
|
|
* GENOFFICE_FONT_CDN_URL — base URL for the curated downloadable-font catalog.
|
|
* Official release jobs inject it through extraMetadata so the endpoint stays
|
|
* out of source. Without it, font download prompts/catalog entries are hidden;
|
|
* users can still install local font files.
|
|
*/
|
|
|
|
const { execFileSync } = require('node:child_process')
|
|
const { existsSync, rmSync } = require('node:fs')
|
|
const { join } = require('node:path')
|
|
|
|
function normalizeHttpsBaseUrl(name, value) {
|
|
if (!value || !value.trim()) return null
|
|
try {
|
|
const url = new URL(value.trim())
|
|
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) {
|
|
throw new Error('invalid')
|
|
}
|
|
return `${url.origin}${url.pathname.replace(/\/+$/, '')}`
|
|
} catch {
|
|
throw new Error(`${name} must be an HTTPS base URL without credentials, query, or fragment`)
|
|
}
|
|
}
|
|
|
|
const updateUrl = process.env.GENOFFICE_UPDATE_URL
|
|
const ga4MeasurementId = process.env.GENOFFICE_GA4_MEASUREMENT_ID
|
|
const ga4ApiSecret = process.env.GENOFFICE_GA4_API_SECRET
|
|
const fontCdnUrl = normalizeHttpsBaseUrl(
|
|
'GENOFFICE_FONT_CDN_URL',
|
|
process.env.GENOFFICE_FONT_CDN_URL,
|
|
)
|
|
|
|
// GENOFFICE_MAC_X64=1 — opt into packaging the Intel (x64) dmg/zip alongside
|
|
// arm64. Off by default: Intel packages must only ever ship signed with the
|
|
// company certificate (planned dual-track pipeline), so the current release
|
|
// pipeline stays arm64-only and never produces a personally-signed Intel
|
|
// artifact. The downstream layout (feed archive name, GenOffice-intel.dmg
|
|
// alias) keys off which dmgs exist, so flipping this flag is the single
|
|
// switch.
|
|
const includeMacX64 = process.env.GENOFFICE_MAC_X64 === '1'
|
|
|
|
// The gsk CLI tree below is copied verbatim from node_modules, and the
|
|
// nested commander path depends on npm's current hoisting layout — fail the
|
|
// build with a clear message if an install ever changes it, instead of
|
|
// shipping an installer with a broken gsk runtime.
|
|
// LICENSES.chromium.html only exists after the Electron binary download —
|
|
// since Electron 42 that no longer happens during `npm ci` (the postinstall
|
|
// script was replaced by the lazy `install-electron` bin), and electron-builder
|
|
// exits 0 on a missing extraResources source, so without this check the
|
|
// installer would silently ship without the Chromium license.
|
|
for (const rel of [
|
|
'../../node_modules/@genspark/cli',
|
|
'../../node_modules/@genspark/cli/node_modules/commander',
|
|
'../../node_modules/ws',
|
|
'../../node_modules/electron/dist/LICENSES.chromium.html',
|
|
'../../node_modules/@embedpdf/pdfium/dist/pdfium.wasm',
|
|
'../pdf/node_modules/harfbuzzjs/hb-subset.wasm',
|
|
]) {
|
|
if (!existsSync(join(__dirname, rel))) {
|
|
throw new Error(
|
|
`electron-builder extraResources source missing: ${rel} (npm hoisting changed?)`,
|
|
)
|
|
}
|
|
}
|
|
|
|
// macOS local-OCR helper (scanned-page text recovery): a swiftc output, not
|
|
// an npm artifact — compiled here on demand so CI runners and fresh checkouts
|
|
// need no manual step. Universal (arm64 + x86_64) when both targets compile,
|
|
// host-arch otherwise; mac installers must not silently ship without it.
|
|
const VISION_OCR_HELPER = '../../packages/pdf2docx/ocr-helper/vision-ocr'
|
|
|
|
// Compile the helper. universalOnly=true has NO host-arch fallback: dual-arch
|
|
// packaging must fail loudly rather than ship a host-arch binary to both dmgs.
|
|
function compileVisionOcr({ universalOnly } = { universalOnly: false }) {
|
|
const src = join(__dirname, `${VISION_OCR_HELPER}.swift`)
|
|
const out = join(__dirname, VISION_OCR_HELPER)
|
|
try {
|
|
try {
|
|
const slices = ['arm64', 'x86_64'].map((arch) => {
|
|
const slice = `${out}.${arch}`
|
|
execFileSync('swiftc', ['-O', src, '-target', `${arch}-apple-macos12`, '-o', slice], {
|
|
stdio: 'inherit',
|
|
})
|
|
return slice
|
|
})
|
|
execFileSync('lipo', ['-create', ...slices, '-output', out], { stdio: 'inherit' })
|
|
for (const slice of slices) rmSync(slice, { force: true })
|
|
} catch (err) {
|
|
if (universalOnly) throw err
|
|
// cross-target SDK unavailable — a host-arch helper still serves this build
|
|
execFileSync('swiftc', ['-O', src, '-o', out], { stdio: 'inherit' })
|
|
}
|
|
} catch (err) {
|
|
throw new Error(`vision-ocr helper compile failed: ${err}`, { cause: err })
|
|
}
|
|
}
|
|
|
|
if (process.platform === 'darwin' && !existsSync(join(__dirname, VISION_OCR_HELPER))) {
|
|
compileVisionOcr()
|
|
}
|
|
|
|
// Windows local-OCR helper (Windows.Media.Ocr): compiled by the in-box .NET
|
|
// Framework csc via build-win.mjs — same on-demand policy as the mac helper,
|
|
// and Windows installers must not silently ship without it.
|
|
const WIN_OCR_HELPER = '../../packages/pdf2docx/ocr-helper/win-ocr.exe'
|
|
if (process.platform === 'win32' && !existsSync(join(__dirname, WIN_OCR_HELPER))) {
|
|
try {
|
|
execFileSync(
|
|
process.execPath,
|
|
[join(__dirname, '../../packages/pdf2docx/ocr-helper/build-win.mjs')],
|
|
{ stdio: 'inherit' },
|
|
)
|
|
} catch (err) {
|
|
throw new Error(`win-ocr helper compile failed: ${err}`, { cause: err })
|
|
}
|
|
}
|
|
|
|
// Dual-arch packs share one extraResources path, so the shipped helper must be
|
|
// a lipo fat binary. A stale host-arch build (dev path above) is rebuilt in
|
|
// place; if a universal build cannot be produced, packaging aborts — otherwise
|
|
// the other arch's OCR silently fails and every scanned page ships as bitmap.
|
|
function assertUniversalVisionOcr() {
|
|
const helper = join(__dirname, VISION_OCR_HELPER)
|
|
const wanted = ['x86_64', 'arm64']
|
|
const archsOf = () =>
|
|
existsSync(helper)
|
|
? execFileSync('lipo', ['-archs', helper], { encoding: 'utf8' }).trim().split(/\s+/)
|
|
: []
|
|
if (!wanted.every((w) => archsOf().includes(w))) {
|
|
rmSync(helper, { force: true })
|
|
compileVisionOcr({ universalOnly: true })
|
|
}
|
|
const archs = archsOf()
|
|
for (const want of wanted) {
|
|
if (!archs.includes(want)) {
|
|
throw new Error(
|
|
`vision-ocr helper is [${archs.join(', ')}] but both mac arch packages ship it`,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The module trees are electron-vite outputs produced by build:all; a missing
|
|
// one means that module's build did not run or failed. electron-builder only
|
|
// logs "file source doesn't exist" for an absent extraResources source and
|
|
// still exits 0, so without this the installer launches normally and is simply
|
|
// missing that editor — it surfaces only when a user opens the tab.
|
|
//
|
|
// Runs from the beforePack hook, not at module load: gen-third-party-notices
|
|
// requires this config to read extraResources, and the dist:* scripts run
|
|
// notices before build:all, when the out dirs legitimately don't exist yet.
|
|
// When the mac build packages BOTH arches (GENOFFICE_MAC_X64=1) its
|
|
// extraResources entry is a single path shared by the two packs, so the
|
|
// sidecar there must be a lipo fat binary — a host-arch-only build (the plain
|
|
// `native:build` dev path) would silently ship an arm64 sidecar inside the
|
|
// Intel dmg, where every workbook open fails. Runs from beforePack, dual-arch
|
|
// mac packs only.
|
|
function assertUniversalSidecar() {
|
|
const sidecar = join(__dirname, '../sheets/native/xlsx-engine/target/release/xlsx-sidecar')
|
|
if (!existsSync(sidecar)) {
|
|
throw new Error(
|
|
`mac extraResources source missing: ${sidecar} (run "npm run native:build:universal -w @genoffice/sheets" first)`,
|
|
)
|
|
}
|
|
const archs = execFileSync('lipo', ['-archs', sidecar], { encoding: 'utf8' }).trim().split(/\s+/)
|
|
for (const want of ['x86_64', 'arm64']) {
|
|
if (!archs.includes(want)) {
|
|
throw new Error(
|
|
`xlsx-sidecar is [${archs.join(', ')}] but both mac arch packages ship it — ` +
|
|
'run "npm run native:build:universal -w @genoffice/sheets" before packaging mac',
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
function assertModuleTreesPresent() {
|
|
for (const rel of [
|
|
'../docs/out',
|
|
'../sheets/out',
|
|
'../slides/out',
|
|
'../pdf/out',
|
|
'../markdown/out',
|
|
]) {
|
|
if (!existsSync(join(__dirname, rel))) {
|
|
throw new Error(
|
|
`electron-builder extraResources source missing: ${rel} (run npm run build:all first)`,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
/** @type {import('electron-builder').Configuration} */
|
|
const config = {
|
|
appId: 'com.genoffice.app',
|
|
productName: 'GenOffice',
|
|
// Resolved from the installed electron package so dependency bumps can
|
|
// never leave a stale hard-coded pin behind (packaging would silently ship
|
|
// the old runtime).
|
|
electronVersion: require('electron/package.json').version,
|
|
directories: {
|
|
output: 'release',
|
|
},
|
|
files: ['out/**'],
|
|
extraResources: [
|
|
{
|
|
from: 'build/THIRD-PARTY-NOTICES.txt',
|
|
to: 'THIRD-PARTY-NOTICES.txt',
|
|
},
|
|
{
|
|
from: '../../node_modules/electron/dist/LICENSES.chromium.html',
|
|
to: 'LICENSES.chromium.html',
|
|
},
|
|
{
|
|
from: '../docs/out',
|
|
to: 'modules/docs',
|
|
},
|
|
{
|
|
from: '../sheets/out',
|
|
to: 'modules/sheets',
|
|
},
|
|
{
|
|
from: '../slides/out',
|
|
to: 'modules/slides',
|
|
},
|
|
{
|
|
from: '../pdf/out',
|
|
to: 'modules/pdf',
|
|
},
|
|
{
|
|
from: '../markdown/out',
|
|
to: 'modules/markdown',
|
|
},
|
|
// PDF text editing engines: the bundled main resolves these under
|
|
// Resources/wasm when node_modules is absent (apps/pdf/src/main/wasm-path.ts)
|
|
{
|
|
from: '../../node_modules/@embedpdf/pdfium/dist/pdfium.wasm',
|
|
to: 'wasm/pdfium.wasm',
|
|
},
|
|
{
|
|
from: '../pdf/node_modules/harfbuzzjs/hb-subset.wasm',
|
|
to: 'wasm/hb-subset.wasm',
|
|
},
|
|
// platform system-OCR helpers for scanned-page recovery (each exists only
|
|
// on its own build platform; electron-builder skips absent sources and the
|
|
// engine resolver degrades to the bitmap fallback when missing)
|
|
{
|
|
from: '../../packages/pdf2docx/ocr-helper/vision-ocr',
|
|
to: 'ocr/vision-ocr',
|
|
},
|
|
{
|
|
from: '../../packages/pdf2docx/ocr-helper/win-ocr.exe',
|
|
to: 'ocr/win-ocr.exe',
|
|
},
|
|
{
|
|
from: '../../node_modules/@genspark/cli',
|
|
to: 'gsk/node_modules/@genspark/cli',
|
|
},
|
|
{
|
|
from: '../../node_modules/@genspark/cli/node_modules/commander',
|
|
to: 'gsk/node_modules/commander',
|
|
},
|
|
{
|
|
from: '../../node_modules/ws',
|
|
to: 'gsk/node_modules/ws',
|
|
},
|
|
],
|
|
// `mimeType` is read only by the Linux target, where it becomes the
|
|
// desktop entry's MimeType= list; associations without it are dropped
|
|
// there. macOS and Windows ignore the field and key off `ext`.
|
|
fileAssociations: [
|
|
{
|
|
ext: 'docx',
|
|
name: 'Word Document',
|
|
role: 'Editor',
|
|
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
},
|
|
{
|
|
ext: 'xlsx',
|
|
name: 'Excel Workbook',
|
|
role: 'Editor',
|
|
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
},
|
|
{
|
|
ext: 'xlsm',
|
|
name: 'Excel Macro-Enabled Workbook',
|
|
role: 'Editor',
|
|
mimeType: 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
|
},
|
|
{
|
|
ext: 'pptx',
|
|
name: 'PowerPoint Presentation',
|
|
role: 'Editor',
|
|
mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
},
|
|
{
|
|
ext: 'xls',
|
|
name: 'Excel 97-2003 Workbook',
|
|
role: 'Editor',
|
|
mimeType: 'application/vnd.ms-excel',
|
|
},
|
|
{
|
|
ext: 'csv',
|
|
name: 'CSV Document',
|
|
role: 'Editor',
|
|
mimeType: 'text/csv',
|
|
},
|
|
{
|
|
ext: 'pdf',
|
|
name: 'PDF Document',
|
|
role: 'Editor',
|
|
mimeType: 'application/pdf',
|
|
},
|
|
{
|
|
ext: 'md',
|
|
name: 'Markdown Document',
|
|
role: 'Editor',
|
|
mimeType: 'text/markdown',
|
|
},
|
|
{
|
|
ext: 'markdown',
|
|
name: 'Markdown Document',
|
|
role: 'Editor',
|
|
mimeType: 'text/markdown',
|
|
},
|
|
],
|
|
npmRebuild: false,
|
|
mac: {
|
|
// Two separate arch packages (NOT universal): arm64 keeps the exact
|
|
// artifact names and update-feed entries it always had, x64 (opt-in via
|
|
// GENOFFICE_MAC_X64=1, see includeMacX64 above) adds Intel support with
|
|
// electron-builder's default arch-less names (GenOffice-<v>.dmg /
|
|
// GenOffice-<v>-mac.zip). Both zips land in one latest-mac.yml and
|
|
// electron-updater picks by process.arch. Dual-arch packs ship the same
|
|
// lipo fat xlsx-sidecar (see assertUniversalSidecar above).
|
|
target: [
|
|
{ target: 'dmg', arch: includeMacX64 ? ['arm64', 'x64'] : ['arm64'] },
|
|
{ target: 'zip', arch: includeMacX64 ? ['arm64', 'x64'] : ['arm64'] },
|
|
],
|
|
category: 'public.app-category.productivity',
|
|
hardenedRuntime: true,
|
|
gatekeeperAssess: false,
|
|
entitlements: 'build/entitlements.mac.plist',
|
|
entitlementsInherit: 'build/entitlements.mac.plist',
|
|
notarize: true,
|
|
extraResources: [
|
|
{
|
|
from: '../sheets/native/xlsx-engine/target/release/xlsx-sidecar',
|
|
to: 'native/xlsx-sidecar',
|
|
},
|
|
],
|
|
},
|
|
win: {
|
|
target: [
|
|
{
|
|
target: 'nsis',
|
|
arch: ['x64'],
|
|
},
|
|
],
|
|
extraResources: [
|
|
{
|
|
from: '../sheets/native/xlsx-engine/target/x86_64-pc-windows-gnu/release/xlsx-sidecar.exe',
|
|
to: 'native/xlsx-sidecar.exe',
|
|
},
|
|
],
|
|
},
|
|
// Unlike win (which cross-compiles the sidecar to an explicit target
|
|
// triple), linux takes it from cargo's host-native target/release/ — the
|
|
// same source mac uses. So no `arch` is pinned here: electron-builder
|
|
// defaults to the build host's architecture, which is the only one the
|
|
// sidecar was actually built for. Packaging arm64 on an x64 host, or the
|
|
// reverse, needs a matching `cargo build --target` first.
|
|
linux: {
|
|
// AppImage (self-contained, any distro) + deb (apt install, pulls in the
|
|
// GTK/NSS runtime deps) + rpm (dnf/zypper install on Fedora / RHEL /
|
|
// openSUSE). Default artifact names are kept on purpose —
|
|
// GenOffice-<v>.AppImage / genoffice_<v>_amd64.deb — because the public
|
|
// README download links and the already-published linux-v0.5.149 release
|
|
// use them.
|
|
target: [
|
|
{ target: 'AppImage', arch: ['x64'] },
|
|
{ target: 'deb', arch: ['x64'] },
|
|
{ target: 'rpm', arch: ['x64'] },
|
|
],
|
|
// deb control metadata; values match the manually published 0.5.149 deb
|
|
// so apt sees the new packages as the same lineage. Homepage comes from
|
|
// package.json "homepage"; the Package field is pinned in the deb block
|
|
// below (packageName is a per-target option, rejected here by the schema).
|
|
maintainer: 'Mainfunc, Inc. <team@genspark.ai>',
|
|
vendor: 'Mainfunc, Inc. <team@genspark.ai>',
|
|
category: 'Office',
|
|
// Icon SET directory, not the single 1024px png: electron-builder does
|
|
// not resize a lone png, so deb/rpm would install only
|
|
// hicolor/1024x1024/apps/genoffice.png — a size absent from the hicolor
|
|
// theme index, leaving GNOME/KDE launchers on the generic fallback icon
|
|
// (genspark-ai/genoffice#90). The set ships every standard raster size.
|
|
icon: 'build/icons',
|
|
// mac and win name the binary from productName; linux instead derives it
|
|
// from package.json "name", and "@genoffice/shell" sanitizes to the
|
|
// invalid "@genofficeshell". Setting it explicitly also makes the
|
|
// generated genoffice.desktop match the WM_CLASS Electron reports (it
|
|
// takes that from the executable basename), so the running window links
|
|
// back to its launcher entry.
|
|
executableName: 'genoffice',
|
|
// Electron takes its X11 app_id from package.json "desktopName"
|
|
// (genoffice.desktop); syncDesktopName makes electron-builder name the
|
|
// .desktop file and its StartupWMClass from the same value. Without it
|
|
// StartupWMClass falls back to productName ("GenOffice"), which does not
|
|
// match the "genoffice" WM_CLASS the window actually reports — and X11
|
|
// compares case-sensitively, so the taskbar shows an unlinked window.
|
|
syncDesktopName: true,
|
|
extraResources: [
|
|
{
|
|
from: '../sheets/native/xlsx-engine/target/release/xlsx-sidecar',
|
|
to: 'native/xlsx-sidecar',
|
|
},
|
|
],
|
|
},
|
|
// Same "@genoffice/shell" problem as executableName above: the default deb
|
|
// artifact name derives from package.json "name", and the scope's "/" makes
|
|
// fpm treat "@genoffice" as a directory. Spell the published name out
|
|
// (genoffice_<version>_amd64.deb, matching the linux-v0.5.149 release).
|
|
// packageName pins the control Package field to the same value the 0.5.149
|
|
// deb shipped with — apt treats a different Package name as an unrelated
|
|
// install, breaking upgrades. Without it, fpm receives productName
|
|
// "GenOffice" and only happens to downcase it to the right value.
|
|
deb: {
|
|
artifactName: 'genoffice_${version}_${arch}.deb',
|
|
packageName: 'genoffice',
|
|
},
|
|
// Same "@genoffice/shell" naming problem as deb: spell the artifact name
|
|
// out (${arch} expands to the rpm arch string, x86_64) and pin the rpm
|
|
// Package name so dnf/zypper treat successive releases as upgrades of the
|
|
// same package. Like deb, rpm installs run no in-app updater — users
|
|
// upgrade with `dnf install ./<new>.rpm`. Packaging needs rpmbuild on the
|
|
// build host (the `rpm` apt package on Ubuntu; CI installs it).
|
|
//
|
|
// publish: null (explicit) keeps the rpm out of the electron-updater feed
|
|
// and off the CDN entirely: the rpm is a GitHub-Release download only, so
|
|
// latest-linux.yml keeps listing exactly what the CDN pipeline uploads
|
|
// (AppImage + deb) and the promote workflow needs no rpm alias.
|
|
rpm: {
|
|
artifactName: 'genoffice-${version}.${arch}.rpm',
|
|
packageName: 'genoffice',
|
|
publish: null,
|
|
},
|
|
nsis: {
|
|
oneClick: false,
|
|
allowToChangeInstallationDirectory: true,
|
|
},
|
|
beforePack: async (context) => {
|
|
assertModuleTreesPresent()
|
|
if (context.electronPlatformName === 'darwin' && includeMacX64) {
|
|
assertUniversalSidecar()
|
|
assertUniversalVisionOcr()
|
|
}
|
|
},
|
|
dmg: {
|
|
sign: true,
|
|
},
|
|
afterAllArtifactBuild: 'build/notarize-dmg.js',
|
|
}
|
|
|
|
if (updateUrl) {
|
|
config.publish = [
|
|
{
|
|
provider: 'generic',
|
|
url: updateUrl.replace(/\/+$/, ''),
|
|
channel: 'latest',
|
|
},
|
|
]
|
|
}
|
|
|
|
// CI's "-c.extraMetadata.version=..." CLI override deep-merges with this block,
|
|
// so the version and all injected feature settings survive together.
|
|
const extraMetadata = {}
|
|
if (ga4MeasurementId && ga4ApiSecret) {
|
|
extraMetadata.genofficeAnalytics = {
|
|
measurementId: ga4MeasurementId,
|
|
apiSecret: ga4ApiSecret,
|
|
}
|
|
}
|
|
if (fontCdnUrl) extraMetadata.genofficeFontCdn = { baseUrl: fontCdnUrl }
|
|
if (Object.keys(extraMetadata).length) config.extraMetadata = extraMetadata
|
|
|
|
module.exports = config
|