Skip to content

Commit

Permalink
chrome: only upload automatically; publish should be manual
Browse files Browse the repository at this point in the history
  • Loading branch information
isnbh0 committed Dec 1, 2024
1 parent fce8ac3 commit 350ff1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
32 changes: 22 additions & 10 deletions scripts/publish-chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const credentials = process.env.MODE === 'local'
};

// Validate credentials
if (!credentials.clientId || !credentials.clientSecret || !credentials.refreshToken || !credentials.extensionId) {
if (!credentials.clientId || !credentials.clientSecret || !credentials.refreshToken || !credentials.chromeExtensionId) {
if (!credentials.clientId) {
console.error('❌ GOOGLE_CLIENT_ID not found in environment variables');
}
Expand Down Expand Up @@ -70,7 +70,7 @@ async function uploadExtension(accessToken, zipFilePath) {
console.log('πŸ“¦ Uploading extension package...');
const fileData = fs.readFileSync(zipFilePath);

const uploadUrl = `https://www.googleapis.com/upload/chromewebstore/v1.1/items/${credentials.extensionId}`;
const uploadUrl = `https://www.googleapis.com/upload/chromewebstore/v1.1/items/${credentials.chromeExtensionId}`;

const response = await fetch(uploadUrl, {
method: 'PUT',
Expand All @@ -82,9 +82,25 @@ async function uploadExtension(accessToken, zipFilePath) {
body: fileData
});

const responseText = await response.text();

try {
const responseData = JSON.parse(responseText);

if (responseData.uploadState === 'FAILURE' && responseData.itemError) {
const error = responseData.itemError[0];
if (error.error_code === 'ITEM_NOT_UPDATABLE') {
console.log('❗ Extension update blocked: The item is currently in pending review, ready to publish, or deleted status');
console.log('❗ Please wait for the review to complete or check the extension status in the Chrome Web Store dashboard');
process.exit(0); // Exit gracefully as this is an expected state
}
}
} catch (parseError) {
// If response isn't JSON, continue with normal error handling
}

if (!response.ok) {
const errorText = await response.text();
throw new Error(`Upload failed with status ${response.status}: ${errorText}`);
throw new Error(`Upload failed with status ${response.status}: ${responseText}`);
}

console.log('βœ… Extension package uploaded successfully');
Expand All @@ -98,7 +114,7 @@ async function uploadExtension(accessToken, zipFilePath) {
async function publishExtension(accessToken) {
try {
console.log('πŸš€ Publishing extension to Chrome Web Store...');
const publishUrl = `https://www.googleapis.com/chromewebstore/v1.1/items/${credentials.extensionId}/publish`;
const publishUrl = `https://www.googleapis.com/chromewebstore/v1.1/items/${credentials.chromeExtensionId}/publish`;

const response = await fetch(publishUrl, {
method: 'POST',
Expand Down Expand Up @@ -138,19 +154,15 @@ async function publishChromeExtension() {

try {
// Refresh access token
console.log('πŸ”„ Refreshing access token...');
const accessToken = await refreshAccessToken();
console.log(`πŸ”‘ Access token obtained: ${accessToken}`);

// Upload the extension package
console.log('πŸ“¦ Uploading extension package...');
await uploadExtension(accessToken, zipFilePath);
console.log('βœ… Extension package uploaded successfully.');

// Publish the extension
console.log('πŸš€ Publishing the extension to Chrome Web Store...');
await publishExtension(accessToken);
console.log('βœ… Extension published successfully.');
console.log('❗ NOTE: Publishing is to be done manually from the Chrome Web Store dashboard.');
} catch (error) {
console.error(`❌ An error occurred during the publishing process: ${error.message}`);
process.exit(1);
Expand Down
7 changes: 5 additions & 2 deletions scripts/zip-chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ filesToInclude.forEach((item) => {
});

// Finalize the archive (i.e., finish the stream)
archive.finalize().catch(err => {
console.error('❌ Error finalizing the archive:', err);
archive.finalize().then(() => {
console.log('βœ… Archive finalized successfully.');
}).catch(err => {
console.log('❌ Error finalizing the archive:', err.stack || err);
console.error('❌ Error finalizing the archive:', err.stack || err);
process.exit(1);
});

0 comments on commit 350ff1c

Please sign in to comment.