Skip to content
This repository was archived by the owner on Jan 2, 2022. It is now read-only.

Commit 3aca187

Browse files
committed
feat: use Netlify utils to improve output
1 parent 98b1cd2 commit 3aca187

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/index.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ interface NetlifyUtils {
66
restore: (path: string, options?: Partial<{cwd: string}>) => Promise<boolean>;
77
save: (path: string, options?: Partial<{digests: string[]; cwd: string; ttl: number}>) => Promise<boolean>;
88
};
9+
build: {
10+
failBuild: (message: string) => unknown;
11+
failPlugin: (message: string) => unknown;
12+
cancelBuild: (message: string) => unknown;
13+
};
14+
status: {
15+
/** @see https://docs.netlify.com/configure-builds/build-plugins/create-plugins/#logging */
16+
show: (status: {title?: string; summary: string; text?: string}) => unknown;
17+
};
918
}
1019

1120
interface NetlifyInputs {
@@ -64,9 +73,12 @@ module.exports = {
6473
console.log(`${paths.absolute.buildDir} ${existsSync(paths.absolute.buildDir) ? 'exists' : 'does not exist'} on disk`);
6574

6675
if (success) {
67-
console.log(`Restored the cached ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
76+
const message = `Restored the cached ${paths.buildDirName} folder at the location ${paths.absolute.buildDir}`;
77+
78+
console.log(message);
79+
utils.status.show({summary: `Restored the ${paths.buildDirName} folder`, text: message});
6880
} else {
69-
console.log(`Couldn't restore the cache for the ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
81+
utils.build.failPlugin(`Couldn't restore the cache for the ${paths.buildDirName} folder at the location ${paths.absolute.buildDir}`);
7082
}
7183
},
7284
// Cache file/directory for future builds.
@@ -85,9 +97,12 @@ module.exports = {
8597
});
8698

8799
if (success) {
88-
console.log(`Cached the ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
100+
const message = `Cached the ${paths.buildDirName} folder at the location ${paths.absolute.buildDir}`;
101+
102+
console.log(message);
103+
utils.status.show({summary: `Saved the ${paths.buildDirName} folder`, text: message});
89104
} else {
90-
console.log(`Couldn't cache the ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
105+
utils.build.failPlugin(`Couldn't cache the ${paths.buildDirName} folder at the location ${paths.absolute.buildDir}`);
91106
}
92107
}
93108
};

0 commit comments

Comments
 (0)