2022-12-03 04:23:18 +00:00
|
|
|
import path from "path/posix";
|
2024-04-24 21:30:01 +00:00
|
|
|
import fs from "fs/promises";
|
|
|
|
|
import gulp from "gulp";
|
|
|
|
|
import { buildFolder } from "./config.js";
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2022-12-03 04:23:18 +00:00
|
|
|
import { getRevision, getVersion } from "./buildutils.js";
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2022-12-03 04:23:18 +00:00
|
|
|
import gulpRename from "gulp-rename";
|
|
|
|
|
import gulpSftp from "gulp-sftp";
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
const commitHash = getRevision();
|
2022-12-03 04:23:18 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
const additionalFolder = path.join("additional_build_files");
|
2020-05-18 17:47:40 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
const additionalGlobs = [
|
|
|
|
|
path.join(additionalFolder, "*"),
|
|
|
|
|
path.join(additionalFolder, "*.*"),
|
|
|
|
|
path.join(additionalFolder, ".*"),
|
|
|
|
|
];
|
2020-05-18 17:47:40 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
};
|
2020-05-18 17:47:40 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
// 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
|
|
|
|
2024-04-24 21:30:01 +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
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
export const upload = Object.fromEntries(
|
|
|
|
|
["alpha", "prod", "staging"].map(deployEnv => {
|
2020-05-18 17:47:40 +00:00
|
|
|
const deployCredentials = credentials[deployEnv];
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
function game() {
|
2020-05-18 17:47:40 +00:00
|
|
|
return gulp
|
|
|
|
|
.src(gameSrcGlobs, { base: buildFolder })
|
|
|
|
|
.pipe(
|
2022-12-03 04:23:18 +00:00
|
|
|
gulpRename(pth => {
|
2020-05-18 17:47:40 +00:00
|
|
|
pth.dirname = path.join("v", commitHash, pth.dirname);
|
|
|
|
|
})
|
|
|
|
|
)
|
2022-12-03 04:23:18 +00:00
|
|
|
.pipe(gulpSftp(deployCredentials));
|
2024-04-24 21:30:01 +00:00
|
|
|
}
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
function indexHtml() {
|
2020-05-18 17:47:40 +00:00
|
|
|
return gulp
|
|
|
|
|
.src([path.join(buildFolder, "index.html"), path.join(buildFolder, "version.json")], {
|
|
|
|
|
base: buildFolder,
|
2020-05-09 14:45:23 +00:00
|
|
|
})
|
2022-12-03 04:23:18 +00:00
|
|
|
.pipe(gulpSftp(deployCredentials));
|
2024-04-24 21:30:01 +00:00
|
|
|
}
|
2020-05-18 17:47:40 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
function additionalFiles() {
|
|
|
|
|
return gulp.src(additionalGlobs, { base: additionalFolder }).pipe(gulpSftp(deployCredentials));
|
|
|
|
|
}
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
return [
|
|
|
|
|
deployEnv,
|
|
|
|
|
{
|
|
|
|
|
game,
|
|
|
|
|
indexHtml,
|
|
|
|
|
additionalFiles,
|
|
|
|
|
all: gulp.series(writeVersion, game, indexHtml, additionalFiles),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
})
|
|
|
|
|
);
|