mirror of https://github.com/laurent22/joplin.git
CI: Trying to fix website builder
parent
572701d9a0
commit
659c851960
|
@ -21,6 +21,10 @@ export function credentialDir() {
|
||||||
throw new Error(`Could not find credential directory in any of these paths: ${JSON.stringify(toTry)}`);
|
throw new Error(`Could not find credential directory in any of these paths: ${JSON.stringify(toTry)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const hasCredentialFile = (filename: string) => {
|
||||||
|
return pathExistsSync(filename);
|
||||||
|
};
|
||||||
|
|
||||||
export function credentialFile(filename: string) {
|
export function credentialFile(filename: string) {
|
||||||
const rootDir = credentialDir();
|
const rootDir = credentialDir();
|
||||||
const output = `${rootDir}/${filename}`;
|
const output = `${rootDir}/${filename}`;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as fs from 'fs-extra';
|
import { pathExists, readFile, writeFile, unlink, stat, createWriteStream } from 'fs-extra';
|
||||||
import { readCredentialFile } from '@joplin/lib/utils/credentialFiles';
|
import { hasCredentialFile, readCredentialFile } from '@joplin/lib/utils/credentialFiles';
|
||||||
import { execCommand as execCommand2, commandToString } from '@joplin/utils';
|
import { execCommand as execCommand2, commandToString } from '@joplin/utils';
|
||||||
|
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
@ -23,7 +23,7 @@ export interface GitHubRelease {
|
||||||
async function insertChangelog(tag: string, changelogPath: string, changelog: string, isPrerelease: boolean, repoTagUrl: string = '') {
|
async function insertChangelog(tag: string, changelogPath: string, changelog: string, isPrerelease: boolean, repoTagUrl: string = '') {
|
||||||
repoTagUrl = repoTagUrl || 'https://github.com/laurent22/joplin/releases/tag';
|
repoTagUrl = repoTagUrl || 'https://github.com/laurent22/joplin/releases/tag';
|
||||||
|
|
||||||
const currentText = await fs.readFile(changelogPath, 'UTF-8');
|
const currentText = await readFile(changelogPath, 'UTF-8');
|
||||||
const lines = currentText.split('\n');
|
const lines = currentText.split('\n');
|
||||||
|
|
||||||
const beforeLines = [];
|
const beforeLines = [];
|
||||||
|
@ -80,7 +80,7 @@ export async function completeReleaseWithChangelog(changelogPath: string, newVer
|
||||||
|
|
||||||
const newChangelog = await insertChangelog(newTag, changelogPath, changelog, isPreRelease, repoTagUrl);
|
const newChangelog = await insertChangelog(newTag, changelogPath, changelog, isPreRelease, repoTagUrl);
|
||||||
|
|
||||||
await fs.writeFile(changelogPath, newChangelog);
|
await writeFile(changelogPath, newChangelog);
|
||||||
|
|
||||||
console.info('');
|
console.info('');
|
||||||
console.info('Verify that the changelog is correct:');
|
console.info('Verify that the changelog is correct:');
|
||||||
|
@ -95,8 +95,8 @@ export async function completeReleaseWithChangelog(changelogPath: string, newVer
|
||||||
async function loadGitHubUsernameCache() {
|
async function loadGitHubUsernameCache() {
|
||||||
const path = `${__dirname}/github_username_cache.json`;
|
const path = `${__dirname}/github_username_cache.json`;
|
||||||
|
|
||||||
if (await fs.pathExists(path)) {
|
if (await pathExists(path)) {
|
||||||
const jsonString = await fs.readFile(path, 'utf8');
|
const jsonString = await readFile(path, 'utf8');
|
||||||
return JSON.parse(jsonString);
|
return JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ async function loadGitHubUsernameCache() {
|
||||||
|
|
||||||
async function saveGitHubUsernameCache(cache: any) {
|
async function saveGitHubUsernameCache(cache: any) {
|
||||||
const path = `${__dirname}/github_username_cache.json`;
|
const path = `${__dirname}/github_username_cache.json`;
|
||||||
await fs.writeFile(path, JSON.stringify(cache));
|
await writeFile(path, JSON.stringify(cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the project root dir
|
// Returns the project root dir
|
||||||
|
@ -173,22 +173,21 @@ export function toSystemSlashes(path: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setPackagePrivateField(filePath: string, value: any) {
|
export async function setPackagePrivateField(filePath: string, value: any) {
|
||||||
const text = await fs.readFile(filePath, 'utf8');
|
const text = await readFile(filePath, 'utf8');
|
||||||
const obj = JSON.parse(text);
|
const obj = JSON.parse(text);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
delete obj.private;
|
delete obj.private;
|
||||||
} else {
|
} else {
|
||||||
obj.private = true;
|
obj.private = true;
|
||||||
}
|
}
|
||||||
await fs.writeFile(filePath, JSON.stringify(obj, null, 2), 'utf8');
|
await writeFile(filePath, JSON.stringify(obj, null, 2), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadFile(url: string, targetPath: string) {
|
export async function downloadFile(url: string, targetPath: string) {
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const file = fs.createWriteStream(targetPath);
|
const file = createWriteStream(targetPath);
|
||||||
https.get(url, (response: any) => {
|
https.get(url, (response: any) => {
|
||||||
if (response.statusCode !== 200) reject(new Error(`HTTP error ${response.statusCode}`));
|
if (response.statusCode !== 200) reject(new Error(`HTTP error ${response.statusCode}`));
|
||||||
response.pipe(file);
|
response.pipe(file);
|
||||||
|
@ -222,10 +221,8 @@ export function fileSha256(filePath: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unlinkForce(filePath: string) {
|
export async function unlinkForce(filePath: string) {
|
||||||
const fs = require('fs-extra');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.unlink(filePath);
|
await unlink(filePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT') return;
|
if (error.code === 'ENOENT') return;
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -233,10 +230,8 @@ export async function unlinkForce(filePath: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fileExists(filePath: string) {
|
export function fileExists(filePath: string) {
|
||||||
const fs = require('fs-extra');
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.stat(filePath, (error: any) => {
|
stat(filePath, (error: any) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else if (error.code === 'ENOENT') {
|
} else if (error.code === 'ENOENT') {
|
||||||
|
@ -326,7 +321,10 @@ export function patreonOauthToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function githubOauthToken() {
|
export function githubOauthToken() {
|
||||||
return readCredentialFile('github_oauth_token.txt');
|
const filename = 'github_oauth_token.txt';
|
||||||
|
if (hasCredentialFile(filename)) return readCredentialFile(filename);
|
||||||
|
if (process.env.JOPLIN_GITHUB_OAUTH_TOKEN) return process.env.JOPLIN_GITHUB_OAUTH_TOKEN;
|
||||||
|
throw new Error(`Cannot get Oauth token. Neither ${filename} nor the env variable JOPLIN_GITHUB_OAUTH_TOKEN are present`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that the GitHub API releases/latest is broken on the joplin-android repo
|
// Note that the GitHub API releases/latest is broken on the joplin-android repo
|
||||||
|
@ -422,12 +420,11 @@ export function isMac() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function insertContentIntoFile(filePath: string, markerOpen: string, markerClose: string, contentToInsert: string) {
|
export async function insertContentIntoFile(filePath: string, markerOpen: string, markerClose: string, contentToInsert: string) {
|
||||||
const fs = require('fs-extra');
|
let content = await readFile(filePath, 'utf-8');
|
||||||
let content = await fs.readFile(filePath, 'utf-8');
|
|
||||||
// [^]* matches any character including new lines
|
// [^]* matches any character including new lines
|
||||||
const regex = new RegExp(`${markerOpen}[^]*?${markerClose}`);
|
const regex = new RegExp(`${markerOpen}[^]*?${markerClose}`);
|
||||||
content = content.replace(regex, markerOpen + contentToInsert + markerClose);
|
content = content.replace(regex, markerOpen + contentToInsert + markerClose);
|
||||||
await fs.writeFile(filePath, content);
|
await writeFile(filePath, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dirname(path: string) {
|
export function dirname(path: string) {
|
||||||
|
|
Loading…
Reference in New Issue