1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-14 02:31:51 +00:00
tobspr_shapez.io/gulp/ftp.js

100 lines
2.8 KiB
JavaScript
Raw Normal View History

import path from "path/posix";
import fs from "fs/promises";
import gulp from "gulp";
import { buildFolder } from "./config.js";
2020-05-09 14:45:23 +00:00
import { getRevision, getVersion } from "./buildutils.js";
2020-05-09 14:45:23 +00:00
import gulpRename from "gulp-rename";
import gulpSftp from "gulp-sftp";
2020-05-09 14:45:23 +00:00
const commitHash = getRevision();
const additionalFolder = path.join("additional_build_files");
const additionalGlobs = [
path.join(additionalFolder, "*"),
path.join(additionalFolder, "*.*"),
path.join(additionalFolder, ".*"),
];
const credentials = {
alpha: {
host: process.env.SHAPEZ_CLI_SERVER_HOST,
user: process.env.SHAPEZ_CLI_ALPHA_FTP_USER,
pass: process.env.SHAPEZ_CLI_ALPHA_FTP_PW,
},
staging: {
host: process.env.SHAPEZ_CLI_SERVER_HOST,
user: process.env.SHAPEZ_CLI_STAGING_FTP_USER,
pass: process.env.SHAPEZ_CLI_STAGING_FTP_PW,
},
prod: {
host: process.env.SHAPEZ_CLI_SERVER_HOST,
user: process.env.SHAPEZ_CLI_LIVE_FTP_USER,
pass: process.env.SHAPEZ_CLI_LIVE_FTP_PW,
},
};
// Write the "commit.txt" file
export async function writeVersion() {
await fs.writeFile(
path.join(buildFolder, "version.json"),
JSON.stringify(
{
commit: getRevision(),
appVersion: getVersion(),
buildTime: new Date().getTime(),
},
null,
4
)
);
}
2020-05-09 14:45:23 +00:00
const gameSrcGlobs = [
path.join(buildFolder, "**/*.*"),
path.join(buildFolder, "**/.*"),
path.join(buildFolder, "**/*"),
path.join(buildFolder, "!**/index.html"),
];
2020-05-09 14:45:23 +00:00
export const upload = Object.fromEntries(
["alpha", "prod", "staging"].map(deployEnv => {
const deployCredentials = credentials[deployEnv];
2020-05-09 14:45:23 +00:00
function game() {
return gulp
.src(gameSrcGlobs, { base: buildFolder })
.pipe(
gulpRename(pth => {
pth.dirname = path.join("v", commitHash, pth.dirname);
})
)
.pipe(gulpSftp(deployCredentials));
}
2020-05-09 14:45:23 +00:00
function indexHtml() {
return gulp
.src([path.join(buildFolder, "index.html"), path.join(buildFolder, "version.json")], {
base: buildFolder,
2020-05-09 14:45:23 +00:00
})
.pipe(gulpSftp(deployCredentials));
}
function additionalFiles() {
return gulp.src(additionalGlobs, { base: additionalFolder }).pipe(gulpSftp(deployCredentials));
}
2020-05-09 14:45:23 +00:00
return [
deployEnv,
{
game,
indexHtml,
additionalFiles,
all: gulp.series(writeVersion, game, indexHtml, additionalFiles),
},
];
})
);