Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
feat(project): full rewrite
Browse files Browse the repository at this point in the history
Improve string parsing, now requires id for project, labels and sections(BREAKING)
Searching of
tasks by section and setting of sections to tasks now possible
Fix update error #128 (bug)
Set time
to next update check (settings)
Optionally receive pre-releases of this workflow
Show task title in
notification when created #126
Set cache timeout for tasks
Allow filtering tasks by project, label,
priority and section #20
Improved error handling and feedback, easily fill out a bug report when an
unexpected error is encountered
Show more helpful errors when a call to the Todoist API fails
#124
Improved typing and code documentation for contributors

BREAKING CHANGE:
Improve string parsing, now requires id for project, labels and sections

ISSUES CLOSED: #128 #126 #124 #20
  • Loading branch information
moranje committed Feb 5, 2020
1 parent 67bb47a commit 2849c8a
Show file tree
Hide file tree
Showing 70 changed files with 24,842 additions and 699 deletions.
18,537 changes: 18,537 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

64 changes: 31 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,22 @@
}
},
"dependencies": {
"@types/fuzzy-search": "2.1.0",
"ajv": "6.10.2",
"babel-polyfill": "6.26.0",
"cache-conf": "0.6.0",
"@sentry/node": "^5.12.3",
"chalk": "^3.0.0",
"clean-stack": "2.2.0",
"compare-versions": "^3.5.1",
"conf": "6.2.0",
"date-fns": "2.8.1",
"fast-plist": "0.1.2",
"fuzzy-search": "3.0.2",
"got": "10.0.1",
"lodash.find": "4.6.0",
"lodash.omit": "4.5.0",
"lodash.remove": "4.7.0",
"lodash.unionby": "4.8.0",
"loud-rejection": "2.2.0",
"lru-cache": "5.1.1",
"date-fns": "2.9.0",
"deep-equal": "^2.0.1",
"fuzzy-search": "3.1.0",
"got": "10.4.0",
"macos-version": "5.2.0",
"md5": "2.2.1",
"mkdirp": "0.5.1",
"moo": "0.5.1",
"nearley": "2.19.0",
"node-notifier": "5.4.0",
"stampit": "4.3.0",
"todoist-rest-api": "1.2.5",
"nearley": "2.19.1",
"new-github-issue-url": "^0.2.1",
"open": "^7.0.2",
"todoist-rest-api": "1.3.2",
"write-json-file": "4.2.1"
},
"devDependencies": {
Expand All @@ -82,38 +75,42 @@
"@babel/plugin-syntax-top-level-await": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/preset-typescript": "^7.8.3",
"@eclass/semantic-release-sentry-releases": "^1.0.0",
"@rollup/plugin-commonjs": "^11.0.1",
"@rollup/plugin-json": "^4.0.1",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-replace": "^2.3.0",
"@eclass/semantic-release-sentry-releases": "^2.0.0",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-json": "^4.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",
"@semantic-release/changelog": "5.0.0",
"@semantic-release/exec": "5.0.0",
"@semantic-release/git": "9.0.0",
"@types/chance": "^1.0.8",
"@types/conf": "3.0.0",
"@types/deep-equal": "^1.0.1",
"@types/fuzzy-search": "2.1.0",
"@types/inquirer": "6.5.0",
"@types/jest": "25.1.1",
"@types/md5": "2.1.33",
"@types/mkdirp": "0.5.2",
"@types/moo": "0.5.1",
"@types/nearley": "2.11.0",
"@types/nearley": "2.11.1",
"@types/new-github-issue-url": "^0.2.1",
"@types/nock": "11.1.0",
"@types/node": "13.5.3",
"@types/node": "13.7.0",
"@types/shelljs": "0.8.6",
"@types/write-json-file": "3.2.1",
"@typescript-eslint/eslint-plugin": "2.18.0",
"@typescript-eslint/parser": "2.18.0",
"@typescript-eslint/eslint-plugin": "2.19.0",
"@typescript-eslint/parser": "2.19.0",
"@wessberg/rollup-plugin-ts": "^1.2.15",
"babel-jest": "^25.1.0",
"bestzip": "2.1.5",
"chance": "^1.1.4",
"colors": "1.4.0",
"coveralls": "3.0.9",
"cz-customizable": "6.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "6.10.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-jsdoc": "^21.0.0",
"eslint-plugin-node": "^11.0.0",
Expand All @@ -123,17 +120,18 @@
"husky": "4.2.1",
"inquirer": "7.0.4",
"jest": "25.1.0",
"jest-mock-process": "^1.3.0",
"lint-staged": "10.0.6",
"jest-mock-process": "^1.3.2",
"json-schema-typed": "^7.0.3",
"lint-staged": "10.0.7",
"mkdirp": "1.0.3",
"nock": "11.7.2",
"prettier": "1.19.1",
"rollup": "1.30.1",
"rollup": "1.31.0",
"rollup-plugin-filesize": "^6.2.1",
"rollup-plugin-node-externals": "^2.1.3",
"rollup-plugin-sourcemaps": "^0.5.0",
"rollup-plugin-terser": "^5.2.0",
"semantic-release": "17.0.1",
"semantic-release": "17.0.2",
"shelljs": "0.8.3",
"ts-node": "8.6.2",
"tslib": "1.10.0",
Expand Down
110 changes: 29 additions & 81 deletions src/alfred-workflow-todoist.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,37 @@
import '@babel/polyfill';
import 'loud-rejection/register';
import {
AlfredError,
cache,
Command,
getSetting,
handleError,
serialize,
} from '@/project';
/* eslint simple-import-sort/sort: 0 */
import compareVersions from 'compare-versions';

/**
* CLI argument parsing
*/

/** @hidden */
const argv = Object.assign([], process.argv);
argv.splice(0, 2);
/** @hidden */
const type = argv.shift();
/** @hidden */
const query = argv.join(' ');
/** @hidden */
const command = Command();
import { getCurrentCall } from '@/lib/cli-args';
import command from '@/lib/command';
import { AlfredError, Errors, funnelError } from '@/lib/error';
import { checkForWorkflowUpdate } from '@/lib/updater';
import { ENV } from '@/lib/utils';

/**
* Serialize cache back to JSON
*
* @hidden
* Make sure minimum node version is satisfied.
*/
function handleSerialization(): Promise<void> {
return serialize(cache.dump()).catch(handleError);
}
if (compareVersions.compare(process.version, ENV.requirements.nodejs, '>=')) {
(async (): Promise<void | null> => {
const call = getCurrentCall();

/**
* Updater
*/
try {
command.updateWorkflowVersion();
} catch (error) {
handleError(error);
}
/**
* Updater.
*/
if (call.name === 'parse' || call.name === 'read') {
await checkForWorkflowUpdate();
}

/**
* CLI option logic
*/
if (type === 'read') {
command
.read(query)
.catch(handleError)
.finally(handleSerialization);
} else if (type === 'create') {
try {
command.create(query);
} catch (error) {
handleError(error);
} finally {
handleSerialization();
}
} else if (type === 'submit') {
command
.submit(
Object.assign(JSON.parse(query), { due_lang: getSetting('language') })
)
.catch(handleError)
.finally(handleSerialization);
} else if (type === 'remove') {
command
.remove(JSON.parse(query))
.catch(handleError)
.finally(handleSerialization);
} else if (type === 'settings' && query.trim() !== '') {
const [key, value] = query.trim().split(' ');
command.verifySetting(key, value);
} else if (type === 'settings') {
command.listSettings();
} else if (type === 'settings:store') {
command.saveSetting(JSON.parse(query)).catch(handleError);
/**
* Command distribution.
*/
return command(call);
})().catch(funnelError);
} else {
handleError(new AlfredError(`Invalid command ${type} (${query})`));
funnelError(
new AlfredError(
Errors.InvalidNodeJS,
'Please upgrade your Node.js version to 10.x or higher for this workflow to work',
{ isSafe: true }
)
);
}

/**
* Catch any unhandled exception or rejected promise and handle here
*/

process.on('uncaughtException', handleError);
// Process.on('unhandledRejection', handleError)
(process as NodeJS.EventEmitter).on('unhandledRejection', handleError);
3 changes: 0 additions & 3 deletions src/lib/cache.ts

This file was deleted.

109 changes: 109 additions & 0 deletions src/lib/cli-args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { TodoistTask, TodoistTaskOptions } from 'todoist-rest-api';
import { isPrimitive } from 'util';

import { Settings } from '@/lib/stores/settings-store';

import { ResourceName } from './todoist/local-rest-adapter';

type Arg =
| string
| TodoistTaskOptions
| TodoistTask
| {
key: string;
value: string | number | boolean;
};

export type Call =
| {
name: 'parse' | 'read' | 'readSettings' | 'openUrl';
args: string;
}
| {
name: 'create';
args: TodoistTaskOptions;
}
| {
name: 'remove';
args: TodoistTask;
}
| {
name: 'writeSetting';
args: {
key: keyof Settings;
value: string | number | boolean;
};
}
| {
name: 'refreshCache';
args: ResourceName;
};

const argv: string[] = Object.assign([], process.argv);
argv.splice(0, 2);

function assertValidArgs(args: Arg): asserts args is Arg {
if (args == null) {
throw new TypeError(
`Property args should not be null or undefined, was ${args}`
);
}
}

function assertValidCall(call: Call): asserts call is Call {
if (!call || isPrimitive(call)) {
throw new TypeError(`The call should be a an object, was ${call}`);
}

if (!call.name || typeof call.name !== 'string') {
throw new TypeError(
`Expected call.name to be a string was ${call.name} (${typeof call.name})`
);
}

assertValidArgs(call.args);
}

function serialize(call: Call): string | never {
assertValidCall(call);

return JSON.stringify(call);
}

function deserialize(serialized: string): Call | never {
if (typeof serialized !== 'string') {
throw new TypeError(
`Expected a string in deserialize, got ${serialized} (${typeof serialized})`
);
}

try {
const call = JSON.parse(serialized) as Call;
assertValidCall(call);

return call;
} catch (error) {
throw new TypeError(
`Expected a JSON string, got '${serialized}' (${typeof serialized})`
);
}
}

/**
* Retrieves the call passed to current alfred input or action.
*
* @returns A `Call` object.
*/
export function getCurrentCall(): Call {
return deserialize(argv.join(' '));
}

/**
* Validates and creates a serialized call.
*
* @param call A `Call` object.
* @returns A serialized call.
*/
export function createCall(call: Call): string {
return serialize(call);
}
Loading

0 comments on commit 2849c8a

Please sign in to comment.