Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Commit

Permalink
feat: add functionality to use as a CLI application
Browse files Browse the repository at this point in the history
Add dependencies and update configuration to act as a CLI app.
  • Loading branch information
mikerourke committed Oct 18, 2018
1 parent aa2330a commit 0868dbd
Show file tree
Hide file tree
Showing 15 changed files with 585 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ typings/
/data/*.json
/config/default.json
lib/
t2c.json
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Toggle to Clockify

Tool to load Toggl data into Clockify.
CLI tool to load Toggl data into Clockify.

**THIS IS A WORK IN PROGRESS AND MAY CAUSE A RUCKUS. DO NOT USE IF YOU HAVE A LOT OF EXISTING CLOCKIFY DATA!**

## Installation
- Install globally with `npm install -g toggl-to-clockify` or `yarn global add toggl-to-clockify`

## Prerequisites
- Toggl API key
- Clockify API key

## Instructions
1. Install required dependencies by running `yarn install`
2. Create a copy of the `default.example.json` file in the `/config` directory named `default.json` (also in `/config`) directory
3. Populate the `email` and `apiToken` fields for `toggl` and the `apiToken` field for `clockify`
4. For the `workspaces` field, specify an array of objects that match this format:
1. Run the command `toggl-to-clockify init` with an optional output path using the `-o` flag to generate a configuration file
2. Populate the `email`, `togglApiToken`, `clockifyApiToken` fields
3. For the `workspaces` field, specify an array of objects that match this format:
```json
{
"name": "<Toggl Workspace Name>",
Expand All @@ -24,14 +26,14 @@ Tool to load Toggl data into Clockify.
```
The `name` is the name of the Workspace from Toggl you wish to copy, the `years` is an array of years to include in the transfer

5. Before initializing the transfer, you **must** create the workspaces on Clockify with the same name as Toggl (you can always change them later)

4. Before initializing the transfer, you **must** create the workspaces on Clockify with the same name as Toggl (you can always change them later)
5. Run the command `toggl-to-clockify transfer` to perform the transfer

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

## Todo

- [ ] Publish to NPM
- [ ] Add comments to code
- [ ] Add tests
11 changes: 11 additions & 0 deletions bin/toggl-to-clockify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
const yargs = require('yargs');

const argv = yargs
.usage('Usage: toggl-to-clockify <command> [options]')
.commandDir('../lib/cmds')
.help()
.alias('help', 'h')
.version(false)
.wrap(Math.min(100, yargs.terminalWidth()))
.argv;
25 changes: 0 additions & 25 deletions config/default.example.json

This file was deleted.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@
"precompile": "rimraf ./lib",
"compile": "tsc",
"lint": "tslint -c tslint.json \"src/**/*.ts\"",
"prettier": "prettier --write \"src/**/*.ts\"",
"transfer": "ts-node --project tsconfig.json src/index.ts"
"prettier": "prettier --write \"src/**/*.ts\""
},
"bin": {
"toggl-to-clockify": "./bin/toggl-to-clockify.js"
},
"files": [
"bin",
"config",
"data",
"lib"
],
"dependencies": {
"chalk": "^2.4.1",
"date-fns": "^1.29.0",
"jsonfile": "^5.0.0",
"lodash": "^4.17.11",
"node-fetch": "^2.2.0"
"node-fetch": "^2.2.0",
"yargs": "^12.0.2"
},
"devDependencies": {
"@types/config": "^0.0.34",
"@types/lodash": "^4.14.116",
"@types/node": "^10.9.4",
"@types/node-fetch": "^2.1.2",
"config": "^2.0.1",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"ts-node": "^7.0.1",
Expand Down
46 changes: 46 additions & 0 deletions src/cmds/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import chalk from 'chalk';
import Config from '../utils/Config';
import JsonFile from '../utils/JsonFile';

export const command = 'init';
export const alias = 'i';
export const desc =
'Creates configuration file for specifying API keys and workspaces';

export const builder = yargs => {
yargs
.options({
output: {
alias: 'o',
describe:
'Output path for the configuration file. If not specified, defaults to working directory',
},
})
.help()
.alias('help', 'h');
};

interface Parameters {
output?: string;
}

export const handler = (parameters: Parameters) => {
const { output } = parameters;

const outputPath = JsonFile.validatePath('t2c', output);
if (outputPath === null) {
console.log(
chalk.red('You must specify a JSON file name for the output path'),
);
process.exit();
return;
}

Config.generateFile(outputPath)
.then(() => {
console.log(chalk.green('Config file successfully created'));
})
.catch(error => {
console.log(chalk.red(`Error creating file: ${error.message}`));
});
};
66 changes: 66 additions & 0 deletions src/cmds/write.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import chalk from 'chalk';
import Config from '../utils/Config';
import Clockify from '../tools/Clockify';
import Toggl from '../tools/Toggl';
import JsonFile from '../utils/JsonFile';
import { ToolName } from '../types/common';

export const command = 'write';
export const alias = 'w';
export const desc = 'Fetches data from API and writes a to JSON file';

export const builder = yargs => {
yargs
.options({
source: {
alias: 's',
describe: 'Source of data',
choices: Object.values(ToolName),
demandOption: true,
},
output: {
alias: 'o',
describe:
'Output path for the JSON file. If not specified, defaults to working directory',
},
config: {
alias: 'c',
describe:
'Path to configuration file. Defaults to searching for "t2c.json" in working directory',
},
})
.help()
.alias('help', 'h');
};

interface Parameters {
source: ToolName;
config?: string;
output?: string;
}

export const handler = (parameters: Parameters) => {
const { source, output, config } = parameters;
const configFilePath = Config.validateFilePath(config);
if (configFilePath === null) {
console.log(chalk.red('You must specify a valid config file path'));
process.exit();
return;
}

const outputPath = JsonFile.validatePath(source, output);
if (outputPath === null) {
console.log(
chalk.red('You must specify a JSON file name for the output path'),
);
process.exit();
return;
}

const entity = {
[ToolName.Clockify]: new Clockify(configFilePath),
[ToolName.Toggl]: new Toggl(configFilePath),
}[source];

entity.writeDataToJson(outputPath);
};
36 changes: 0 additions & 36 deletions src/index.ts

This file was deleted.

Loading

0 comments on commit 0868dbd

Please sign in to comment.