This repository has been archived by the owner on Mar 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
270 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface WebBuildSettings { | ||
outputFolder: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as TreeView from "dnd-tree-view"; | ||
|
||
let outputFolder: string; | ||
|
||
export default class WebBuildSettingsEditor implements SupClient.BuildSettingsEditor { | ||
private outputFolderTextfield: HTMLInputElement; | ||
private outputFolderButton: HTMLButtonElement; | ||
private errorRowElt: HTMLTableRowElement; | ||
private errorInput: HTMLInputElement; | ||
|
||
private table: HTMLTableElement; | ||
|
||
constructor(container: HTMLDivElement, private entries: SupCore.Data.Entries, private entriesTreeView: TreeView) { | ||
const { table, tbody } = SupClient.table.createTable(container); | ||
this.table = table; | ||
table.classList.add("properties"); | ||
table.hidden = true; | ||
|
||
const outputFolderRow = SupClient.table.appendRow(tbody, SupClient.i18n.t("buildSettingsEditors:web.outputFolder")); | ||
const inputs = SupClient.html("div", "inputs", { parent: outputFolderRow.valueCell }); | ||
|
||
const value = outputFolder != null ? outputFolder : ""; | ||
this.outputFolderTextfield = SupClient.html("input", { parent: inputs, type: "text", value, readOnly: true, style: { cursor: "pointer" } }) as HTMLInputElement; | ||
this.outputFolderButton = SupClient.html("button", { parent: inputs, textContent: SupClient.i18n.t("common:actions.select") }) as HTMLButtonElement; | ||
|
||
this.outputFolderTextfield.addEventListener("click", (event) => { event.preventDefault(); this.selectOutputfolder(); }); | ||
this.outputFolderButton.addEventListener("click", (event) => { event.preventDefault(); this.selectOutputfolder(); }); | ||
|
||
const errorRow = SupClient.table.appendRow(tbody, "Error"); | ||
this.errorRowElt = errorRow.row; | ||
this.errorRowElt.hidden = true; | ||
this.errorInput = SupClient.html("input", { parent: errorRow.valueCell, type: "text", readOnly: true }) as HTMLInputElement; | ||
} | ||
|
||
setVisible(visible: boolean) { | ||
this.table.hidden = !visible; | ||
} | ||
|
||
getSettings(callback: (settings: WebBuildSettings) => void) { | ||
this.ensureOutputFolderValid((outputFolderValid) => { | ||
callback(outputFolderValid ? { outputFolder } : null); | ||
}); | ||
} | ||
|
||
private selectOutputfolder() { | ||
SupApp.chooseFolder((folderPath) => { | ||
if (folderPath == null) return; | ||
|
||
outputFolder = this.outputFolderTextfield.value = folderPath; | ||
this.ensureOutputFolderValid(); | ||
}); | ||
} | ||
|
||
private ensureOutputFolderValid(callback?: (outputFolderValid: boolean) => void) { | ||
if (outputFolder == null) { | ||
this.displayError(SupClient.i18n.t("buildSettingsEditors:web.errors.selectDestionationFolder")); | ||
if (callback != null) callback(false); | ||
return; | ||
} | ||
|
||
SupApp.readDir(outputFolder, (err, files) => { | ||
if (err != null) { | ||
this.displayError(SupClient.i18n.t("buildSettingsEditors:web.errors.emptyDirectoryCheckFail")); | ||
console.log(err); | ||
if (callback != null) callback(false); | ||
return; | ||
} | ||
|
||
let index = 0; | ||
while (index < files.length) { | ||
const item = files[index]; | ||
if (item[0] === "." || item === "Thumbs.db") files.splice(index, 1); | ||
else index++; | ||
} | ||
|
||
if (files.length > 0) { | ||
this.displayError(SupClient.i18n.t("buildSettingsEditors:web.errors.destinationFolderEmpty")); | ||
if (callback != null) callback(false); | ||
} else { | ||
this.errorRowElt.hidden = true; | ||
if (callback != null) callback(true); | ||
} | ||
}); | ||
} | ||
|
||
private displayError(err: string) { | ||
this.errorRowElt.hidden = false; | ||
this.errorInput.value = err; | ||
|
||
(this.errorRowElt as any).animate([ | ||
{ transform: "translateX(0)" }, | ||
{ transform: "translateX(1.5vh)" }, | ||
{ transform: "translateX(0)" } | ||
], { duration: 100 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as async from "async"; | ||
import * as querystring from "querystring"; | ||
import supFetch from "../../../../../../SupClient/src/fetch"; | ||
import * as path from "path"; | ||
|
||
const qs = querystring.parse(window.location.search.slice(1)); | ||
|
||
let settings: WebBuildSettings; | ||
|
||
const progress = { index: 0, total: 0, errors: 0 }; | ||
const statusElt = document.querySelector(".status"); | ||
const progressElt = document.querySelector("progress") as HTMLProgressElement; | ||
const detailsListElt = document.querySelector(".details ol") as HTMLOListElement; | ||
|
||
export default function build(socket: SocketIOClient.Socket, theSettings: WebBuildSettings, buildPort: number) { | ||
settings = theSettings; | ||
|
||
socket.emit("build:project", (err: string, buildId: string) => { | ||
const buildPath = `${window.location.protocol}//${window.location.hostname}:${buildPort}/builds/${qs.project}/${buildId}/`; | ||
|
||
supFetch(`${buildPath}files.json`, "json", (err, filesToDownload) => { | ||
if (err != null) { | ||
progress.errors++; | ||
SupClient.html("li", { parent: detailsListElt, textContent: SupClient.i18n.t("builds:web.errors.exportFailed", { path: settings.outputFolder }) }); | ||
return; | ||
} | ||
|
||
progress.total = filesToDownload.length; | ||
updateProgress(); | ||
|
||
async.each(filesToDownload as string[], (filePath, cb) => { | ||
downloadFile(buildPath, filePath, (err) => { | ||
if (err != null) { | ||
progress.errors++; | ||
SupClient.html("li", { parent: detailsListElt, textContent: SupClient.i18n.t("builds:web.errors.exportFailed", { path: filePath }) }); | ||
} else { | ||
progress.index++; | ||
updateProgress(); | ||
} | ||
|
||
cb(err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function updateProgress() { | ||
progressElt.max = progress.total; | ||
progressElt.value = progress.index; | ||
|
||
if (progress.index < progress.total) { | ||
statusElt.textContent = SupClient.i18n.t("builds:web.progress", { path: settings.outputFolder, index: progress.index, total: progress.total }); | ||
} else if (progress.errors > 0) { | ||
statusElt.textContent = SupClient.i18n.t("builds:web.doneWithErrors", { path: settings.outputFolder, total: progress.total, errors: progress.errors }); | ||
} else { | ||
statusElt.textContent = SupClient.i18n.t("builds:web.done", { path: settings.outputFolder, total: progress.total }); | ||
} | ||
} | ||
|
||
function downloadFile(buildPath: string, filePath: string, callback: ErrorCallback) { | ||
const inputPath = `${buildPath}files/${filePath}`; | ||
const outputPath = path.join(settings.outputFolder, filePath); | ||
|
||
SupApp.mkdirp(path.dirname(outputPath), (err) => { | ||
supFetch(inputPath, "arraybuffer", (err, data) => { | ||
if (err != null) { callback(err); return; } | ||
|
||
SupApp.writeFile(outputPath, new Buffer(data), callback); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference path="./WebBuildSettings.d.ts" /> | ||
|
||
import WebBuildSettingsEditor from "./WebBuildSettingsEditor"; | ||
import buildWeb from "./buildWeb"; | ||
|
||
SupClient.registerPlugin<SupClient.BuildPlugin>("build", "web", { | ||
settingsEditor: WebBuildSettingsEditor, | ||
build: buildWeb | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference path="../../../../../SupCore/SupCore.d.ts" /> | ||
/// <reference path="../../../../../SupClient/SupClient.d.ts" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "superpowers-web-default-export-plugin", | ||
"description": "Export plugin for Superpowers Web, the collaborative static site editor", | ||
"version": "1.0.0", | ||
"license": "ISC", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/superpowers/superpowers-web.git" | ||
}, | ||
"scripts": { | ||
"build": "gulp --gulpfile=../../../../../scripts/pluginGulpfile.js --cwd=." | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
plugins/default/export/public/locales/en/buildSettingsEditors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"web": { | ||
"label": "Default", | ||
"description": "Export as HTML5", | ||
|
||
"outputFolder": "Output folder", | ||
"errors": { | ||
"selectDestionationFolder": "Select a destination folder.", | ||
"emptyDirectoryCheckFail": "Failed to check if the selected folder is empty.", | ||
"destinationFolderEmpty": "The destination folder must be empty." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"web": { | ||
"title": "HTML5 export", | ||
"progress": "Exporting to ${path}... (${index}/${total})", | ||
"doneWithErrors": "Encountered ${errors} errors while exporting ${total} elements to ${path}.", | ||
"done": "Exported ${total} elements to ${path}.", | ||
|
||
"errors": { | ||
"exportFailed": "Failed to export ${path}." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"noImplicitAny": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters