Skip to content

Commit

Permalink
command line interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Metroxe committed Dec 13, 2019
1 parent 76b01fb commit 4e06c5b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "colour-chisel",
"version": "1.0.0",
"version": "0.1.0",
"bin": {
"colour-chisel": "./dist/cc.js"
},
"description": "A library for navigating the colour wheel and creating colour schemes.",
"main": "dist/index.js",
"scripts": {
"test": "ts-mocha ./test/**/* --timeout 10000",
"build": "rm -rf dist && tsc",
"deploy-demo": "npm run build --prefix ./demo && gh-pages -d ./demo/build"
"deploy-demo": "npm run build --prefix ./demo && gh-pages -d ./demo/build",
"deploy-npm": "npm publish --access public"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,5 +40,8 @@
"ts-node": "^8.4.1",
"typescript": "^3.6.3",
"gh-pages": "^2.0.1"
}
},
"files": [
"/dist"
]
}
29 changes: 29 additions & 0 deletions src/cc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node
import {readFileSync, writeFileSync} from "fs";
import ColourChisel from "./ColourChisel";
const [input, format, output] = process.argv.slice(2);

if (!input) {
throw new Error("No input file");
}

const code = readFileSync(input, 'utf8');
const colourChisel = new ColourChisel(code);
let outputCode: string;

switch (format) {
case ("js"):
outputCode = colourChisel.js({});
break;
case ("scss"):
outputCode = colourChisel.scss({});
break;
default:
throw new Error(`Invalid Format: ${format}`);
}

if (output) {
writeFileSync(output, outputCode);
} else {
console.log(outputCode);
}
Empty file added test/testFile
Empty file.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": true,
"sourceMap": false,
"declaration": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
Expand Down

0 comments on commit 4e06c5b

Please sign in to comment.