Skip to content

Commit

Permalink
build with urequire (eat your own dogfood). Allows importing of stand…
Browse files Browse the repository at this point in the history
…ard modules (lodash, uberscore, UError) & use specrunner to autogen specs.
  • Loading branch information
anodynos committed Nov 15, 2014
1 parent e2a0ede commit 5c7703e
Show file tree
Hide file tree
Showing 45 changed files with 63 additions and 303 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ node_js:

before_script:
- npm install -g grunt-cli
- npm install -g coffee-script
- grunt build
- npm install -g mocha
131 changes: 49 additions & 82 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -1,88 +1,55 @@
_ = (_B = require 'uberscore')._
S = if process.platform is 'win32' then '\\' else '/'
startsWith = (string, substring) -> string.lastIndexOf(substring, 0) is 0
nodeBin = "node_modules#{S}.bin#{S}"

sourceDir = "source/code"
buildDir = "build/code"
sourceSpecDir = "source/spec"
buildSpecDir = "build/spec"

module.exports = gruntFunction = (grunt) ->
pkg = grunt.file.readJSON 'package.json'

gruntConfig =
pkg: pkg

meta:
banner: """
/*!
* <%= pkg.name %> - version <%= pkg.version %>
* Compiled on <%= grunt.template.today(\"yyyy-mm-dd\") %>
* <%= pkg.repository.url %>
* Copyright(c) <%= grunt.template.today(\"yyyy\") %> <%= pkg.author.name %> (<%= pkg.author.email %> )
* Licensed <%= pkg.licenses[0].type %> <%= pkg.licenses[0].url %>
*/\n
"""
varVERSION: "var VERSION = '<%= pkg.version %>'; //injected by grunt:concat\n"
mdVersion: "# <%= pkg.name %> v<%= pkg.version %>\n"
usrBinEnvNode: "#!/usr/bin/env node\n"

options: {sourceDir, buildDir, sourceSpecDir, buildSpecDir}

clean:
build: 'build'
temp: 'temp'

concat:
VERSIONurequire:
options: banner: "<%= meta.banner %><%= meta.varVERSION %>"
src: [ '<%= options.buildDir %>/urequire.js']
dest: '<%= options.buildDir %>/urequire.js'

copy:
specResources:
files: [ expand: true, cwd: "#{sourceSpecDir}/NodeRequirer", src: ["*.json"], dest: "#{buildSpecDir}/NodeRequirer"]
urequire: # eat your own dogfood
_all:
dependencies: imports:
lodash: '_'
uberscore: '_B'
'utils/UError': 'UError'
resources:[
[ '+inject-_B.logger', ['**/*.js'],
(m)-> m.beforeBody = "var l = new _B.Logger('urequire:#{m.path}');"] ]
runtimeInfo: false
bare: true
template: name: 'nodejs'

lib:
path: 'source/code'
dstPath: 'build/code'
main: 'urequire'
template: banner: true
resources: [ 'inject-version' ]

spec:
path: 'source/spec'
dstPath: 'build/spec'
copy: /./
dependencies:
imports:
chai: 'chai'
specHelpers: 'spH'
replace: '../code/utils/UError' : 'utils/UError'
resources: [
['import-keys',
specHelpers: """
equal, notEqual, ok, notOk, tru, fals, deepEqual, notDeepEqual, exact, notExact, iqual,
notIqual, ixact, notIxact, like, notLike, likeBA, notLikeBA, equalSet, notEqualSet"""
chai: 'expect' ] ]
afterBuild: require 'urequire-ab-specrunner'

specWatch: derive: 'spec', watch: true

copy: wiki: files: [ expand: true, cwd: "source/code/config", src: ["*.md"], dest: "../uRequire.wiki/"]

clean: build: 'build', temp: 'temp'

wiki:
files: [ expand: true, cwd: "#{sourceDir}/config/", src: ["*.md"], dest: "../uRequire.wiki/"]

watch:
dev: # requires `coffeeWatch` to compile changed only files! need a changed-only-files coffee task!
files: ["build/**/*"]
tasks: ['copy', 'mochaCmd']

copy:
files: ["source/**/*"]
tasks: ['copy:wiki']

shell:
coffee: command: "#{nodeBin}coffee -cb -o ./build ./source"
coffeeWatch: command: "#{nodeBin}coffee -cbw -o ./build ./source"
mochaCmd: command: "#{nodeBin}mocha #{buildSpecDir}/**/*-spec.js --recursive --timeout 5000 --bail"
options: verbose: true, failOnError: true, stdout: true, stderr: true

# copy build files to wherever urequire is a dev dep testbed
deps = [] #['uberscore']
for dep in deps
gruntConfig.copy[dep] =
files: [ expand: true, src: ["**/*.js", "**/*.json", "!node_modules/**/*"], dest: "../#{dep}/node_modules/urequire"]

