1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00
joplin/Tools/release-clipper.js
Laurent Cozic 71efff6827
Linter update (#1777)
* Update eslint config

* Applied linter to lib

* Applied eslint config to CliClient/app

* Removed prettier due to https://github.com/prettier/prettier/pull/4765

* First pass on test units

* Applied linter config to test units

* Applied eslint config to clipper

* Applied to plugin dir

* Applied to root of ElectronClient

* Applied on RN root

* Applied on CLI root

* Applied on Clipper root

* Applied config to tools

* test hook

* test hook

* test hook

* Added pre-commit hook

* Applied rule no-trailing-spaces

* Make sure root packages are installed when installing sub-dir

* Added doc
2019-07-30 09:35:42 +02:00

99 lines
3.6 KiB
JavaScript

const fs = require('fs-extra');
const { execCommand } = require('./tool-utils.js');
const clipperDir = __dirname + '/../Clipper/joplin-webclipper';
const tmpSourceDir = __dirname + '/../Clipper/joplin-webclipper-source';
async function copyDir(baseSourceDir, sourcePath, baseDestDir) {
await fs.mkdirp(baseDestDir + '/' + sourcePath);
await fs.copy(baseSourceDir + '/' + sourcePath, baseDestDir + '/' + sourcePath);
}
async function copyToDist(distDir) {
await copyDir(clipperDir, 'popup/build', distDir);
await copyDir(clipperDir, 'content_scripts', distDir);
await copyDir(clipperDir, 'icons', distDir);
await fs.copy(clipperDir + '/background.js', distDir + '/background.js');
await fs.copy(clipperDir + '/main.js', distDir + '/main.js');
await fs.copy(clipperDir + '/manifest.json', distDir + '/manifest.json');
await fs.remove(distDir + '/popup/build/manifest.json');
}
async function updateManifestVersionNumber(manifestPath) {
const manifestText = await fs.readFile(manifestPath, 'utf-8');
let manifest = JSON.parse(manifestText);
let v = manifest.version.split('.');
const buildNumber = Number(v.pop()) + 1;
v.push(buildNumber);
manifest.version = v.join('.');
console.info('New version: ' + manifest.version);
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 4));
return manifest.version;
}
async function main() {
const newVersion = await updateManifestVersionNumber(clipperDir + '/manifest.json');
console.info('Building extension...');
process.chdir(clipperDir + '/popup');
console.info(await execCommand('npm run build'));
const dists = [
{
dir: clipperDir + '/dist/chrome',
name: 'chrome',
removeManifestKeys: (manifest) => {
manifest = Object.assign({}, manifest);
delete manifest.applications;
return manifest;
},
},
{
dir: clipperDir + '/dist/firefox',
name: 'firefox',
removeManifestKeys: (manifest) => {
manifest = Object.assign({}, manifest);
delete manifest.background.persistent;
return manifest;
},
},
];
for (let i = 0; i < dists.length; i++) {
const dist = dists[i];
await fs.remove(dist.dir);
await fs.mkdirp(dist.dir);
await copyToDist(dist.dir);
const manifestText = await fs.readFile(dist.dir + '/manifest.json', 'utf-8');
let manifest = JSON.parse(manifestText);
manifest.name = 'Joplin Web Clipper';
if (dist.removeManifestKeys) manifest = dist.removeManifestKeys(manifest);
await fs.writeFile(dist.dir + '/manifest.json', JSON.stringify(manifest, null, 4));
process.chdir(dist.dir);
console.info(await execCommand('7z a -tzip ' + dist.name + '.zip *'));
console.info(await execCommand('mv ' + dist.name + '.zip ..'));
}
console.info('Creating source tarball for code validation...');
process.chdir(clipperDir + '/../');
console.info(await execCommand('rsync -a --delete --exclude \'node_modules/\' --exclude \'build/\' --exclude \'dist/\' ' + clipperDir + '/ ' + tmpSourceDir + '/'));
console.info(await execCommand('7z a -tzip joplin-webclipper-source.zip joplin-webclipper-source'));
console.info(await execCommand('mv joplin-webclipper-source.zip ' + clipperDir + '/dist/ && rm -rf joplin-webclipper-source'));
console.info(await execCommand('git pull'));
console.info(await execCommand('git add -A'));
console.info(await execCommand('git commit -m "Clipper release v' + newVersion + '"'));
console.info(await execCommand('git tag clipper-' + newVersion));
console.info(await execCommand('git push'));
console.info(await execCommand('git push --tags'));
}
main().catch((error) => {
console.error('Fatal error');
console.error(error);
process.exit(1);
});