<commit_before>/*
BEFORE PUBLISHING
- Run the build so that the build folder exists.
- Update the version in the manifest JSON and the package JSON (the latter doesn't actually change anything but I'm OCD).
*/

import chromeWebstoreUpload from 'chrome-webstore-upload'
import fs from 'fs'
import zipdir from 'zip-dir'

const dir = './dist';
if (!fs.existsSync(dir)){
    fs.mkdirSync(dir);
}

await zipdir('./build', { saveTo: './dist/seshy.zip' });

const store = chromeWebstoreUpload({
	extensionId: 'noeieddjehppejohbbchbcmheecaneac',
	clientId: process.env.SESHY_PUBLISHER_CLIENT_ID,
	refreshToken: process.env.SESHY_PUBLISHER_REFRESH_TOKEN,
})
const token = await store.fetchToken()
const myZipFile = fs.createReadStream('./dist/seshy.zip')
const resource = await store.uploadExisting(myZipFile, token)
console.info('New version uploaded', resource)

await store.publish('default', token)
console.info('New version published')<commit_msg>Add error handling to publish script<commit_after>/*
BEFORE PUBLISHING
- Run the build so that the build folder exists.
- Update the version in the manifest JSON and the package JSON (the latter doesn't actually change anything but I'm OCD).
*/

import chromeWebstoreUpload from 'chrome-webstore-upload'
import fs from 'fs'
import zipdir from 'zip-dir'

createDistFolder();
await zipBuildFolder();

const store = chromeWebstoreUpload({
	extensionId: 'noeieddjehppejohbbchbcmheecaneac',
	clientId: process.env.SESHY_PUBLISHER_CLIENT_ID,
	refreshToken: process.env.SESHY_PUBLISHER_REFRESH_TOKEN,
})

try {
	const token = await store.fetchToken()
	await uploadZip(token);
	await publish(token);
} catch (error) {
	console.error(error.message, '\n', error.response.body)
}

async function publish (token) {
	await store.publish('default', token);
	console.info('New version published');
}

async function uploadZip (token) {
	const seshyZip = fs.createReadStream('./dist/seshy.zip');
	const resource = await store.uploadExisting(seshyZip, token);
	console.info('New version uploaded', resource);
}

async function zipBuildFolder () {
	await zipdir('./build', { saveTo: './dist/seshy.zip' });
}

function createDistFolder () {
	const dir = './dist';
	if (!fs.existsSync(dir)) {
		fs.mkdirSync(dir);
	}
}

{'fraction_non_alphanumeric': 0.12221231043710973, 'fraction_numerical': 0.0, 'mean_word_length': 5.426934097421204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3665077', 'n_tokens_mistral': 741, 'n_tokens_neox': 718, 'n_words': 200}