piskel/bin/copy-to-piskel-website.js

75 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-01-15 16:07:04 +03:00
const rmdir = require('rmdir');
const path = require('path');
const fs = require('fs');
const fse = require('fs-extra');
const PISKEL_PATH = path.resolve(__dirname, '..');
const PISKELAPP_PATH = path.resolve(__dirname, '../../piskel-website');
2017-05-07 03:00:09 +03:00
var pjson = require('../package.json');
2017-01-15 16:07:04 +03:00
// Callbacks sorted by call sequence.
function onCopy(err) {
if (err) {
console.error('Failed to copy static files...');
return console.error(err);
}
console.log('Copied static files to piskel-website...');
let previousPartialPath = path.resolve(PISKELAPP_PATH, 'templates/editor/main-partial.html');
fs.unlink(previousPartialPath, onDeletePreviousPartial);
}
function onDeletePreviousPartial(err) {
if (err) {
console.error('Failed to delete previous main partial...');
return console.error(err);
}
console.log('Previous main partial deleted...');
fse.copy(
path.resolve(PISKELAPP_PATH, "static/editor/piskelapp-partials/main-partial.html"),
path.resolve(PISKELAPP_PATH, "templates/editor/main-partial.html"),
onCopyNewPartial
);
}
function onCopyNewPartial(err) {
if (err) {
console.error('Failed to delete previous main partial...');
return console.error(err);
}
console.log('Main partial copied...');
rmdir(
path.resolve(PISKELAPP_PATH, "static/editor/piskelapp-partials/"),
onDeleteTempPartial
);
}
function onDeleteTempPartial(err) {
if (err) {
console.error('Failed to delete temporary main partial...');
return console.error(err);
}
console.log('Temporary main partial deleted...');
2017-05-07 03:00:09 +03:00
fs.writeFile(path.resolve(PISKELAPP_PATH, "static/editor/VERSION"), pjson.version, onVersionFileCreated);
}
function onVersionFileCreated(err) {
if (err) {
console.error('Failed to create temporary main partial...');
return console.error(err);
}
console.log('Version file created...');
2017-01-15 16:07:04 +03:00
console.log('Finished!');
}
fse.copy(
path.resolve(PISKEL_PATH, "dest/prod"),
path.resolve(PISKELAPP_PATH, "static/editor"),
onCopy
);