mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Tools: Allow setting website build environment from config file
This commit is contained in:
parent
bdd9c6cf35
commit
a0d77d10ba
@ -1,6 +1,10 @@
|
||||
const fs = require('fs-extra');
|
||||
import { pathExistsSync, readFileSync } from 'fs-extra';
|
||||
|
||||
export async function credentialDir() {
|
||||
// All these calls used to be async but certain scripts need to load config
|
||||
// files early, so they've been converted to sync calls. Do not convert them
|
||||
// back to async.
|
||||
|
||||
export function credentialDir() {
|
||||
const username = require('os').userInfo().username;
|
||||
|
||||
const toTry = [
|
||||
@ -11,23 +15,23 @@ export async function credentialDir() {
|
||||
];
|
||||
|
||||
for (const dirPath of toTry) {
|
||||
if (await fs.pathExists(dirPath)) return dirPath;
|
||||
if (pathExistsSync(dirPath)) return dirPath;
|
||||
}
|
||||
|
||||
throw new Error(`Could not find credential directory in any of these paths: ${JSON.stringify(toTry)}`);
|
||||
}
|
||||
|
||||
export async function credentialFile(filename: string) {
|
||||
const rootDir = await credentialDir();
|
||||
export function credentialFile(filename: string) {
|
||||
const rootDir = credentialDir();
|
||||
const output = `${rootDir}/${filename}`;
|
||||
if (!(await fs.pathExists(output))) throw new Error(`No such file: ${output}`);
|
||||
if (!(pathExistsSync(output))) throw new Error(`No such file: ${output}`);
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function readCredentialFile(filename: string, defaultValue: string = '') {
|
||||
export function readCredentialFile(filename: string, defaultValue: string = '') {
|
||||
try {
|
||||
const filePath = await credentialFile(filename);
|
||||
const r = await fs.readFile(filePath);
|
||||
const filePath = credentialFile(filename);
|
||||
const r = readFileSync(filePath);
|
||||
// There's normally no reason to keep the last new line character and it
|
||||
// can cause problems in certain scripts, so trim it. Any other white
|
||||
// space should also not be relevant.
|
||||
@ -36,3 +40,16 @@ export async function readCredentialFile(filename: string, defaultValue: string
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function readCredentialFileJson<T>(filename: string, defaultValue: T = null): T {
|
||||
const v = readCredentialFile(filename);
|
||||
if (!v) return defaultValue;
|
||||
|
||||
try {
|
||||
const o = JSON.parse(v);
|
||||
return o;
|
||||
} catch (error) {
|
||||
error.message = `Could not parse JSON file ${filename}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,21 @@ import { MarkdownAndFrontMatter, stripOffFrontMatter } from './utils/frontMatter
|
||||
import { dirname, basename } from 'path';
|
||||
import { readmeFileTitle, replaceGitHubByWebsiteLinks } from './utils/parser';
|
||||
import { extractOpenGraphTags } from './utils/openGraph';
|
||||
import { readCredentialFileJson } from '@joplin/lib/utils/credentialFiles';
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
interface BuildConfig {
|
||||
env: Env;
|
||||
}
|
||||
|
||||
const buildConfig = readCredentialFileJson<BuildConfig>('website-build.json', {
|
||||
env: Env.Prod,
|
||||
});
|
||||
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const md5File = require('md5-file/promise');
|
||||
|
||||
const env = Env.Prod;
|
||||
|
||||
const docDir = `${dirname(dirname(dirname(dirname(__dirname))))}/joplin-website/docs`;
|
||||
|
||||
if (!pathExistsSync(docDir)) throw new Error(`Doc directory does not exist: ${docDir}`);
|
||||
@ -25,7 +32,7 @@ const readmeDir = `${rootDir}/readme`;
|
||||
const mainTemplateHtml = readFileSync(`${websiteAssetDir}/templates/main-new.mustache`, 'utf8');
|
||||
const frontTemplateHtml = readFileSync(`${websiteAssetDir}/templates/front.mustache`, 'utf8');
|
||||
const plansTemplateHtml = readFileSync(`${websiteAssetDir}/templates/plans.mustache`, 'utf8');
|
||||
const stripeConfig = loadStripeConfig(env, `${rootDir}/packages/server/stripeConfig.json`);
|
||||
const stripeConfig = loadStripeConfig(buildConfig.env, `${rootDir}/packages/server/stripeConfig.json`);
|
||||
const partialDir = `${websiteAssetDir}/templates/partials`;
|
||||
|
||||
const discussLink = 'https://discourse.joplinapp.org/c/news/9';
|
||||
@ -82,7 +89,7 @@ async function getAssetUrls(): Promise<AssetUrls> {
|
||||
|
||||
function defaultTemplateParams(assetUrls: AssetUrls): TemplateParams {
|
||||
return {
|
||||
env,
|
||||
env: buildConfig.env,
|
||||
baseUrl,
|
||||
imageBaseUrl: `${baseUrl}/images`,
|
||||
cssBaseUrl,
|
||||
|
Loading…
Reference in New Issue
Block a user