Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@qrohlf/bones

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qrohlf/bones - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

.bones/arguments-example/__name|snakeCase__.sh

13

.bones/bones.config.js

@@ -5,3 +5,14 @@ // user configuration overrides for bones

module.exports = {
// templateFiles: ['.js', '.html', '.txt', '.md']
templateFiles: [
'.js',
'.html',
'.txt',
'.md',
'.sh',
'.rb',
'.cpp',
'.c',
'.h',
'.scss'
]
}

4

lib/defaultConfig.js
module.exports = {
mustacheDelimiters: ['__', '__'],
templateFiles: [ // todo expand this list of default with the Github Linguist dataset

@@ -12,4 +11,5 @@ '.js',

'.c',
'.o'
'.h',
'.scss'
]
}

@@ -5,3 +5,2 @@ #!/usr/bin/env node

const path = require('path')
const mustache = require('mustache')
const utils = require('./utils')

@@ -30,3 +29,2 @@

const config = utils.getConfig(bonesDir)
mustache.tags = config.mustacheDelimiters
const templatePath = path.join(bonesDir, template)

@@ -33,0 +31,0 @@

@@ -5,3 +5,3 @@ const path = require('path')

const USER_HOMEDIR = path.resolve(os.homedir())
const mustache = require('mustache')
const _ = require('lodash')

@@ -61,10 +61,29 @@ const tuplesToObject = tuples => (

const processDestPath = (path, templateArgs) => (
Object.keys(templateArgs).reduce((s, key) => (
s.replace(`__${key}__`, templateArgs[key])
), path)
const templateHelpers = {
camelCase: _.camelCase,
pascalCase: str => _.upperFirst(_.camelCase(str)),
snakeCase: _.snakeCase,
kebabCase: _.kebabCase,
upperCase: str => str.toUpperCase(),
upperSnakeCase: str => _.snakeCase(str).toUpperCase(),
lowerCase: str => str.toLowerCase()
}
const processTemplateString = (path, templateArgs) => (
Object.keys(templateArgs).reduce((s, key) => {
const regexSafeKey = _.escapeRegExp(key)
const regexStr = `__${regexSafeKey}(?:\\|([A-Za-z]+))?__`
const search = new RegExp(regexStr, 'g')
const templateArg = templateArgs[key]
// console.log(`using regex ${search}`)
return s.replace(search, (match, fn) => (
fn
? templateHelpers[fn](templateArg)
: templateArg
))
}, path)
)
const renderTemplate = (sourcePath, _destPath, templateArgs, config) => {
const destPath = processDestPath(_destPath, templateArgs)
const destPath = processTemplateString(_destPath, templateArgs)

@@ -84,3 +103,3 @@ if (isDirectory(sourcePath)) {

const mode = fs.statSync(sourcePath).mode
const rendered = mustache.render(template, templateArgs)
const rendered = processTemplateString(template, templateArgs)
fs.writeFileSync(destPath, rendered, {mode}) // todo overwrite prompt?

@@ -99,4 +118,4 @@ } else {

copyRecursive,
processDestPath,
processTemplateString,
renderTemplate
}
{
"name": "@qrohlf/bones",
"version": "0.1.0",
"version": "0.2.0",
"description": "A simple Javascript scaffolding tool",

@@ -24,7 +24,7 @@ "repository": "github:qrohlf/bones",

"dependencies": {
"mustache": "^2.3.0"
"lodash": "^4.17.15"
},
"devDependencies": {
"standard": "^11.0.0"
"standard": "^11.0.1"
}
}

@@ -31,2 +31,9 @@ # @qrohlf/bones

4. Add your own 'bones':
```
mkdir .bones/mytemplate
vim .bones/mytemplate/__name__.js
```
## Usage

@@ -50,6 +57,25 @@

There are also a number of string helpers you can use for transforming variables.
The syntax for doing this is `__name|snakeCase`. The currently available helpers
are:
| helper | output|
| - | - |
|`camelCase`|fooBar|
|`pascalCase`|FooBar|
|`snakeCase`|foo_bar|
|`kebabCase`|foo-bar|
|`upperCase`|FOOBAR|
|`upperSnakeCase`|FOO_BAR|
|`lowerCase`|foobar|
Bones uses a whitelist to determine which files to run through the template
engine and which files to copy. See the [default config](./lib/defaultConfig.js)
for a list of file extensions that are interpreted as templates
for a list of file extensions that are interpreted as templates.
## Examples
You can see some template examples in the [.bones](./.bones) directory of this
repo.
## Customization

@@ -56,0 +82,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc