standard/ci.js

105 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-05-17 19:00:53 +02:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of standard which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
2020-07-19 10:53:26 +02:00
/* eslint-disable */
2020-05-15 12:51:09 +02:00
'use strict';
2020-07-19 11:06:59 +02:00
const authors = [
JSON.stringify ({ name: 'Timo Hocker', email: 'timo@scode.ovh' })
];
2020-05-15 12:51:09 +02:00
const fs = require ('fs');
const child_process = require ('child_process');
const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8'));
child_process.execSync ('yarn lint', { stdio: 'inherit' });
child_process.execSync ('yarn test', { stdio: 'inherit' });
child_process.execSync ('yarn compile', { stdio: 'inherit' });
2020-05-23 17:36:36 +02:00
let ok = true;
2020-05-15 12:51:09 +02:00
if (typeof pkg.description === 'undefined' || pkg.description === '') {
console.log ('description undefined');
2020-05-23 17:36:36 +02:00
ok = false;
2020-05-15 12:51:09 +02:00
}
if (typeof pkg.repository === 'object') {
if (pkg.repository.type !== 'git') {
console.log ('repository is not of type git');
ok = false;
}
if (!(/^https:\/\/.+\.git/iu).test (pkg.repository.url))
console.log ('repo url is not https.git');
}
else {
2020-05-15 12:51:09 +02:00
console.log ('repository undefined');
2020-05-23 17:36:36 +02:00
ok = false;
2020-05-15 12:51:09 +02:00
}
if (!(/^https:\/\/.+/iu).test (pkg.bugs)) {
console.log ('issue tracker url not defined');
ok = false;
}
2020-07-19 10:46:12 +02:00
if (typeof pkg.author === 'object') {
2020-07-19 11:06:59 +02:00
if (!authors.includes (JSON.stringify (pkg.author))) {
console.log ('author is none of the registered');
2020-07-19 10:46:12 +02:00
ok = false;
}
}
else {
console.log ('author not in object format');
ok = false;
}
2020-07-19 11:13:17 +02:00
if (!Array.isArray(pkg.keywords) || pkg.keywords.length < 1) {
console.log ('keywords empty');
ok = false;
}
2020-05-15 12:51:09 +02:00
function major (version) {
return version.replace (/\.[0-9x]+$/ui, '');
}
if (fs.existsSync ('README.md')) {
const readme = fs.readFileSync ('README.md', 'utf-8');
const version = (/version: ([0-9x.]+)/ui).exec (readme);
if (
version === null
|| major (version[1]) !== major (pkg.version)
) {
console.log ('readme version does not match package version');
2020-05-23 17:36:36 +02:00
ok = false;
2020-05-15 12:51:09 +02:00
}
}
else {
console.log ('readme does not exist');
2020-05-23 17:36:36 +02:00
ok = false;
2020-05-15 12:51:09 +02:00
}
2020-05-23 17:36:36 +02:00
if (fs.existsSync ('CHANGELOG.md')) {
const changelog = fs.readFileSync ('CHANGELOG.md', 'utf-8');
const cl_version = (/^## ([0-9x.]+)/mu).exec (changelog);
if (
cl_version === null
2020-05-23 17:42:25 +02:00
|| major (cl_version[1]) !== major (pkg.version)
2020-05-23 17:36:36 +02:00
) {
console.log ('changelog is not up to date');
ok = false;
}
}
else {
console.log ('changelog does not exist');
2020-07-19 10:36:45 +02:00
ok = false;
2020-05-23 17:36:36 +02:00
}
if (ok)
child_process.execSync ('yarn publish --access public');
else
process.exit (1);