-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac172f6
commit 280a158
Showing
12 changed files
with
767 additions
and
411 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,6 @@ node_modules/ | |
|
||
# JS | ||
node_modules | ||
dist | ||
dist | ||
|
||
.orbiter |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,106 @@ | ||
import { | ||
ConfigMode, | ||
VariableIds, | ||
possiblyIncompleteOrbiterConfigSchema, | ||
type OrbiterConfig, | ||
type PossiblyIncompleteOrbiterConfig, | ||
} from "./types"; | ||
|
||
import {constantCase} from 'change-case'; | ||
import { | ||
isBrowser, | ||
isElectronRenderer, | ||
isReactNative, | ||
isWebWorker, | ||
} from "wherearewe"; | ||
import Ajv from "ajv/dist/jtd"; | ||
|
||
import { CONFIG_FILE_NAME } from "./consts.js"; | ||
|
||
const ajv = new Ajv(); | ||
const validateConfig = ajv.compile(possiblyIncompleteOrbiterConfigSchema); | ||
|
||
export const getConfig = async ({ | ||
dir, | ||
}: { | ||
dir: string; | ||
}): Promise<PossiblyIncompleteOrbiterConfig> => { | ||
if (isBrowser || isElectronRenderer || isReactNative || isWebWorker) { | ||
throw new Error( | ||
"The `getConfig` function is only available in Node and Electron main environments.", | ||
); | ||
} | ||
const { existsSync, readFileSync } = await import("fs"); | ||
const { join } = await import("path"); | ||
const configFilePath = join(dir, CONFIG_FILE_NAME); | ||
if (existsSync(configFilePath)) { | ||
const data = readFileSync(configFilePath); | ||
try { | ||
const jsonConfig = JSON.parse(new TextDecoder().decode(data)) as unknown; | ||
if (validateConfig(jsonConfig)) { | ||
return jsonConfig; | ||
} else { | ||
return {}; | ||
} | ||
} catch { | ||
return {}; | ||
} | ||
} | ||
return {}; | ||
}; | ||
|
||
export const saveConfig = async ({ | ||
dir, | ||
config, | ||
mode = "vite", | ||
}: { | ||
dir: string; | ||
config: OrbiterConfig; | ||
mode: ConfigMode; | ||
}) => { | ||
const configFileText = exportConfig({ config, mode }); | ||
if (isBrowser || isElectronRenderer || isReactNative || isWebWorker) { | ||
throw new Error( | ||
"The `saveConfig` function is only available in Node and Electron main environments.", | ||
); | ||
} | ||
const { writeFileSync } = await import("fs"); | ||
const { join } = await import("path"); | ||
const configFilePath = join(dir, CONFIG_FILE_NAME); | ||
writeFileSync(configFilePath, configFileText); | ||
}; | ||
|
||
export const exportConfig = ({ | ||
config, | ||
mode = "vite", | ||
}: { | ||
config: OrbiterConfig; | ||
mode: ConfigMode; | ||
}): string => { | ||
if (mode === "vite") return exportViteConfig({ config }); | ||
else throw new Error(`Unknown exportation mode ${mode}.`); | ||
}; | ||
|
||
export const exportViteConfig = ({ | ||
config, | ||
}: { | ||
config: OrbiterConfig; | ||
}): string => { | ||
const { siteId, swarmId, variableIds } = config; | ||
let envFileText = '# The address below should be regenerated for each Orbiter site. If you are setting up an independent site, erase the value below and run the site in development mode (`pnpm dev`) to automatically regenerate. \n' + | ||
'VITE_SITE_ID=' + siteId + | ||
'\n'; | ||
const variableIdsList = Object.keys(variableIds).map( | ||
k => `VITE_${constantCase(k)}_ID=${variableIds[k as keyof VariableIds]}`, | ||
); | ||
|
||
envFileText += | ||
'# These should ideally stay the same for all Orbiter site. Changing these will create a parallel network and thereby keep your lens from syncing and interacting with the main network.\n' + | ||
'VITE_SWARM_ID=' + swarmId + | ||
'\n' + | ||
'\n' + | ||
variableIdsList.join('\n') + | ||
'\n' | ||
; | ||
return envFileText; | ||
}; |
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,31 +1,33 @@ | ||
export const TRUSTED_SITES_TABLE_KEY = 'trustedSites'; | ||
export const TRUSTED_SITES_SITE_ID_COL = 'siteId'; | ||
export const TRUSTED_SITES_NAME_COL = 'siteName'; | ||
export const TRUSTED_SITES_TABLE_KEY = "trustedSites"; | ||
export const TRUSTED_SITES_SITE_ID_COL = "siteId"; | ||
export const TRUSTED_SITES_NAME_COL = "siteName"; | ||
|
||
export const FEATURED_RELEASES_TABLE_KEY = 'featuredReleases'; | ||
export const FEATURED_RELEASES_RELEASE_ID_COLUMN = 'releaseId'; | ||
export const FEATURED_RELEASES_START_TIME_COLUMN = 'startTime'; | ||
export const FEATURED_RELEASES_END_TIME_COLUMN = 'endTime'; | ||
export const FEATURED_RELEASES_TABLE_KEY = "featuredReleases"; | ||
export const FEATURED_RELEASES_RELEASE_ID_COLUMN = "releaseId"; | ||
export const FEATURED_RELEASES_START_TIME_COLUMN = "startTime"; | ||
export const FEATURED_RELEASES_END_TIME_COLUMN = "endTime"; | ||
|
||
export const BLOCKED_RELEASES_TABLE_KEY = 'blockedReleases'; | ||
export const BLOCKED_RELEASES_RELEASE_ID_COLUMN = 'releaseId'; | ||
export const BLOCKED_RELEASES_TABLE_KEY = "blockedReleases"; | ||
export const BLOCKED_RELEASES_RELEASE_ID_COLUMN = "releaseId"; | ||
|
||
export const RELEASES_FILE_COLUMN = 'file'; | ||
export const RELEASES_AUTHOR_COLUMN = 'author'; | ||
export const RELEASES_NAME_COLUMN = 'contentName'; | ||
export const RELEASES_METADATA_COLUMN = 'metadata'; | ||
export const RELEASES_THUMBNAIL_COLUMN = 'thumbnail'; | ||
export const RELEASES_CATEGORY_COLUMN = 'category'; | ||
export const RELEASES_STATUS_COLUMN = 'status'; | ||
export const RELEASES_COVER_COLUMN = 'cover'; | ||
export const RELEASES_FILE_COLUMN = "file"; | ||
export const RELEASES_AUTHOR_COLUMN = "author"; | ||
export const RELEASES_NAME_COLUMN = "contentName"; | ||
export const RELEASES_METADATA_COLUMN = "metadata"; | ||
export const RELEASES_THUMBNAIL_COLUMN = "thumbnail"; | ||
export const RELEASES_CATEGORY_COLUMN = "category"; | ||
export const RELEASES_STATUS_COLUMN = "status"; | ||
export const RELEASES_COVER_COLUMN = "cover"; | ||
|
||
export const COLLECTIONS_RELEASES_COLUMN = 'releases'; | ||
export const COLLECTIONS_AUTHOR_COLUMN = 'author'; | ||
export const COLLECTIONS_NAME_COLUMN = 'contentName'; | ||
export const COLLECTIONS_METADATA_COLUMN = 'metadata'; | ||
export const COLLECTIONS_THUMBNAIL_COLUMN = 'thumbnail'; | ||
export const COLLECTIONS_CATEGORY_COLUMN = 'category'; | ||
export const COLLECTIONS_STATUS_COLUMN = 'status'; | ||
export const COLLECTIONS_RELEASES_COLUMN = "releases"; | ||
export const COLLECTIONS_AUTHOR_COLUMN = "author"; | ||
export const COLLECTIONS_NAME_COLUMN = "contentName"; | ||
export const COLLECTIONS_METADATA_COLUMN = "metadata"; | ||
export const COLLECTIONS_THUMBNAIL_COLUMN = "thumbnail"; | ||
export const COLLECTIONS_CATEGORY_COLUMN = "category"; | ||
export const COLLECTIONS_STATUS_COLUMN = "status"; | ||
|
||
export const RELEASES_DB_TABLE_KEY = 'releases'; | ||
export const COLLECTIONS_DB_TABLE_KEY = 'collections'; | ||
export const RELEASES_DB_TABLE_KEY = "releases"; | ||
export const COLLECTIONS_DB_TABLE_KEY = "collections"; | ||
|
||
export const CONFIG_FILE_NAME = ".orbiter-config.json"; |
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,4 +1,4 @@ | ||
export { Orbiter } from "./orbiter.js"; | ||
export { version } from "./version.js"; | ||
export { version } from "./version.js"; | ||
export * as types from "./types.js"; | ||
export * as consts from "./consts.js"; | ||
export * as consts from "./consts.js"; |
Oops, something went wrong.