This repository has been archived on 2021-02-20. You can view files and clone it, but cannot push or open issues or pull requests.
shapez.io/gulp/ftp.js

102 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-05-09 16:45:23 +02:00
const path = require("path");
const fs = require("fs");
const buildUtils = require("./buildutils");
function gulptasksFTP($, gulp, buildFolder) {
const commitHash = buildUtils.getRevision();
const additionalFolder = path.join(__dirname, "additional_build_files");
const additionalFiles = [
path.join(additionalFolder, "*"),
path.join(additionalFolder, "*.*"),
path.join(additionalFolder, ".*"),
];
const credentials = {
2020-07-05 12:54:43 +02:00
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-09 16:45:23 +02:00
// Write the "commit.txt" file
2020-06-13 17:59:25 +02:00
gulp.task("ftp.writeVersion", cb => {
2020-05-09 16:45:23 +02:00
fs.writeFileSync(
path.join(buildFolder, "version.json"),
JSON.stringify(
{
commit: buildUtils.getRevision(),
appVersion: buildUtils.getVersion(),
buildTime: new Date().getTime(),
},
null,
4
)
);
2020-06-13 17:59:25 +02:00
cb();
2020-05-09 16:45:23 +02:00
});
const gameSrcGlobs = [
path.join(buildFolder, "**/*.*"),
path.join(buildFolder, "**/.*"),
path.join(buildFolder, "**/*"),
path.join(buildFolder, "!**/index.html"),
];
2020-07-05 12:54:43 +02:00
for (const deployEnv of ["alpha", "prod", "staging"]) {
const deployCredentials = credentials[deployEnv];
2020-05-09 16:45:23 +02:00
gulp.task(`ftp.upload.${deployEnv}.game`, () => {
return gulp
.src(gameSrcGlobs, { base: buildFolder })
.pipe(
$.rename(pth => {
pth.dirname = path.join("v", commitHash, pth.dirname);
})
)
.pipe($.sftp(deployCredentials));
});
2020-05-09 16:45:23 +02:00
gulp.task(`ftp.upload.${deployEnv}.indexHtml`, () => {
return gulp
.src([path.join(buildFolder, "index.html"), path.join(buildFolder, "version.json")], {
base: buildFolder,
2020-05-09 16:45:23 +02:00
})
.pipe($.sftp(deployCredentials));
});
gulp.task(`ftp.upload.${deployEnv}.additionalFiles`, () => {
2020-05-18 19:50:00 +02:00
return gulp
.src(additionalFiles, { base: additionalFolder }) //
.pipe($.sftp(deployCredentials));
});
2020-05-09 16:45:23 +02:00
gulp.task(
`ftp.upload.${deployEnv}`,
gulp.series(
"ftp.writeVersion",
`ftp.upload.${deployEnv}.game`,
`ftp.upload.${deployEnv}.indexHtml`,
`ftp.upload.${deployEnv}.additionalFiles`
)
);
}
2020-05-09 16:45:23 +02:00
}
module.exports = {
gulptasksFTP,
};