diff --git a/dist/index.js b/dist/index.js index 4f80628..5b36f1b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2345,9 +2345,11 @@ var child_process_1 = require("child_process"); var cross_fetch_1 = require("cross-fetch"); +var path_1 = require("path"); + (function () { return __awaiter(void 0, void 0, void 0, function () { - var urlPrefix_1, zoneID_1, apiToken_1, apiKey_1, email_1, fromCommit_1, toCommit_1, gitPath_1, diffFiles, fileURLs, chunks, requests, i, resp, _a, error_1; + var urlPrefix_1, zoneID_1, apiToken_1, apiKey_1, email_1, fromCommit_1, toCommit_1, gitPath_1, diffFiles, fileURLs_1, chunks, requests, i, resp, _a, error_1; return __generator(this, function (_b) { switch (_b.label) { @@ -2394,11 +2396,24 @@ var cross_fetch_1 = require("cross-fetch"); case 1: diffFiles = _b.sent(); - fileURLs = diffFiles.map(function (filePath) { + fileURLs_1 = diffFiles.map(function (filePath) { return (urlPrefix_1.endsWith('/') ? urlPrefix_1 : urlPrefix_1 + '/') + filePath; + }); // index.html + + diffFiles.map(function (filePath) { + if (path_1.basename(filePath, path_1.extname(filePath)) == 'index') { + var fileDir = path_1.dirname(filePath); + + if (fileDir == ".") { + fileDir = ""; + } + + fileURLs_1.push((urlPrefix_1.endsWith('/') ? urlPrefix_1 : urlPrefix_1 + '/') + fileDir); + fileURLs_1.push((urlPrefix_1.endsWith('/') ? urlPrefix_1 : urlPrefix_1 + '/') + fileDir + '/'); + } }); - console.log("Changed files:", JSON.stringify(fileURLs, null, 2)); - chunks = chunk(fileURLs, 30); + console.log("Changed files:", JSON.stringify(fileURLs_1, null, 2)); + chunks = chunk(fileURLs_1, 30); requests = chunks.map(function (chunk) { return cross_fetch_1.fetch("https://api.cloudflare.com/client/v4/zones/" + zoneID_1 + "/purge_cache", { method: 'POST', diff --git a/src/index.ts b/src/index.ts index 17cd3cc..8838085 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { getInput } from '@actions/core'; import { exec } from 'child_process'; import { fetch } from 'cross-fetch'; +import { basename, dirname, extname } from 'path'; (async () => { try { @@ -38,6 +39,17 @@ import { fetch } from 'cross-fetch'; const fileURLs: string[] = diffFiles.map(filePath => { return (urlPrefix.endsWith('/') ? urlPrefix : urlPrefix + '/') + filePath; }) + // index.html + diffFiles.map(filePath => { + if (basename(filePath, extname(filePath)) == 'index') { + var fileDir = dirname(filePath); + if(fileDir == "."){ + fileDir = ""; + } + fileURLs.push((urlPrefix.endsWith('/') ? urlPrefix : urlPrefix + '/') + fileDir); + fileURLs.push((urlPrefix.endsWith('/') ? urlPrefix : urlPrefix + '/') + fileDir + '/'); + } + }) console.log("Changed files:", JSON.stringify(fileURLs, null, 2)); const chunks = chunk(fileURLs, 30); @@ -79,4 +91,4 @@ function chunk(arr: T[], max: number): T[][] { chunks = [...chunks, arr]; } return chunks; -} \ No newline at end of file +}