WesyerJS is a NodeJS tool that permit you to automatize all of your tasks. It permits to perform operations on files and write the result in other files.
To install WesyerJS, you first need to install the NodeJS Package Manager (npm).
Then, type the following command in your terminal :
npm install wesyer-js -g
NOTE : The -g argument installs WesyerJS globally. This permits to use WesyerJS everywhere and access to the 'wy' command.
All of these commands needs to have installed WesyerJS globally with -g argument
WesyerJS works only on projects. To create a project, use the following command :
wy init my-project
cd my-project
NOTE : Replace my-project by your project's name
You will be asked about informations :
Property | Optionnal | What is it ? |
---|---|---|
description | true | The description of your project |
author | true | The author of the project |
license | true | The license of the project |
verbose | false | Choose if WesyerJS has to say you all about errors (development) |
server port | false | If you choose to create a local server to test your pages, the port to use |
root file | false | The file to deliver to the client when he asks for the root page (/) |
encoding | false | The encoding of all files in your project |
server encoding | false | The file encoding for the server's pages |
server verbose | false | Make the server verbose |
NOTE : Hold Return
(or Entrée
) key will set the default value to the asked property (this value is written in green)
If you perform a ls -a
on this new directory, you can see that one folder and one file has been created.
First, the folder .wesyer
contains files required by WesyerJS to works. Don't touch to this folder !!!
There is also a taskfile.js
file, which contains the following content :
// Wesyer task file
var config = {
"description": "",
"author": "",
"license": "Apache 2.0",
"modules": {
"repository": "https://wesyerjs.olympe.in/modules"
},
"verbose": "false",
"server": {
"port": 8080,
"rootFile": [
"index.html"
],
"encoding": "utf-8",
"templates": {},
"verbose": "false",
"mime-types": {}
}
};
To use WesyerJS, you need to create a task.
For that, open the taskfile.js
file in your favorite code editor, and add the following content at the end of the file :
Wesyer.task('default', function() {
console.log('This task works great !');
});
And type in your terminal :
wy
If you see a message This task works great !
in your console, then all works great !
We have created a task by using Wesyer.task()
function. This function requires two parameters : the name of the task, and the callback.
To run a task, you have to type wy <taskname>
in your terminal. But if you don't type a task name, the default task will be runned.
Now, we will use modules. But first, you need to download one :
wy install test-module
If it exists on the server, it will be downloaded.
NOTE : If you want to use an other server, change the URL in config['modules']['repository']
When you download a module, the final URL is <server-url>/<module-name>/archive.zip
(example : https://wesyerjs.olympe.in/modules/test-module/archive.zip
)
The module will be downloaded as a ZIP archive in .wesyer/archive.zip
and will be extracted in folder .wesyer/<module-name>
.
WARNING : Do NOT download two modules at the same time ! This can corrupt project directory or do dangerous things !
The test-module
module is now downloaded on the .wesyer
folder !
I've said at the beginning that WesyerJS works on files. Now, I say that modules permit to works on these files. And we'll test that.
In fact, the module we've downloaded permit to replace the __FILE__
text on all files by the file path.
First, create a folder src
and a folder out
in your project directory.
Create into a file named test.txt
in the src
folder, with the following content :
The relative path of this file is : __FILE__
Save it.
Then, edit the default
task (in taskfile.js
) and replace it content with this :
Wesyer.task('default', function() {
Wesyer
.for('src/*')
.pipe('test-module')
.out('out/', {root: true})
});
To work on files, you need to say it to WesyerJS. The for
command permits to select files.
The pipe
command permits to pass the file to a module (here, the module we've downloaded before).
And the out
command permits to write the result of the work in a directory.
This last function is a little bit complicated than others :
- We've choosed to works on all files in the
src
folder - We've piped them with the
test-module
module - We want to write these files on the
out
folder
If you don't pass the {root: true}
object to the command, WesyerJS will try to write our test.txt
file on this path : out/src/test.txt
The {root: true}
argument say to WesyerJS "Write these files at the root of the output directory !"
So our file will be to out/test.txt
Now, run the task by running wy
in your terminal.
If you see a file named test.txt
appear in the out
folder, then all works great ;-) !
Open this new file. The content is now :
The relative path of this file is : src/test.txt
Enjoy !
You perhaps want to do other things that replace __FILE__
by a path in all of your files !
So, let's see how to create a new module. Our module will replace the author
by ME
in all files (that's for the example)
First, use the following command :
cd ..
wy create-module my-module
cd my-module
NOTE : I don't describe it the asked properties of the module because they are very simples.
Open the package.json
file. It contains the following content :
{
"files": [
"index.js"
],
"name": "my-module",
"description": "A simple test module for the WesyerJS tutorial",
"author": "Clément Nerma",
"main": "index.js",
"license": "Apache 2.0",
"version": "0.1.0"
}
The files
field contains all files that your module will use.
The main
field indicates what is the main file of your module.
Now, open the index.js
file. It is empty. But we will write it ;-) !
You can check out the WesyerJS API to learn what you can do on files (see the Wesyer.Files
section)
So, let's code ! Write the following content in index.js
:
return input.apply(function(content) {
return content.replace(/the author/g, 'ME');
});
Simple, isn't ?
input
is an instance of Wesyer.File
that represents the input file (such as src/my-test-file.txt
).
This is always a single file.
The apply
function permits to get the content of the file and perform operations on. We've replaced all the author
by me
in this content, and we've returned it.
The returned content will in fact overwrite the old file content.
Our module is now ready to be used in a project !
Now, let's see how to build it. Type in your terminal :
wy build-module
This will create a ZIP file that contains your module. All files contained in this ZIP are in the files
field in package.json
, and this last file has been added to the group !
Now, return to your project
cd ../my-project
And install our new module :
wy install my-module --local ../my-module/my-module.zip
A my-module
folder will be created in the .wesyer
directory. That's all !
You can now use the my-module
module in your tasks !
This project is under the GNU GPL license terms.
Let's see the wiki ! You can find it at https://github.com/ClementNerma/WesyerJS/wiki
The software is provided "as is" and the author disclaims all warranties with regard to this software including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, direct, indirect, or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software.