Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

# Fairpost

Fairpost helps you manage your social
feeds from the command line, using Node.
Fairpost helps you manage your social media feeds from a single
entry point, using Node. It supports Facebook, Instagram,
Reddit, Twitter and LinkedIn.

Your Feed is just a folder on disk, and all subfolders are Posts,
containing at least one text file (the post body) and
Expand All @@ -14,7 +15,7 @@ how a folder with contents can best be presented
as a post on each platform.

Commonly, you would call this script every day or week.
Fairpost will then automatically **prepare** the folders,
Fairpost can then automatically **prepare** the folders,
**schedule** the next post using a certain interval and
**publish** any post when it is due. All you have to do is
add folders with content.
Expand Down Expand Up @@ -45,7 +46,7 @@ cp .env.dist .env && nano .env

## Enable platforms

Read how to enable various media platforms in the [docs](docs).
Read how to enable various social media platforms in the [docs](docs).


## Feed planning
Expand Down Expand Up @@ -127,10 +128,10 @@ fairpost.js publish-due-posts [--folders=xxx,xxx] [--platforms=xxx,xxx] [--dry-r
# Select which config file to use
fairpost.js [command] [arguments] --config=.env-test

# Set the cli output format to pure json
# Set the cli report format to pure json
fairpost.js [command] [arguments] --report=json

# Output trace logging on the command line (overriding .env)
# Enable trace logging output to the console (overriding .env)
fairpost.js [command] [arguments] --verbose

```
Expand Down
96 changes: 54 additions & 42 deletions src/core/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
import * as log4js from "log4js";

const configFile = process.env.FAIRPOST_LOGGER_CONFIG || "log4js.json";
const category = process.env.FAIRPOST_LOGGER_CATEGORY || "default";
const level = process.env.FAIRPOST_LOGGER_LEVEL || "INFO";
const console = process.env.FAIRPOST_LOGGER_CONSOLE !== "false";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require(__dirname + "/../../" + configFile);
if (!config.categories[category]) {
throw new Error(
"Log4js category " + category + " not found in " + configFile,
);
}
if (console && !config.categories[category]["appenders"].includes("console")) {
if (!config.appenders["console"]) {
config.appenders["console"] = { type: "console" };
}
config.categories[category]["appenders"].push("console");
}

log4js.configure(config);
const logger = log4js.getLogger(category);
logger.level = level;

export default logger;

// (trace, debug, info, warn, error, fatal).
/*export default class Logger {
trace(msg) {
logger.trace(msg);
}
debug(msg) {
logger.trace(msg);
class Logger {
static instance: Logger;
logger: log4js.Logger;
constructor() {
if (Logger.instance) {
throw new Error("Logger: call getInstance() instead");
}
info(msg) {
logger.trace(msg);
}
warn(msg) {
logger.trace(msg);
const configFile = process.env.FAIRPOST_LOGGER_CONFIG || "log4js.json";
const category = process.env.FAIRPOST_LOGGER_CATEGORY || "default";
const level = process.env.FAIRPOST_LOGGER_LEVEL || "INFO";
const console = process.env.FAIRPOST_LOGGER_CONSOLE !== "false";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require(__dirname + "/../../" + configFile);
if (!config.categories[category]) {
throw new Error(
"Logger: Log4js category " + category + " not found in " + configFile,
);
}
error(msg) {
logger.trace(msg);
if (
console &&
!config.categories[category]["appenders"].includes("console")
) {
if (!config.appenders["console"]) {
config.appenders["console"] = { type: "console" };
}
config.categories[category]["appenders"].push("console");
}
fatal(msg) {
logger.trace(msg);

log4js.configure(config);
this.logger = log4js.getLogger(category);
this.logger.level = level;
}
static getInstance(): Logger {
if (!Logger.instance) {
Logger.instance = new Logger();
}
return Logger.instance;
}
trace(...args) {
this.logger.trace(args);
}
debug(...args) {
this.logger.trace(args);
}
info(...args) {
this.logger.trace(args);
}
warn(...args) {
this.logger.trace(args);
}
error(...args) {
this.logger.trace(args);
}
fatal(...args) {
this.logger.trace(args);
}
}
*/
export default Logger.getInstance();
30 changes: 22 additions & 8 deletions src/core/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Store - minimalist storage manager
* Store - minimalist storage manager - singleton
*
* - sets and gets key / value pairs.
* - uses two 'stores':
Expand All @@ -8,12 +8,24 @@
* stored and encrypted somewhere else
*
*/
export default class Storage {
public static get(
store: "settings" | "auth",
key: string,
def?: string,
): string {

class Storage {
static instance: Storage;

constructor() {
if (Storage.instance) {
throw new Error("Storage: call getInstance() instead");
}
}

static getInstance(): Storage {
if (!Storage.instance) {
Storage.instance = new Storage();
}
return Storage.instance;
}

public get(store: "settings" | "auth", key: string, def?: string): string {
let value = "" as string;
const storage =
store === "settings"
Expand All @@ -33,7 +45,7 @@ export default class Storage {
return value;
}

public static set(store: "settings" | "auth", key: string, value: string) {
public set(store: "settings" | "auth", key: string, value: string) {
const storage =
store === "settings"
? process.env.FAIRPOST_STORAGE_SETTINGS
Expand All @@ -53,3 +65,5 @@ export default class Storage {
}
}
}

export default Storage.getInstance();