2018-05-25 14:30:27 +02:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const { execCommand } = require('./tool-utils.js');
|
|
|
|
|
|
|
|
const clipperDir = __dirname + '/../Clipper/joplin-webclipper';
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2018-06-14 20:11:22 +02:00
|
|
|
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));
|
2018-06-28 23:16:15 +02:00
|
|
|
return manifest.version;
|
2018-06-14 20:11:22 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 14:30:27 +02:00
|
|
|
async function main() {
|
2018-06-28 23:16:15 +02:00
|
|
|
const newVersion = await updateManifestVersionNumber(clipperDir + '/manifest.json');
|
2018-05-25 14:30:27 +02:00
|
|
|
|
2018-06-14 20:11:22 +02:00
|
|
|
console.info('Building extension...');
|
|
|
|
process.chdir(clipperDir + '/popup');
|
2018-05-25 14:30:27 +02:00
|
|
|
console.info(await execCommand('npm run build'));
|
|
|
|
|
|
|
|
const dists = [
|
|
|
|
{
|
2018-06-14 20:11:22 +02:00
|
|
|
dir: clipperDir + '/dist/chrome',
|
2018-05-25 14:30:27 +02:00
|
|
|
name: 'chrome',
|
2018-06-14 20:11:22 +02:00
|
|
|
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;
|
|
|
|
},
|
2018-05-25 14:30:27 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < dists.length; i++) {
|
|
|
|
const dist = dists[i];
|
2018-06-14 20:11:22 +02:00
|
|
|
await fs.remove(dist.dir);
|
|
|
|
await fs.mkdirp(dist.dir);
|
2018-05-25 14:30:27 +02:00
|
|
|
await copyToDist(dist.dir);
|
2018-06-14 20:11:22 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2018-05-25 14:30:27 +02:00
|
|
|
process.chdir(dist.dir);
|
|
|
|
console.info(await execCommand('7z a -tzip ' + dist.name + '.zip *'));
|
2018-06-14 20:11:22 +02:00
|
|
|
console.info(await execCommand('mv ' + dist.name + '.zip ..'));
|
2018-05-25 14:30:27 +02:00
|
|
|
}
|
2018-06-28 23:16:15 +02:00
|
|
|
|
|
|
|
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'));
|
2018-05-25 14:30:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error('Fatal error');
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|