Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processing index.html #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -79,4 +91,4 @@ function chunk<T>(arr: T[], max: number): T[][] {
chunks = [...chunks, arr];
}
return chunks;
}
}