From 2d56b4cc68a9e8acccd3ae4b53de2fa138aa6b11 Mon Sep 17 00:00:00 2001 From: Mu-Tsun Tsai Date: Mon, 1 Apr 2024 13:59:26 +0800 Subject: [PATCH] Fix build script bug after fresh-cloning of repo --- gulp/tasks/ftp.js | 31 +++++++++++++++++++++++-------- gulp/tasks/lib.js | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gulp/tasks/ftp.js b/gulp/tasks/ftp.js index e6de506a..de4165c2 100644 --- a/gulp/tasks/ftp.js +++ b/gulp/tasks/ftp.js @@ -1,12 +1,20 @@ const $ = require("../utils/proxy"); const gulp = require("gulp"); +const { existsSync } = require("fs"); const config = require("../config.json"); const seriesIf = require("../utils/seriesIf"); // This file is not in the repo, of course -/** @type {import("../../.vscode/ftp.json")} */ -const ftpConfig = require(process.cwd() + "/.vscode/ftp.json"); +const ftpConfigPath = process.cwd() + "/.vscode/ftp.json"; + +/** @type {import("../../.vscode/ftp.json")|null} */ +const ftpConfig = existsSync(ftpConfigPath) ? require(ftpConfigPath) : null; + +function configGuard() { + if(!ftpConfig) throw new Error("The repo is not figured with FTP. This operation is for maintainers only."); + return true; +} function connect() { const ftp = require("vinyl-ftp"); @@ -63,7 +71,7 @@ async function ftpFactory(folder, additionalGlobs, pipeFactory) { ); } -gulp.task("cleanPub", () => seriesIf( +gulp.task("cleanPub", () => configGuard() && seriesIf( async () => { const inquirer = (await import("inquirer")).default; const answers = await inquirer.prompt([{ @@ -76,15 +84,19 @@ gulp.task("cleanPub", () => seriesIf( }, () => cleanFactory("bp") )); -gulp.task("uploadPub", () => ftpFactory("bp", [config.dest.dist + "/.htaccess"])); +gulp.task("uploadPub", () => configGuard() && ftpFactory("bp", [ + config.dest.dist + "/.htaccess", + "!**/vue.runtime.global.js", // debug-only +])); /** * @param {"qa"|"dev"} id */ function taskFactory(id) { const name = id.replace(/^\w/, a => a.toUpperCase()); - gulp.task("clean" + name, () => cleanFactory(ftpConfig[id].folder)); + gulp.task("clean" + name, () => configGuard() && cleanFactory(ftpConfig[id].folder)); gulp.task("upload" + name, () => { + configGuard(); const lazypipe = require("lazypipe"); const htmlPipe = lazypipe() .pipe(() => $.replace('