php.js is a resource that offers community-built JavaScript alternatives to PHP functions.
More info at: http://phpjs.org/about
$ mkdir test && cd $_
$ npm install phpjs
$ $EDITOR try.js
var php = require('phpjs');
php.echo(php.sprintf('Hey, %s : )', 'you'));
php.echo(php.parse_url('mysql://kevin:[email protected]/databasename')['pass']);
php.echo(php.strtotime('2 januari 2012, 11:12:13 GMT'));
$ node try.js
Hey, you : )
abcd1234
1325502733
make test
node bin/phpjs.js --action test --name sort
node bin/phpjs.js --action test --category array
PORT=8080 node test/browser/server.js
Point your webbrowser to http://localhost:8080
We keep the website in ./website
for so it's easy to keep docs & code in sync. For those reading this screaming murder, HashiCorp does this for all their projects, and it's working pretty well for them on a scale more impressive than ours.
Our website is built with Jekyll.
Here's the flow that takes written functions to the website:
npm run website:inject
runslib/cli.js
'sinjectweb
methodinjectweb
iterates over./functions
and useslib/phpjsutil.js
to parse them, most significantly: the header comments that declare authors, tests, and dependenciesinjectweb
then writes each function towebsite/_functions
. This is a Jekyll Collection. The code is written as the content, and all the other properties are added as YAML front matter- Jekyll uses
website/_layouts/function.html
as the layout template for the function collection, this determines how all the properties are rendered.
Blog posts can be found in website/_posts
.
At the time of writing, the Jekyll Asset pipeline is in a bad place, and so SASS / ES6 asset transpiling is handled separately via npm scripts. Unfortunately we don't have the theme of the website in SASS, so it's included in app.scss
as plain CSS for now. You can find all the transpiling options in website/package.json
.
Typing npm run website:deploy
in the root of the project takes care of all the building steps above, and then force pushes the generated HTML to the gh-pages
branch of this repo.
- Split out the npm module so you could do
var sprintf = require('phpjs/sprintf')
- Auto-deploys via Travis CI