Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var path = require('path');
- var mdeps = require('module-deps');
- var through = require('through');
- function get_dependency_files(filepath, callback){
- 'use strict';
- var scripts = [];
- var mytransform = through(
- function(dependency){
- scripts.push(dependency.file);
- },
- function(data){
- var files = [];
- var l = scripts.length;
- for (var i = 0; i < l; i++){
- var js_filepath = scripts[i];
- var base = path.join(js_filepath, '..');
- try {
- var code = fs.readFileSync(path.join(base, 'package.json'), 'utf8');
- var definition = JSON.parse(code);
- if (definition && definition.files){
- var subfiles = definition.files;
- var l2 = subfiles.length;
- for (var j = 0; j < l2; j++){
- files.push(path.join(base, subfiles[j]));
- }
- }
- } catch(e){
- //
- }
- }
- callback(files);
- mytransform.queue(null);
- }
- );
- var md = mdeps({transformKey: ['browserify', 'transform']});
- md.pipe(mytransform);
- md.end({file: filepath});
- }
- get_dependency_files('./src/application/index.js', function(files){
- 'use strict';
- var stylesheets = files.filter(function(filepath){
- return filepath.match(/\.styl$/) || filepath.match(/\.css$/);
- });
- console.log('--------------- STYLUS ---------------');
- console.log(stylesheets);
- console.log('--------------------------------------');
- var images = files.filter(function(filepath){
- return filepath.match(/\.jpg$/) || filepath.match(/\.png$/) || filepath.match(/\.gif$/) || filepath.match(/\.svg$/);
- });
- console.log('--------------- IMAGES ---------------');
- console.log(images);
- console.log('--------------------------------------');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement