Skip to content

Instantly share code, notes, and snippets.

@maximkoretskiy
Created February 2, 2016 12:40
Show Gist options
  • Save maximkoretskiy/88f6c5bf5f91f22a15cc to your computer and use it in GitHub Desktop.
Save maximkoretskiy/88f6c5bf5f91f22a15cc to your computer and use it in GitHub Desktop.
Fast add package json for all views
"use strict"
const glob = require('glob');
const path = require('path');
const fs = require('fs');
glob('app/scripts/view/**/*.coffee', function (err, files) {
files = files
.filter(f=> f.match(/\/(\w+)\/\1/i))
.map(path.parse)
.forEach(f=>{
const packageLocation = path.resolve(`${f.dir}/package.json`);
const packageContent = `{\n "main": "./${f.base}" \n}`;
fs.writeFileSync(packageLocation, packageContent)
console.info(`Write package.js in folder ${f.dir}`);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment