|
|
@ -4,7 +4,6 @@ import path from 'path'; |
|
|
import fetch from "node-fetch"; |
|
|
import fetch from "node-fetch"; |
|
|
import express from 'express'; |
|
|
import express from 'express'; |
|
|
import {create} from 'express-handlebars'; |
|
|
import {create} from 'express-handlebars'; |
|
|
import fsExtra from 'fs-extra'; |
|
|
|
|
|
import browserSync from 'browser-sync'; |
|
|
import browserSync from 'browser-sync'; |
|
|
import config from 'config'; |
|
|
import config from 'config'; |
|
|
import gulp from 'gulp'; |
|
|
import gulp from 'gulp'; |
|
|
@ -19,8 +18,7 @@ import open from "open"; |
|
|
import {sanitizeUrl} from "@braintree/sanitize-url"; |
|
|
import {sanitizeUrl} from "@braintree/sanitize-url"; |
|
|
import sanitizeHtml from 'sanitize-html'; |
|
|
import sanitizeHtml from 'sanitize-html'; |
|
|
import {escape} from "lodash-es"; |
|
|
import {escape} from "lodash-es"; |
|
|
import archiver from 'archiver'; |
|
|
import {getBlockConfigs, getConfigs, readJSONFile, zipProject} from "./helpers.js"; |
|
|
import {getBlockConfigs, getConfigs, readJSONFile} from "./helpers.js"; |
|
|
|
|
|
import PluginError from 'plugin-error'; |
|
|
import PluginError from 'plugin-error'; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -130,7 +128,7 @@ app.get('/publish', async (req, res) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (responseData.uploadUrl) { |
|
|
if (responseData.uploadUrl) { |
|
|
await zipProject(); |
|
|
await zipProject(path.join(projectPath, 'src')); |
|
|
const body = await fs.readFile(path.join(projectPath, 'dist.zip')); |
|
|
const body = await fs.readFile(path.join(projectPath, 'dist.zip')); |
|
|
const response = await fetch(`${responseData.uploadUrl}`, { |
|
|
const response = await fetch(`${responseData.uploadUrl}`, { |
|
|
method: 'PUT', |
|
|
method: 'PUT', |
|
|
@ -339,52 +337,6 @@ function prepareListOfDataFiles(dataFiles) { |
|
|
.sort(); |
|
|
.sort(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function zipProject() { |
|
|
|
|
|
// create a file to stream archive data to.
|
|
|
|
|
|
const output = await fsExtra.createWriteStream('dist.zip'); |
|
|
|
|
|
const archive = archiver('zip', {}); |
|
|
|
|
|
|
|
|
|
|
|
// listen for all archive data to be written
|
|
|
|
|
|
// 'close' event is fired only when a file descriptor is involved
|
|
|
|
|
|
output.on('close', function () { |
|
|
|
|
|
console.log(archive.pointer() + ' total bytes'); |
|
|
|
|
|
console.log('archiver has been finalized and the output file descriptor has closed.'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// This event is fired when the data source is drained no matter what was the data source.
|
|
|
|
|
|
// It is not part of this library but rather from the NodeJS Stream API.
|
|
|
|
|
|
// @see: https://nodejs.org/api/stream.html#stream_event_end
|
|
|
|
|
|
output.on('end', function () { |
|
|
|
|
|
console.log('Data has been drained'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// good practice to catch warnings (ie stat failures and other non-blocking errors)
|
|
|
|
|
|
archive.on('warning', function (err) { |
|
|
|
|
|
if (err.code === 'ENOENT') { |
|
|
|
|
|
// log warning
|
|
|
|
|
|
} else { |
|
|
|
|
|
// throw error
|
|
|
|
|
|
throw err; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// good practice to catch this error explicitly
|
|
|
|
|
|
archive.on('error', function (err) { |
|
|
|
|
|
throw err; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// pipe archive data to the file
|
|
|
|
|
|
archive.pipe(output); |
|
|
|
|
|
|
|
|
|
|
|
// append files from a subdirectory, putting its contents at the root of archive
|
|
|
|
|
|
archive.directory(path.join(projectPath, 'src'), false); |
|
|
|
|
|
|
|
|
|
|
|
// finalize the archive (ie we are done appending files but streams have to finish yet)
|
|
|
|
|
|
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
|
|
|
|
|
await archive.finalize(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleSyntaxErrors(err, req, res, next) { |
|
|
function handleSyntaxErrors(err, req, res, next) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
return res.render('error', { |
|
|
return res.render('error', { |
|
|
|