Skip to content

Commit

Permalink
Updated helpers to esm & fixed esm runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Sep 18, 2022
1 parent a922898 commit 029a651
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@ctrl/plex": "^1.5.3",
"@inrixia/db": "2.0.0",
"@inrixia/helpers": "^1.23.4",
"@inrixia/helpers": "^2.0.1",
"chalk-template": "^0.4.0",
"default-import": "^1.1.5",
"dotenv": "^16.0.2",
Expand Down
8 changes: 5 additions & 3 deletions src/float.ts
Expand Up @@ -4,12 +4,14 @@ import { settings, fetchFFMPEG, fApi } from './lib/helpers.js';
import { MyPlexAccount } from '@ctrl/plex';
import { loginFloatplane } from './logins.js';
import Downloader from './Downloader.js';
import { gt, diff } from 'semver';

import chalk from 'chalk-template';
import fs from 'fs';

import type Subscription from './lib/Subscription.js';

import semver from "semver";
const { gt, diff } = semver;

/**
* Main function that triggeres everything else in the script
*/
Expand All @@ -35,7 +37,7 @@ const fetchNewVideos = async (subscriptions: Array<Subscription>, videoProcessor
};

(async () => {
const version: string = require('../package.json').version;
const version: string = process.env.npm_package_version ?? JSON.parse(fs.readFileSync('./package.json').toString()).version;
const latest = await fApi
.got('https://raw.githubusercontent.com/Inrixia/Floatplane-Downloader/master/package.json', { resolveBodyOnly: true })
.then(JSON.parse)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Video.ts
Expand Up @@ -11,7 +11,7 @@ import { htmlToText } from 'html-to-text';
import sanitize from 'sanitize-filename';
import builder from 'xmlbuilder';

import { nPad } from '@inrixia/helpers/math';
import { nPad } from '@inrixia/helpers/math.js';

import type { FilePathFormattingOptions } from './types.js';
import type { BlogPost } from 'floatplane/creator';
Expand Down
17 changes: 11 additions & 6 deletions src/lib/helpers.ts
@@ -1,5 +1,5 @@
import { downloadBinaries, detectPlatform, getBinaryFilename } from 'ffbinaries';
import { getEnv, rebuildTypes, recursiveUpdate } from '@inrixia/helpers/object';
import { getEnv, rebuildTypes, recursiveUpdate } from '@inrixia/helpers/object.js';
import { defaultArgs, defaultSettings } from './defaults.js';
import db from '@inrixia/db';
import fs from 'fs';
Expand All @@ -10,9 +10,11 @@ import _ARGV from 'process.argv';
const ARGV = defaultImport(_ARGV);

import 'dotenv/config';
import { parse } from 'json5';

import type { Args, PartialArgs, Settings } from './types.js';
import json5 from 'json5';
const { parse } = json5;

import type { PartialArgs, Settings } from './types.js';

import { FileCookieStore } from 'tough-cookie-file-store';
import { CookieJar } from 'tough-cookie';
Expand All @@ -25,13 +27,16 @@ export const settings = db<Settings>('./db/settings.json', { template: defaultSe
recursiveUpdate(settings, defaultSettings);

const argv = ARGV(process.argv.slice(2))<PartialArgs>({});
rebuildTypes<PartialArgs, Settings & Args>(argv, { ...defaultSettings, ...defaultArgs });
rebuildTypes(argv, { ...defaultSettings, ...defaultArgs });
recursiveUpdate(settings, argv, { setUndefined: false, setDefined: true });

const env = getEnv();
rebuildTypes<PartialArgs, Settings & Args>(env, { ...defaultSettings, ...defaultArgs });
rebuildTypes(env, { ...defaultSettings, ...defaultArgs });

if (env.__FPDSettings !== undefined) recursiveUpdate(settings, parse(env.__FPDSettings.replaceAll('\\"', '"')), { setUndefined: false, setDefined: true });
if (env.__FPDSettings !== undefined) {
if (typeof env.__FPDSettings !== 'string') throw new Error('The __FPDSettings environment variable cannot be parsed!');
recursiveUpdate(settings, parse(env.__FPDSettings.replaceAll('\\"', '"')), { setUndefined: false, setDefined: true });
}

recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });

Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
@@ -1,6 +1,6 @@
export type Resolutions = ['360', '720', '1080', '2160'];

import type { ValueOfA } from '@inrixia/helpers/ts';
import type { ValueOfA } from '@inrixia/helpers/ts.js';
import type { BlogPost } from 'floatplane/creator';

type ChannelIdentifier = {
Expand Down
5 changes: 2 additions & 3 deletions src/logins.ts
@@ -1,8 +1,7 @@
import { loopError } from '@inrixia/helpers/object';
import { loopError } from '@inrixia/helpers/object.js';
import { floatplane, plex } from './lib/prompts/index.js';
import { fApi } from './lib/helpers.js';
import { fApi, args } from './lib/helpers.js';
import { MyPlexAccount } from '@ctrl/plex';
import { args } from './lib/helpers.js';

export const loginFloatplane = async (): Promise<void> => {
let loginResponse;
Expand Down

0 comments on commit 029a651

Please sign in to comment.