codepusher v0.1.0
codepusher CLI
A CLI tool for creating and publishing challenges to codepusher.io.
Key Features
- init: initialise a repository for storing all your codepusher challenges.
- create: create a new codepusher challenge.
- publish: publish your changes to codepusher.io.
Install
From your command line:
# install codepusher cli
$ npm install -g codepusher
# see available commands and options
$ codepusher --help
Init
To initialise a repository for storing codepusher challenges run the following command:
$ codepusher init
Follow the prompts to generate a codepusher.json
file which will be used as configuration in subsequent publishing steps.
codepusher.json
fields
name: Set a name that can be used for searching. e.g. codepusher top algorithm challenges
visibility: This can be set to either
public
orprivate
.public: Challenges can be searchable and accessed by any user.
private: Challenges cannot be searchable and are only accessible by users in your private sessions.
dir: The directory for storing codepusher challenges. This is relative to your current working directory.
Create
A new codepusher challenge can be created using the following command:
$ codepusher create --challenge <name>
Note: name arguments should be given in either camel case (fooBar
), snake case (foo_bar
) or kebab case (foo-bar
) and will be converted to start case (Foo Bar
) at publish time.
All challenges will have the following file structure:
./<name>
|
+-- README.md
|
+-- tests.json
README.md
The content of this file will be rendered to markdown view and displayed in the README
tab on codepusher.io during a session.
tests.json
This file is used to validate a pass or fail case. It's structure is an array
with each item being an object
that has both an input
field and an output
field.
For example:
[
{ "input": 1, "output": 2 },
{ "input": 2, "output": 3 },
{ "input": 3, "output": 4 }
]
Both input
and output
fields can be either a string
, number
, object
, or array
. During a session, when code is pushed, the input
value is made available on a global context
object. The result from the script is then compared against the corresponding output
field to determine a pass or fail case.
For example, to solve the above test cases we could have the following solution:
const incrementByOne = ({ input }) => {
return input + 1;
};
incrementByOne(context);
Publish
Your codepusher repository can be published using the following command:
$ codepusher publish --token <value>
You can generate a unique token for your account through the settings page on codepusher.io. This token should be treated as a secret key and not committed into any git or other version control repositories.
Note: Currently each repository is limited to a maximum of 245 challenges.