### shortcuts generation ###
splitTasks = (tasks)-> if (tasks instanceof Array) then tasks else tasks.split(/\s/).filter((f)->!!f)
grunt.registerTask cmd, splitTasks "shell:#{cmd}" for cmd of gruntConfig.shell # shortcut to all "shell:cmd"
grunt.registerTask shortCut, "urequire:#{shortCut}" for shortCut of gruntConfig.urequire
grunt.registerTask shortCut, splitTasks tasks for shortCut, tasks of {
default: "clean build test"
build: "coffee concat copy"
test: "copy:specResources mochaCmd"

# IDE shortcuts
"alt-c": "copy:wiki"
"alt-b": "build"
"alt-t": "test"
default: 'clean lib spec'
develop: 'clean lib specWatch'
"alt-c": "copy" # IDE shortcuts
"alt-b": "lib"
}

grunt.loadNpmTasks task for task of pkg.devDependencies when startsWith(task, 'grunt-')
grunt.initConfig gruntConfig

null
grunt.loadNpmTasks task for task of grunt.file.readJSON('package.json').devDependencies when task.lastIndexOf('grunt-', 0) is 0
grunt.initConfig gruntConfig
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"main": "./build/code/urequire.js",
"preferGlobal": false,
"scripts": {
"test": "grunt test"
"test": "grunt"
},
"directories": {
"doc": "./doc",
Expand All @@ -68,29 +68,31 @@
"require-clean": "0.1.x",
"requirejs": "2.1.15",
"rimraf": "2.2.x",
"upath": "^0.1.3",
"upath": "^0.1.4",
"uberscore": "0.0.17",
"uglify-js": "^2.4.15",
"underscore.string": "^2.3.3",
"urequire-rc-coco": "0.1.x",
"urequire-rc-coffee-script": "0.1.x",
"urequire-rc-coffee-script": "^0.1.1",
"urequire-rc-iced-coffee-script": "0.1.x",
"urequire-rc-livescript": "0.1.x",
"when": "^3.6.2"
},
"devDependencies": {
"mocha": "2.0.x",
"chai": "1.9.2",
"chai-as-promised": "4.1.1",
"grunt": "0.4.5",
"grunt-contrib-clean": "0.4.x",
"grunt-contrib-concat": "0.1.x",
"grunt-contrib-copy": "0.4.x",
"grunt-contrib-watch": "0.5.x",
"grunt-shell": "0.3.x",
"mocha": "2.0.x",
"grunt-urequire": "0.7.x",
"urequire-rc-exec": "0.1.x",
"urequire-rc-less": "0.1.x",
"urequire-rc-teacup-js": "0.2.x",
"teacup": "0.4.x"
"teacup": "0.4.x",
"urequire": ">=0.7.0-beta10",
"urequire-ab-specrunner": "^0.1.9",
"urequire-rc-inject-version": "^0.1.2"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# uRequire v0.7.0-beta5
# uRequire v0.7.0-beta10

## Beta release note

Expand Down
3 changes: 0 additions & 3 deletions source/code/NodeRequirer.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_ = (_B = require 'uberscore')._

fs = require 'fs'
upath = require 'upath'

Expand All @@ -11,7 +9,6 @@ Dependency = require './fileResources/Dependency'
urequire = require './urequire'

BundleBase = require './process/BundleBase'
UError = require './utils/UError'

###
The `nodejs`'s require facility.
Expand Down
5 changes: 0 additions & 5 deletions source/code/codeUtils/CodeMerger.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/codeUtils/CodeMerger'

UError = require '../utils/UError'

toCode = require "./toCode"
toAST = require "./toAST"
isLikeCode = require "./isLikeCode"
Expand Down
1 change: 0 additions & 1 deletion source/code/codeUtils/isEqualCode.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
_ = (_B = require 'uberscore')._
toAST = require './toAST'

module.exports = isEqualCode = (code1, code2)->
Expand Down
4 changes: 1 addition & 3 deletions source/code/codeUtils/isLikeCode.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
_B = require 'uberscore'
toAST = require './toAST'

module.exports = isLikeCode = (code1, code2)->
_B.isLike toAST(code1, 'Program')?.body,
toAST(code2, 'Program')?.body

toAST(code2, 'Program')?.body
3 changes: 0 additions & 3 deletions source/code/codeUtils/replaceCode.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/codeUtils/replaceCode'

toCode = require "./toCode"
toAST = require "./toAST"
isLikeCode = require "./isLikeCode"
Expand Down
5 changes: 0 additions & 5 deletions source/code/codeUtils/toAST.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/codeUtils/toAST'#, 100

esprima = require 'esprima'

UError = require '../utils/UError'
# @param codeOrAST {String|AST}
# @return an AST that can be generated to code
# either as type: 'Program' or type: 'BlockStatement'
Expand Down
4 changes: 0 additions & 4 deletions source/code/codeUtils/toCode.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/codeUtils/toCode'# 100

escodegen = require 'escodegen'

dfb = new _B.DeepDefaultsBlender

UError = require '../utils/UError'
toAST = require './toAST'

# returns the AST of the 1st statement/expression if its a String, as-is otherwise
Expand Down
3 changes: 0 additions & 3 deletions source/code/config/ResourceConverter.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/config/ResourceConverter', 0 # config's `build.debugLevel` doesn't work here, cause the config is not read yet!

upath = require 'upath'

UError = require '../utils/UError'

# ResourceConverter creates materialized RC instances
# It contains setter factories on the instance
# @note on properties conventions:
Expand Down
3 changes: 0 additions & 3 deletions source/code/config/blendConfigs.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/blendConfigs'
fs = require 'fs'
upath = require 'upath'
require('butter-require')() # no need to store it somewhere

MasterDefaultsConfig = require './MasterDefaultsConfig'
ResourceConverter = require './ResourceConverter'
UError = require '../utils/UError'

arrayizeUniqueReversingUnshifter = new _B.ArrayizeBlender [], {unique: true, reverse:true, addMethod: 'unshift'}
arrayizeBlender = new _B.ArrayizeBlender
Expand Down
2 changes: 0 additions & 2 deletions source/code/config/isTrueOrFileMatch.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_ = (_B = require 'uberscore')._

umatch = require 'umatch'

module.exports = (val, filename)->
Expand Down
4 changes: 0 additions & 4 deletions source/code/fileResources/BundleFile.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/BundleFile'

fs = require 'fs'
mkdirp = require "mkdirp"
When = require 'when'

upath = require 'upath'

# urequire
UError = require '../utils/UError'
isTrueOrFileMatch = require '../config/isTrueOrFileMatch'
pathRelative = '../paths/pathRelative'

Expand Down
4 changes: 0 additions & 4 deletions source/code/fileResources/Dependency.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/Dependency' #, 110

_.mixin (require 'underscore.string').exports()

util = require 'util'
Expand All @@ -10,7 +7,6 @@ umatch = require 'umatch'

MasterDefaultsConfig = require '../config/MasterDefaultsConfig'
pathRelative = require './../paths/pathRelative'
UError = require '../utils/UError'

untrust = (str)->
str = new String(str + '')
Expand Down
4 changes: 0 additions & 4 deletions source/code/fileResources/FileResource.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/FileResource'

fs = require 'fs'
mkdirp = require 'mkdirp'
When = require 'when'

# uRequire
BundleFile = require './BundleFile'
upath = require 'upath'
UError = require '../utils/UError'
ResourceConverter = require '../config/ResourceConverter'
ResourceConverterError = require '../utils/ResourceConverterError'

Expand Down
4 changes: 0 additions & 4 deletions source/code/fileResources/Module.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/Module'#, 100
_.mixin (require 'underscore.string').exports()
fs = require 'fs'
util = require 'util'
Expand All @@ -10,8 +8,6 @@ upath = require 'upath'
ModuleGeneratorTemplates = require '../templates/ModuleGeneratorTemplates'
TextResource = require './TextResource'
Dependency = require "./Dependency"
UError = require '../utils/UError'

isTrueOrFileMatch = require '../config/isTrueOrFileMatch'

isLikeCode = require "../codeUtils/isLikeCode"
Expand Down
4 changes: 0 additions & 4 deletions source/code/fileResources/TextResource.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/TextResource'
When = require 'when'

# uRequire
FileResource = require './FileResource'
UError = require '../utils/UError'
ResourceConverter = require '../config/ResourceConverter'

###
Expand Down
9 changes: 0 additions & 9 deletions source/code/process/Build.coffee
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
_ = (_B = require 'uberscore')._
l = new _B.Logger 'uRequire/process/Build'
fs = require 'fs'

rimraf = require 'rimraf'
globExpand = require 'glob-expand'

moment = require 'moment'
url = require 'url'

upath = require 'upath'
umatch = require 'umatch'

# uRequire
When = require '../promises/whenFull'

isTrueOrFileMatch = require '../config/isTrueOrFileMatch'

BundleFile = require './../fileResources/BundleFile'
AlmondOptimizationTemplate = require '../templates/AlmondOptimizationTemplate'
DependenciesReporter = require './../utils/DependenciesReporter'
MasterDefaultsConfig = require '../config/MasterDefaultsConfig'

UError = require '../utils/UError'

{dependenciesBindingsBlender} = require '../config/blendConfigs'

# circular dependencies, lazily loaded on constructor for testing
Expand Down
Loading

0 comments on commit 5c7703e

Please sign in to comment.