mirror of https://github.com/sualko/cloud_bbb
chore: move back to js scripts
parent
3d9b579d55
commit
dee6866fd1
|
@ -9,19 +9,10 @@ const execa = require('execa');
|
||||||
const simpleGit = require('simple-git/promise');
|
const simpleGit = require('simple-git/promise');
|
||||||
const inquirer = require('inquirer');
|
const inquirer = require('inquirer');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
import { generateChangelog, hasChangeLogEntry } from './imports/changelog';
|
const { generateChangelog, hasChangeLogEntry } = require('./imports/changelog');
|
||||||
|
|
||||||
const packageInfo = require('../package.json');
|
const packageInfo = require('../package.json');
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface String {
|
|
||||||
error: string
|
|
||||||
verbose: string
|
|
||||||
warn: string
|
|
||||||
green: string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
colors.setTheme({
|
colors.setTheme({
|
||||||
verbose: 'cyan',
|
verbose: 'cyan',
|
||||||
warn: 'yellow',
|
warn: 'yellow',
|
||||||
|
@ -144,7 +135,7 @@ async function keypress() {
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function commitChangeLog(): Promise<void> {
|
async function commitChangeLog() {
|
||||||
const status = await git.status();
|
const status = await git.status();
|
||||||
|
|
||||||
if (status.staged.length > 0) {
|
if (status.staged.length > 0) {
|
||||||
|
@ -216,7 +207,7 @@ function createArchive(appId, fileBaseName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNextcloudSignature(appId, filePath) {
|
function createNextcloudSignature(appId, filePath) {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const sigPath = filePath + '.ncsig';
|
const sigPath = filePath + '.ncsig';
|
||||||
exec(`openssl dgst -sha512 -sign ~/.nextcloud/certificates/${appId}.key ${filePath} | openssl base64 > ${sigPath}`, (error, stdout, stderr) => {
|
exec(`openssl dgst -sha512 -sign ~/.nextcloud/certificates/${appId}.key ${filePath} | openssl base64 > ${sigPath}`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -239,7 +230,7 @@ function createNextcloudSignature(appId, filePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createGPGSignature(filePath) {
|
function createGPGSignature(filePath) {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise((resolve) => {
|
||||||
exec(`gpg --yes --detach-sign "${filePath}"`, (error, stdout, stderr) => {
|
exec(`gpg --yes --detach-sign "${filePath}"`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -261,7 +252,7 @@ function createGPGSignature(filePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createGPGArmorSignature(filePath) {
|
function createGPGArmorSignature(filePath) {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise((resolve) => {
|
||||||
exec(`gpg --yes --detach-sign --armor "${filePath}"`, (error, stdout, stderr) => {
|
exec(`gpg --yes --detach-sign --armor "${filePath}"`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -289,7 +280,7 @@ async function validateXml(xmlDoc) {
|
||||||
throw 'Found no schema location';
|
throw 'Found no schema location';
|
||||||
}
|
}
|
||||||
|
|
||||||
let schemaString: string;
|
let schemaString;
|
||||||
try {
|
try {
|
||||||
console.log('Downloading schema file...'.verbose);
|
console.log('Downloading schema file...'.verbose);
|
||||||
|
|
||||||
|
@ -315,8 +306,8 @@ async function validateXml(xmlDoc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wget(url: string) {
|
function wget(url) {
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
https.get(url, (resp) => {
|
https.get(url, (resp) => {
|
||||||
let data = '';
|
let data = '';
|
||||||
|
|
|
@ -6,7 +6,7 @@ const inquirer = require('inquirer');
|
||||||
|
|
||||||
const git = simpleGit();
|
const git = simpleGit();
|
||||||
|
|
||||||
export async function generateChangelog(version: string): Promise<string> {
|
async function generateChangelog(version) {
|
||||||
const latestTag = (await git.tags()).latest;
|
const latestTag = (await git.tags()).latest;
|
||||||
const title = `v${version}` === latestTag ? '[Unreleased]' : `${version} (${new Date().toISOString().split('T')[0]})`;
|
const title = `v${version}` === latestTag ? '[Unreleased]' : `${version} (${new Date().toISOString().split('T')[0]})`;
|
||||||
|
|
||||||
|
@ -33,13 +33,13 @@ export async function generateChangelog(version: string): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [, type, scope, description] = match;
|
const [, type, scope, description] = match;
|
||||||
const entry = { type, scope, description, issues: <string[]> [] };
|
const entry = { type, scope, description, issues: [] };
|
||||||
|
|
||||||
if(log.body) {
|
if(log.body) {
|
||||||
const matches = log.body.match(/(?:fix|fixes|closes?|refs?) #(\d+)/g) || [];
|
const matches = log.body.match(/(?:fix|fixes|closes?|refs?) #(\d+)/g) || [];
|
||||||
|
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const [, number] = <RegExpMatchArray> match.match(/(\d+)$/);
|
const [, number] = match.match(/(\d+)$/);
|
||||||
|
|
||||||
entry.issues.push(number);
|
entry.issues.push(number);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ export async function generateChangelog(version: string): Promise<string> {
|
||||||
return changeLog;
|
return changeLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function editChangeLog(changeLog: string):Promise<string> {
|
async function editChangeLog(changeLog) {
|
||||||
const answers = await inquirer.prompt([{
|
const answers = await inquirer.prompt([{
|
||||||
type: 'editor',
|
type: 'editor',
|
||||||
name: 'changeLog',
|
name: 'changeLog',
|
||||||
|
@ -104,7 +104,7 @@ export async function editChangeLog(changeLog: string):Promise<string> {
|
||||||
return answers.changeLog;
|
return answers.changeLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function hasChangeLogEntry(version: string): Promise<boolean> {
|
async function hasChangeLogEntry(version) {
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -118,14 +118,14 @@ export async function hasChangeLogEntry(version: string): Promise<boolean> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getChangelogEntry(version: string): Promise<string> {
|
function getChangelogEntry(version) {
|
||||||
return new Promise<string>(resolve => {
|
return new Promise(resolve => {
|
||||||
fs.readFile(path.join(__dirname, '..', '..', 'CHANGELOG.md'), 'utf8', function (err, data) {
|
fs.readFile(path.join(__dirname, '..', '..', 'CHANGELOG.md'), 'utf8', function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
const releaseHeader = /^\d+\.\d+\.\d+$/.test(version) ? `## ${version}` : '## [Unreleased]';
|
const releaseHeader = /^\d+\.\d+\.\d+$/.test(version) ? `## ${version}` : '## [Unreleased]';
|
||||||
const lines = data.split('\n');
|
const lines = data.split('\n');
|
||||||
const entry: string[] = [];
|
const entry = [];
|
||||||
|
|
||||||
let inEntry = false;
|
let inEntry = false;
|
||||||
|
|
||||||
|
@ -147,3 +147,5 @@ export function getChangelogEntry(version: string): Promise<string> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.default = {generateChangelog, editChangeLog, hasChangeLogEntry, getChangelogEntry};
|
|
@ -8,20 +8,11 @@ const simpleGit = require('simple-git/promise');
|
||||||
const inquirer = require('inquirer');
|
const inquirer = require('inquirer');
|
||||||
const dotenv = require('dotenv');
|
const dotenv = require('dotenv');
|
||||||
const { Octokit } = require('@octokit/rest');
|
const { Octokit } = require('@octokit/rest');
|
||||||
import { getChangelogEntry, hasChangeLogEntry } from './imports/changelog';
|
const { getChangelogEntry, hasChangeLogEntry } = require('./imports/changelog');
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const packageInfo = require('../package.json');
|
const packageInfo = require('../package.json');
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface String {
|
|
||||||
error: string
|
|
||||||
verbose: string
|
|
||||||
warn: string
|
|
||||||
green: string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
colors.setTheme({
|
colors.setTheme({
|
||||||
verbose: 'cyan',
|
verbose: 'cyan',
|
||||||
warn: 'yellow',
|
warn: 'yellow',
|
||||||
|
@ -54,7 +45,9 @@ async function notAlreadyTagged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function lastCommitNotBuild() {
|
async function lastCommitNotBuild() {
|
||||||
return (await git.log(['-1'])).latest?.message !== commitMessage;
|
const latest = (await git.log(['-1'])).latest || {};
|
||||||
|
|
||||||
|
return latest.message !== commitMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isMasterBranch() {
|
async function isMasterBranch() {
|
||||||
|
@ -72,7 +65,7 @@ async function stageAllFiles() {
|
||||||
|
|
||||||
const gitProcess = execa('git', ['add', '-u']);
|
const gitProcess = execa('git', ['add', '-u']);
|
||||||
|
|
||||||
gitProcess.stdout?.pipe(process.stdout);
|
gitProcess.stdout.pipe(process.stdout);
|
||||||
|
|
||||||
return gitProcess;
|
return gitProcess;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +73,7 @@ async function stageAllFiles() {
|
||||||
function showStagedDiff() {
|
function showStagedDiff() {
|
||||||
const gitProcess = execa('git', ['diff', '--staged']);
|
const gitProcess = execa('git', ['diff', '--staged']);
|
||||||
|
|
||||||
gitProcess.stdout?.pipe(process.stdout);
|
gitProcess.stdout.pipe(process.stdout);
|
||||||
|
|
||||||
return gitProcess;
|
return gitProcess;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +174,7 @@ async function createGithubRelease(changeLog) {
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
release_id: releaseResponse.data.id,
|
release_id: releaseResponse.data.id,
|
||||||
data: <any> fs.createReadStream(file),
|
data: fs.createReadStream(file),
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': getMimeType(filename),
|
'content-type': getMimeType(filename),
|
||||||
'content-length': fs.statSync(file)['size'],
|
'content-length': fs.statSync(file)['size'],
|
||||||
|
@ -206,7 +199,7 @@ async function uploadToNextcloudStore(archiveUrl) {
|
||||||
|
|
||||||
const hostname = 'apps.nextcloud.com';
|
const hostname = 'apps.nextcloud.com';
|
||||||
const apiEndpoint = '/api/v1/apps/releases';
|
const apiEndpoint = '/api/v1/apps/releases';
|
||||||
const signatureFile = <string> files.find(file => file.endsWith('.ncsig'));
|
const signatureFile = files.find(file => file.endsWith('.ncsig'));
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
download: archiveUrl,
|
download: archiveUrl,
|
||||||
signature: fs.readFileSync(signatureFile, 'utf-8'),
|
signature: fs.readFileSync(signatureFile, 'utf-8'),
|
||||||
|
@ -229,7 +222,7 @@ async function uploadToNextcloudStore(archiveUrl) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = https.request(options, res => {
|
const req = https.request(options, res => {
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
console.log('App release was updated successfully'.verbose);
|
console.log('App release was updated successfully'.verbose);
|
Loading…
Reference in New Issue