Skip to content

Commit

Permalink
Turn into ES Module + update all dependencies (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Sep 18, 2021
1 parent 41f8a0c commit 1829794
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 171 deletions.
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (command, flags) {
export default function getConfig(command, flags) {
const apiConfig = {
extensionId: flags.extensionId || process.env.EXTENSION_ID,
clientId: flags.clientId || process.env.CLIENT_ID,
Expand All @@ -14,4 +14,4 @@ module.exports = function (command, flags) {
autoPublish: flags.autoPublish,
trustedTesters: flags.trustedTesters,
};
};
}
28 changes: 13 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node

const path = require('path');
const ora = require('ora');
const meow = require('meow');
const { green, red, yellow } = require('chalk');
const createConfig = require('./config');
const { upload, publish, fetchToken } = require('./wrapper');
const {
import path from 'node:path';
import ora from 'ora';
import meow from 'meow';
import chalk from 'chalk';
import createConfig from './config.js';
import { upload, publish, fetchToken } from './wrapper.js';
import {
isUploadSuccess,
exitWithUploadFailure,
exitWithPublishStatus,
validateInput,
} = require('./util');
} from './util.js';

const cli = meow(`
Usage
Expand All @@ -37,10 +37,8 @@ const cli = meow(`
Publish extension (with CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN set as env variables)
$ webstore publish --extension-id elomekmlfonmdhmpmdfldcjgdoacjcba
`, {
importMeta: import.meta,
flags: {
_: {
type: 'string',
},
source: {
type: 'string',
default: process.cwd(),
Expand All @@ -50,7 +48,7 @@ const cli = meow(`

const preliminaryValidation = validateInput(cli.input, cli.flags);
if (preliminaryValidation.error) {
console.error(red(preliminaryValidation.error));
console.error(chalk.red(preliminaryValidation.error));
cli.showHelp(1);
}

Expand Down Expand Up @@ -105,7 +103,7 @@ function doUpload() {
return exitWithUploadFailure(res);
}

console.log(green('Upload Completed'));
console.log(chalk.green('Upload Completed'));
}).catch(errorHandler);
}

