From 74d8aa8c9cf1ad7167261a7f19c2a93c1b692c7d Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sun, 15 Jan 2017 14:07:04 +0100 Subject: [PATCH] migrate copy script to node --- bin/copy-to-piskel-website.js | 62 +++++++++++++++++++++++++ misc/scripts/copy-to-piskel-website.cmd | 21 --------- package.json | 4 +- 3 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 bin/copy-to-piskel-website.js delete mode 100644 misc/scripts/copy-to-piskel-website.cmd diff --git a/bin/copy-to-piskel-website.js b/bin/copy-to-piskel-website.js new file mode 100644 index 00000000..02933cc6 --- /dev/null +++ b/bin/copy-to-piskel-website.js @@ -0,0 +1,62 @@ +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'); + +// 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...'); + console.log('Finished!'); +} + +fse.copy( + path.resolve(PISKEL_PATH, "dest/prod"), + path.resolve(PISKELAPP_PATH, "static/editor"), + onCopy +); \ No newline at end of file diff --git a/misc/scripts/copy-to-piskel-website.cmd b/misc/scripts/copy-to-piskel-website.cmd deleted file mode 100644 index d8537729..00000000 --- a/misc/scripts/copy-to-piskel-website.cmd +++ /dev/null @@ -1,21 +0,0 @@ -@ECHO off - -SETLOCAL - - SET PISKEL_PATH="C:\Development\git\piskel" - SET PISKELAPP_PATH="C:\Development\git\piskel-website" - - ECHO "Copying files to piskelapp" - XCOPY "%PISKEL_PATH%\dest\prod" "%PISKELAPP_PATH%\static\editor" /e /i /h /y - - ECHO "Delete previous partial" - DEL "%PISKELAPP_PATH%\templates\editor\main-partial.html" - ECHO "Copy new partial" - MOVE "%PISKELAPP_PATH%\static\editor\piskelapp-partials\main-partial.html" "%PISKELAPP_PATH%\templates\editor" - ECHO "Delete temp partial" - RMDIR "%PISKELAPP_PATH%\static\editor\piskelapp-partials\" /S /Q - - PAUSE - explorer "%PISKELAPP_PATH%\" - -ENDLOCAL \ No newline at end of file diff --git a/package.json b/package.json index a52620a6..2a4d574a 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "devDependencies": { "dateformat": "2.0.0", + "fs-extra": "1.0.0", "grunt": "^0.4.5", "grunt-casperjs": "^2.2.1", "grunt-contrib-clean": "1.0.0", @@ -53,7 +54,8 @@ "load-grunt-tasks": "3.5.0", "phantomjs": "2.1.7", "phantomjs-polyfill-object-assign": "0.0.2", - "promise-polyfill": "6.0.2" + "promise-polyfill": "6.0.2", + "rmdir": "1.2.0" }, "window": { "title": "Piskel",