Skip to content

Instantly share code, notes, and snippets.

@mubaidr
Created November 29, 2018 10:11
Show Gist options
  • Save mubaidr/be7310d26c885162f627343363125cda to your computer and use it in GitHub Desktop.
Save mubaidr/be7310d26c885162f627343363125cda to your computer and use it in GitHub Desktop.
const fs = require('fs');
const Replace = require('replace');
const basePath = './api/';
const modelsPath = './api/db/models/';
const models = fs.readdirSync(modelsPath);
models.forEach(model => {
const splitted = model
.replace('.js', '')
.toLowerCase()
.split('_');
if (splitted.length > 1) {
const find = splitted
.map((s, i) => {
if (i === 0) return s;
return s[0].toUpperCase() + s.substr(1);
})
.join('');
splitted.shift();
const replace = splitted
.map((s, i) => {
if (i === 0) return s;
return s[0].toUpperCase() + s.substr(1);
})
.join('');
// console.log(find, replace);
Replace({
regex: find,
replacement: replace,
paths: ['./api/'],
recursive: true,
silent: true,
include: '*.js',
q: true,
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment