This repository has been archived by the owner on Jan 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add functionality to use as a CLI application
Add dependencies and update configuration to act as a CLI app.
- Loading branch information
1 parent
aa2330a
commit 0868dbd
Showing
15 changed files
with
585 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,4 @@ typings/ | |
/data/*.json | ||
/config/default.json | ||
lib/ | ||
t2c.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.