Expand All @@ -120,10 +118,10 @@ function doPublish() {

function errorHandler(err) {
spinner.stop();
console.error(red(err.message));
console.error(chalk.red(err.message));

if (err.response && err.response.body) {
console.error(yellow(JSON.stringify(err.response.body, null, 4)));
console.error(chalk.yellow(JSON.stringify(err.response.body, null, 4)));
}

process.exit(1);
Expand Down
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "1.2.2",
"license": "MIT",
"description": "CLI Utility to quickly upload + publish extensions to the Chrome Web Store",
"repository": "https://github.com/fregante/chrome-webstore-upload-cli",
"repository": "fregante/chrome-webstore-upload-cli",
"bin": {
"webstore": "index.js"
},
"type": "module",
"scripts": {
"test": "ava"
"test": "xo && ava"
},
"keywords": [
"chrome",
Expand All @@ -23,22 +24,21 @@
"author": "Andrew Levine",
"devDependencies": {
"ava": "^3.15.0",
"execa": "^0.4.0",
"is-stream": "^1.1.0",
"execa": "^5.1.1",
"is-stream": "^3.0.0",
"xo": "^0.44.0"
},
"dependencies": {
"chalk": "^1.1.3",
"chrome-webstore-upload": "^0.4.3",
"junk": "^1.0.2",
"meow": "^9.0.0",
"ora": "^0.2.3",
"pify": "^2.3.0",
"recursive-readdir": "^2.0.0",
"yazl": "^2.3.1"
"chalk": "^4.1.2",
"chrome-webstore-upload": "^0.5.0",
"junk": "^4.0.0",
"meow": "^10.1.1",
"ora": "^6.0.1",
"recursive-readdir": "^2.2.2",
"yazl": "^2.5.1"
},
"engines": {
"node": ">=12.17"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"contributors": [
"Andrew Levine",
Expand All @@ -59,13 +59,10 @@
],
"camelcase": "off",
"func-names": "off",
"import/extensions": "off",
"node/prefer-global/process": "off",
"promise/prefer-await-to-then": "off",
"unicorn/prevent-abbreviations": "off",
"unicorn/no-process-exit": "off",
"unicorn/import-style": "off",
"unicorn/prefer-module": "off"
"unicorn/no-process-exit": "off"
}
}
}
4 changes: 2 additions & 2 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('ava');
const execa = require('execa');
import test from 'ava';
import execa from 'execa';

function env(vars = {}) {
return {
Expand Down
4 changes: 2 additions & 2 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('ava');
const createConfig = require('../config');
import test from 'ava';
import createConfig from '../config.js';

test('Favors params over env vars', t => {
process.env.EXTENSION_ID = 123;
Expand Down
32 changes: 16 additions & 16 deletions test/helpers/stubs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module.exports = {
stubProcessExit(stub) {
const old = process.exit;
process.exit = stub;
return () => {
process.exit = old;
};
},

stubConsoleLog(stub) {
const old = console.log;
console.log = stub;
return () => {
console.log = old;
};
},
};
export function stubProcessExit(stub) {
const old = process.exit;
process.exit = stub;
return () => {
process.exit = old;
};
}

export function stubConsoleLog(stub) {
const old = console.log;
console.log = stub;
return () => {
console.log = old;
};
}

19 changes: 10 additions & 9 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const test = require('ava');
const util = require('../util');
const stubs = require('./helpers/stubs');

const { stubProcessExit, stubConsoleLog } = stubs;
import test from 'ava';
import { isUploadSuccess,
exitWithUploadFailure,
exitWithPublishStatus,
zipPath } from '../util.js';
import { stubProcessExit, stubConsoleLog } from './helpers/stubs.js';

test('isUploadSuccess', t => {
t.true(util.isUploadSuccess({
t.true(isUploadSuccess({
uploadState: 'SUCCESS',
}));
});
Expand All @@ -27,7 +28,7 @@ test('exitWithUploadFailure', t => {
}
});

util.exitWithUploadFailure({
exitWithUploadFailure({
itemError: [{
error_code: errorCode,
error_detail: errorDetail,
Expand All @@ -50,7 +51,7 @@ test('exitWithPublishStatus', t => {
}
});

util.exitWithPublishStatus({
exitWithPublishStatus({
status: [status],
});

Expand Down Expand Up @@ -82,6 +83,6 @@ test('zipPath', t => {
}];

for (const { root, file, expected } of pathMappings) {
t.is(util.zipPath(root, file), expected);
t.is(zipPath(root, file), expected);
}
});
15 changes: 7 additions & 8 deletions test/zipdir.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const test = require('ava');
const pify = require('pify');
const { ZipFile } = require('yazl');
const { readable } = require('is-stream');
const recursiveDir = require('recursive-readdir');
const zipdir = require('../zipdir');
import test from 'ava';
import recursiveDir from 'recursive-readdir';
import { ZipFile } from 'yazl';
import { isReadableStream } from 'is-stream';
import zipdir from '../zipdir.js';

function stubAddFile(stub) {
const old = ZipFile.prototype.addFile;
Expand All @@ -15,7 +14,7 @@ function stubAddFile(stub) {
}

function getExtensionFixtureFiles(name) {
return pify(recursiveDir)(`./test/fixtures/${name}`);
return recursiveDir(`./test/fixtures/${name}`);
}

test('Rejects when provided invalid dir', async t => {
Expand All @@ -29,7 +28,7 @@ test('Rejects when provided invalid dir', async t => {

test('Resolves to a readable stream', async t => {
const shouldBeStream = await zipdir('./test/fixtures/without-junk');
t.true(readable(shouldBeStream));
t.true(isReadableStream(shouldBeStream));
});

test.serial('Adds each file in dir', async t => {
Expand Down
77 changes: 38 additions & 39 deletions util.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
const { relative } = require('path');

module.exports = {
isUploadSuccess(res) {
return res.uploadState === 'SUCCESS';
},

exitWithUploadFailure(item) {
const firstError = item.itemError[0];
console.log(`Error Code: ${firstError.error_code}`);
console.log(`Details: ${firstError.error_detail}`);
process.exit(1);
},

exitWithPublishStatus(item) {
const firstStatus = item.status[0];
// TODO: Look at item stucture and determine where "detail" actually is,
// since it's clearly not the same as the line right above this
// const firstStatusDetail = item.status[0];
console.log(`Publish Status: ${firstStatus}`);
process.exit(0);
},

validateInput(input) {
if (input.length === 0) {
return { error: 'Must specify "upload" or "publish"' };
}

if (input.length > 1) {
return { error: 'Too many parameters' };
}

return { valid: true };
},

zipPath(root, file) {
return relative(root, file);
},
};
import { relative } from 'node:path';

export function isUploadSuccess(res) {
return res.uploadState === 'SUCCESS';
}

export function exitWithUploadFailure(item) {
const firstError = item.itemError[0];
console.log(`Error Code: ${firstError.error_code}`);
console.log(`Details: ${firstError.error_detail}`);
process.exit(1);
}

export function exitWithPublishStatus(item) {
const firstStatus = item.status[0];
// TODO: Look at item stucture and determine where "detail" actually is,
// since it's clearly not the same as the line right above this
// const firstStatusDetail = item.status[0];
console.log(`Publish Status: ${firstStatus}`);
process.exit(0);
}

export function validateInput(input) {
if (input.length === 0) {
return { error: 'Must specify "upload" or "publish"' };
}

if (input.length > 1) {
return { error: 'Too many parameters' };
}

return { valid: true };
}

export function zipPath(root, file) {
return relative(root, file);
}

0 comments on commit 1829794

Please sign in to comment.