Rocket Squirrel Rocket Squirrel
Rocket Squirrel

A global community of coders, developers, and designers

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories


Constructr – when solving that one problem got out of control.

OzziePOzzieP

As always, us developers will have a task and a plethora of ways that we could go about solving it. But, being the way we are, some more NIH (Not Invented Here Syndrome) then others, we don’t want to just solve the problem, we don’t want to just hack something up to solve it, we want to solve it in the most awesome and amazing fashion possible. Maybe not everyone… But you can’t deny you’ve not been there, and that’s why I made Constructr.

What is Constructr?

Good question. Constructr is a terminal app that allows you to write commands in JavaScript and then import them into a globally accessible space.

That is essentially Constructr. Now, since you came here to find out What Constructr is, I could just wrap this up here, but what would the use in that be?

Creating a command.

Currently the only commands are create-command, and delete command.

create-command takes the command name, and the location as parameters.

Take Fetch as our example.

config.json: 

[
  {
    "Name": "fetch",
    "Description": "Fetches stuff from the web",
    "command_js": "fetch.js"
  }
]

 

Now for the fetch command.

Will be using Request to fetch some information from the IpIfy API.

API: https://api.ipify.org – so useful.

const request = require('request');
request(`http://api.ipify.org/?ip=${process.argv[2]}`, function(
  error,
  response,
  body
) {
  if (error) {
    console.log(error);
  } else {
    console.log(`Your IP is [${body}]`); 
  }
});

Not the best code, but it’s just an example*

Now we want to import the command, providing the config.json checks out, Constructr will import the command.

At the moment I’ve not finished the command to set the home directory, so the best option is to drag the file into the terminal, to get its full path. The upcoming versions will have a command to set a working directory. Will also be adding an init command for easier creation of the config file, much like yarn or NPM. But for now, I am researching code compilation into a binary, for future versions.

So, if your command file is on your Desktop, you would do.

constructr set-home Desktop

constructr create-command Fetch

Very nice and quick. This will be in 1.2.

Creating the command without the set-home command.

constructr create-command fetch /Users/ozzie/Desktop/fetch
=> fetch move [done] 
=> fetch command creation [done]

 

If moving the command failed, the command will be created, but it will be linked to the provided location: /Users/ozzie/Desktop/fetch

But obviously, if that folder is removed, the command won’t work. And will in future versions, be removed from the commands file. Or it will just be linked to a js file to return “that command is missing” or something.

 

Running the command:

constructr fetch 
=> Your IP is [86.166.64.106] 

 

to delete a command:

constructr delete-command fetch
=> fetch has been deleted. 
=> fetch is no longer accessible

 

 

That is it, I am finalising the current version, and will be updating my GitHub with this version over the next few days.

Constructr GitHub

 

Comments 0
There are currently no comments.