Permalink
Browse files

Fakefile

  • Loading branch information...
1 parent c5839e8 commit d33a5d77d2ece80da451575ce26f0e36885d6188 @kvz committed Apr 1, 2016
Showing with 109 additions and 120 deletions.
  1. +40 −101 Makefile
  2. +46 −13 bin/phpjs.js → lib/cli.js
  3. +23 −6 package.json
View
@@ -1,101 +1,40 @@
-SHELL := /bin/bash
-
-.PHONY: setup
-setup:
- git pull && \
- cd _octopress && \
- bundle exec rake setup_github_pages\[git@github.com:kvz/phpjs.git\] && \
- cd .. ; \
-
-.PHONY: test
-test:
- ulimit -n 1024 ||true
- npm install
- make build
- ./node_modules/.bin/mocha --reporter list
- node bin/phpjs.js --action test --debug
-
-# Apply code standards & reformat headers
-.PHONY: cleanup
-cleanup:
- node bin/phpjs.js --action cleanup
- npm run fix || true
- @$(MAKE) test
-
-.PHONY: serve
-serve:
- python -m SimpleHTTPServer
-
-.PHONY: upgrade-npm-dependencies
-upgrade-npm-dependencies:
- @npm install
- @./node_modules/.bin/npm-check-updates --upgrade
- @npm install
- @$(MAKE) test
- @git add ./package.json
- @git commit -m'Upgrade NPM dependencies'
- @git pull && git push
-
-.PHONY: test-cleanup
-test-cleanup:
- node bin/phpjs.js --action cleanup --name array_change_key_case
- node bin/phpjs.js --action cleanup --name echo
- git diff functions/array/array_change_key_case.js
- git diff functions/strings/echo.js
- git checkout -- functions/array/array_change_key_case.js
- git checkout -- functions/strings/echo.js
-
-.PHONY: npm
-npm:
- node bin/phpjs.js --action buildnpm --output build/npm.js
- ls -al build/npm.js
- node build/npm.js
- node test/npm/npm.js
- echo "Build success. "
-
-.PHONY: publish
-publish: npm
- npm publish
-
-.PHONY: build
-build: npm
-
-.PHONY: hook
-hook:
- mkdir -p ~/.gittemplate/hooks
- curl https://raw.github.com/kvz/ochtra/master/pre-commit -o ~/.gittemplate/hooks/pre-commit
- chmod u+x ~/.gittemplate/hooks/pre-commit
- git config --global init.templatedir '~/.gittemplate'
- rm .git/hooks/pre-commit || true
- git init
-
-.PHONY: site
-site:
- git pull && \
- cd _octopress && \
- bundle install --path vendor/bundle && \
- npm install && \
- bundle exec rake integrate && \
- bundle exec rake build && \
- bundle exec rake generate && \
- bundle exec rake deploy ; \
- cd .. ; \
- git add --all . ; \
- git commit -anm "Update site" ; \
- git push origin master
-
-.PHONY: site-clean
-site-clean:
- cd _octopress && \
- git clean -fd ; \
- git reset --hard ; \
- bundle exec rake clean ; \
- cd ..
-
-.PHONY: site-preview
-site-preview:
- cd _octopress && \
- bundle exec rake build && \
- bundle exec rake generate && \
- bundle exec rake preview ; \
- cd ..
+# Licensed under MIT.
+# Copyright (2016) by Kevin van Zonneveld https://twitter.com/kvz
+#
+# https://www.npmjs.com/package/fakefile
+#
+# This Makefile offers convience shortcuts into any Node.js project that utilizes npm scripts.
+# It functions as a wrapper around the actual listed in `package.json`
+# So instead of typing:
+#
+# $ npm script build:assets
+#
+# you could also type:
+#
+# $ make build-assets
+#
+# Notice that colons (:) are replaced by dashes for Makefile compatibility.
+#
+# The benefits of this wrapper are:
+#
+# - You get to keep the the scripts package.json, which is more portable
+# (Makefiles & Windows are harder to mix)
+# - Offer a polite way into the project for developers coming from different
+# languages (npm scripts is obviously very Node centric)
+# - Profit from better autocomplete (make <TAB><TAB>) than npm currently offers.
+# OSX users will have to install bash-completion
+# (http://davidalger.com/development/bash-completion-on-os-x-with-brew/)
+
+define npm_script_targets
+TARGETS := $(shell node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}')
+$$(TARGETS):
+ npm run $(subst -,:,$(MAKECMDGOALS))
+
+.PHONY: $$(TARGETS)
+endef
+
+$(eval $(call npm_script_targets))
+
+# These npm run scripts are available, without needing to be mentioned in `package.json`
+install:
+ npm run install
@@ -1,14 +1,15 @@
#!/usr/bin/env node
-
var cli = require('cli').enable('status', 'help', 'version', 'glob', 'timeout')
var fs = require('fs')
var glob = require('glob')
var path = require('path')
+var mkdirp = require('mkdirp')
var _ = require('underscore')
-var phpjsutil = new require('../lib/phpjsutil')
+var PhpjsUtil = require('./phpjsutil')
var equal = require('deep-equal')
-var __root = __dirname + '/..'
+var __root = path.join(__dirname, '..')
var beautify = require('js-beautify').js_beautify
+var YAML = require('js-yaml')
// Not ideal: http://stackoverflow.com/questions/8083410/how-to-set-default-timezone-in-node-js
process.env.TZ = 'UTC'
@@ -22,7 +23,7 @@ cli.parse({
abort : ['a', 'Abort on first failure']
})
-var PhpjsUtil = phpjsutil({
+var phpjsUtil = new PhpjsUtil({
injectDependencies: ['ini_set', 'ini_get'],
equal : equal,
debug : cli.debug,
@@ -44,7 +45,7 @@ var PhpjsUtil = phpjsutil({
// Environment-specific file opener. function name needs to
// be translated to code. The difficulty is in finding the
// category.
-PhpjsUtil.opener = function (name, cb) {
+phpjsUtil.opener = function (name, cb) {
var pattern = __root + '/functions/*/' + name + '.js'
glob(pattern, {}, function (err, files) {
if (err) {
@@ -178,8 +179,8 @@ cli.buildnpm = function (args, options) {
fs.appendFileSync(options.output, '// Make function changes in ./functions and \n')
fs.appendFileSync(options.output, '// generator changes in ./lib/phpjsutil.js \n')
- for (var global in PhpjsUtil.globals) {
- fs.appendFileSync(options.output, 'exports.' + global + ' = ' + PhpjsUtil.globals[global] + ';\n')
+ for (var global in phpjsUtil.globals) {
+ fs.appendFileSync(options.output, 'exports.' + global + ' = ' + phpjsUtil.globals[global] + ';\n')
}
fs.appendFileSync(options.output, 'exports.window.window = exports.window;\n')
@@ -189,14 +190,46 @@ cli.buildnpm = function (args, options) {
}
var buf = '\n'
buf += 'exports.' + params.func_name + ' = function (' + params.func_arguments.join(', ') + ') {\n'
- buf += ' ' + params.body.split('\n').join('\n ').replace(/^ $/g, '') + '\n'
+ buf += ' ' + params.body.split('\n').join('\n ').replace(/^ {2}$/g, '') + '\n'
buf += '};\n'
fs.appendFileSync(options.output, buf)
})
}
-cli.glob = function (pattern, cb) {
+cli.injectweb = function (args, options) {
+ console.dir({args: args, options: options})
+
+ var self = this
+ var funcPath = options.category + '/' + options.name
+ var webfuncPath = __root + '/website/' + funcPath + '.md'
+ var pattern = __root + '/functions/' + funcPath + '.js'
+
+ self.glob(pattern, function (err, params, file) {
+ if (err) {
+ return self.error('Could not glob for ' + pattern + '. ' + err)
+ }
+ var data = {
+ redirect_from: [ '/functions/' + params.func_name + '/' ]
+ }
+ var buf = '---' + '\n' + YAML.safeDump(data) + '\n' + '---' + '\n'
+ buf += '{% highlight javascript %}'
+ buf += file
+ buf += '{% endhighlight %}'
+
+ mkdirp(path.dirname(webfuncPath), function (err) {
+ if (err) {
+ return self.error('Could not mkdir for ' + webfuncPath + '. ' + err)
+ }
+ fs.writeFileSync(webfuncPath, buf)
+ })
+ })
+}
+
+cli.glob = function (pattern, workerCb) {
glob(pattern, {}, function (err, files) {
+ if (err) {
+ return workerCb(err)
+ }
var names = []
var map = {}
for (var i in files) {
@@ -208,12 +241,12 @@ cli.glob = function (pattern, cb) {
}
}
names.forEach(function (name) {
- PhpjsUtil.load(name, function (err, params) {
+ phpjsUtil.load(name, function (err, params) {
if (err) {
- return cb(err)
+ return workerCb(err)
}
- return cb(null, params, map[name])
+ return workerCb(null, params, map[name])
})
})
})
@@ -248,7 +281,7 @@ cli.test = function (args, options) {
return cli.info('--> ' + params.name + ' skipped as instructed. ')
}
- PhpjsUtil.test(params, function (err, test, params) {
+ phpjsUtil.test(params, function (err, test, params) {
var testName = params.name + '#' + (+(test.number * 1) + 1)
if (!err) {
self.pass_cnt++
View
@@ -6,7 +6,7 @@
"homepage": "http://phpjs.org",
"author": "Kevin van Zonneveld <kevin@vanzonneveld.net>",
"engines": {
- "node": ">= 0.8.0"
+ "node": ">= 0.10.0"
},
"devDependencies": {
"cli": "0.11.2",
@@ -36,10 +36,27 @@
},
"readmeFilename": "README.md",
"scripts": {
- "test": "make test",
- "fix": "eslint functions bin lib test tools --fix",
- "website:start": "cd website && npm run start",
- "lint": "eslint functions"
+ "build": "npm run build:npm",
+ "build:npm": "node lib/cli.js --action buildnpm --output build/npm.js && ls -al build/npm.js",
+ "fix": "node lib/cli.js --action cleanup && eslint functions bin lib test tools --fix",
+ "lint": "eslint functions",
+ "release:major": "env SEMANTIC=major npm run release",
+ "release:minor": "env SEMANTIC=minor npm run release",
+ "release:patch": "env SEMANTIC=patch npm run release",
+ "release": "git commit CHANGELOG.md -m 'Update CHANGELOG.md' && npm version ${SEMANTIC:-patch} -m \"Release %s\" && npm run version:replace && git commit test/fixture/*.stdio -m 'Update version' && git push --tags && git push && npm publish",
+ "test": "npm run test:utils && npm run test:functions && npm run test:module",
+ "test:utils": "mocha --reporter spec",
+ "test:functions": "node lib/cli.js --action test --debug",
+ "test:module": "node build/npm.js && node test/npm/npm.js",
+ "website:inject": "node lib/cli.js --action injectweb",
+ "website:start": "cd website && npm run start"
},
- "bin": "bin/phpjs.js"
+ "bin": {
+ "node lib/cli.js": "lib/cli.js"
+ },
+ "dependencies": {
+ "fakefile": "0.0.8",
+ "js-yaml": "3.5.5",
+ "mkdirp": "0.5.1"
+ }
}

0 comments on commit d33a5d7

Please sign in to comment.