Skip to content

Commit 1e20dfa

Browse files
committed
Update cli.mjs
1 parent eb0a4bf commit 1e20dfa

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

bin/cli.mjs

+16-14
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@ const adsTxtContent = `google.com, ${env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID}, DIRE
1616
const createAdsTxt = async () => {
1717
console.log(`📝 [next-google-adsense] Creating "ads.txt"...`);
1818

19-
if (!isPublisherId(env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID)) {
20-
throw new Error(
21-
`❌ [next-google-adsense] Invalid Google AdSense Publisher ID: ${env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID}`
19+
if (isPublisherId(env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID)) {
20+
try {
21+
await fs.access(publicPath);
22+
} catch (err) {
23+
console.log(`📁 [next-google-adsense] Creating "public" folder...`);
24+
await fs.mkdir(publicPath);
25+
}
26+
27+
await fs.writeFile(adsTxtPath, adsTxtContent);
28+
29+
console.log(`✅ [next-google-adsense] Generation completed: ${adsTxtPath}`);
30+
console.log(
31+
`✨ [next-google-adsense] You can access it at: http://<hostname>/ads.txt`
2232
);
2333
}
2434

25-
try {
26-
await fs.access(publicPath);
27-
} catch (err) {
28-
console.log(`📁 [next-google-adsense] Creating "public" folder...`);
29-
await fs.mkdir(publicPath);
30-
}
31-
32-
await fs.writeFile(adsTxtPath, adsTxtContent);
33-
34-
console.log(`✅ [next-google-adsense] Generation completed: ${adsTxtPath}`);
35-
console.log(`✨ [next-google-adsense] You can access it at: http://<hostname>/ads.txt`);
35+
console.error(
36+
`❌ [next-google-adsense] Invalid Google AdSense Publisher ID: ${env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID}`
37+
);
3638
};
3739

3840
createAdsTxt();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-google-adsense",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Next.js Google AdSense",
55
"main": "dist/index.js",
66
"type": "commonjs",

0 commit comments

Comments
 (0)