scroungejs

compress, concatenate and/or timestamp your files as part of a build process for your web site.

scrounge.js

(c)Bumblehead, 2012-2016 MIT-license

NOT FOR PRODUCTION USE -ALPHA QUALITY

scrounge.js is a narrow use-case build-tool of minimal setup. It is a decision-making wrapper around tools like depgraph, replace-requires, uglifyjs2, umd and detective. features include:

  • supports CommonJS and NPM/Bower module resolution and does not support AMD, ES6 or other module formats
  • compression and concatenation are enabled or disabled for each build (useful during development)
  • does not require unusual tags or attributes added to markup files
  • handles ".css" and ".less" stylesheets

Clone and try out the test with npm start.


get started

A sample scrounge.js configuration found in test/,

scroungejs.build({
  inputpath      : './test/testbuild1/testbuildSrc',
  outputpath     : './test/testbuild1/testbuildFin',
  publicpath     : './testbuildFin',
  basepage       : './test/testbuild1/index.html',
  iscompressed   : true,
  isconcatenated : false,
  roots          : 'app.js'
}, function (errres) {
  if (err) return console.log(err);
  console.log('finished!');
});

It console prints this when it runs,

[...] start: Mon Dec 07 2015 22:09:36 GMT-0800 (PST)
[...] root: app.js
 
scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/app.js
└─┬ scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/views/viewsall.js
. ├─┬ scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/views/viewa.js
. │ └─┬ scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/controls/ctrlsall.js
. │   ├─┬ scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/controls/ctrla.js
. │   │ └── scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/models/modela.js
. │   └─┬ scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/controls/ctrlb.js
. │     └── scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/models/modelb.js
. └── scroungejs-0.8.0:~/test/testbuild1/testbuildSrc/views/viewb.js
 
[...] ugly: (app.js, .css, 1/1) ./test/testbuild1/testbuildSrc/views/viewa.css
[...] write: ./test/testbuild1/testbuildFin/app.css
[...] ugly: (app.js, .js, 1/9) ./test/testbuild1/testbuildSrc/views/viewb.js
[...] ugly: (app.js, .js, 2/9) ./test/testbuild1/testbuildSrc/models/modelb.js
[...] ugly: (app.js, .js, 3/9) ./test/testbuild1/testbuildSrc/controls/ctrlb.js
[...] ugly: (app.js, .js, 4/9) ./test/testbuild1/testbuildSrc/models/modela.js
[...] ugly: (app.js, .js, 5/9) ./test/testbuild1/testbuildSrc/controls/ctrla.js
[...] ugly: (app.js, .js, 6/9) ./test/testbuild1/testbuildSrc/controls/ctrlsall.js
[...] ugly: (app.js, .js, 7/9) ./test/testbuild1/testbuildSrc/views/viewa.js
[...] ugly: (app.js, .js, 8/9) ./test/testbuild1/testbuildSrc/views/viewsall.js
[...] ugly: (app.js, .js, 9/9) ./test/testbuild1/testbuildSrc/app.js
[...] write: ./test/testbuild1/testbuildFin/app.js
[...] write: ./test/testbuild1/index.html
[...] finish: 00:00:288 (mm:ss:ms)

It reads index.tpl.html,

<!DOCTYPE html>
<html>
  <head>
    <!-- <scrounge trees="app.css"> -->
    <!-- </scrounge> -->
    <!-- <scrounge trees="app.js"> -->
    <!-- </scrounge> -->
  </head>
  <body>
    <script type="text/javascript">
      app.start();
    </script> 
  </body>
</html>

It then creates or updates index.html to look like this,

<!DOCTYPE html>
<html>
  <head>
    <!-- <scrounge trees="app.css"> -->
    <link href="./testbuildFin/app.css" rel="stylesheet" type="text/css">
    <!-- </scrounge> -->
    <!-- <scrounge trees="app.js"> -->
    <script src="./testbuildFin/app.js" type="text/javascript"></script> 
    <!-- </scrounge> -->
  </head>
  <body>
    <script type="text/javascript">
      app.start();
    </script> 
  </body>
</html>

That's the basic functionality with details explained below. Pull Requests are liberally accepted.


modifiers

  • inputpath= path, default: ./

    a systempath to a directory

  • outputpath= path, default: ./www_

    a systempath to a directory or file

  • publicpath= path, default: null

    a path to files created by scrounge.js used with basepage

    ./getStarted/app/cmpr/app.js, with publicpath /cmpr/

    <script src="/cmpr/app.js" type="text/javascript"></script>';
  • isunique= bool, default: false

    add a unique argument to reference paths in include elements

    <script src="Main.js?u=1370491167925" type="text/javascript"></script>';
    <link href="Main.css?u=1370491167926" rel="stylesheet" type="text/css">
  • iscompressed= bool, default: false

    compress scripts and styles before writing them.

  • isconcatenated= bool, default: false

    concatenate scripts and stylesheets files before writing them.

  • issilent= bool, default: false

    supress console messages.

  • isbrowser= bool, default: true

    locate files defined to the "browser" property defined in package.json and bower.json files.

  • basepage= basepage, default: null

    update scrounge tags in the defined basepage. basepage is not modified if it does not contain scrounge tags.


license

(The MIT License)

Copyright (c) 2012-2016 Bumblehead chris@bumblehead.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.