Skip to content

Commit

Permalink
feat(): package.json is now created for the npm package
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Max Ruf committed May 18, 2017
1 parent c4e57ad commit fffaaab
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@ const path = require('path')
const fs = require('fs')

const buildPath = path.resolve(__dirname, 'build')
const distPath = path.resolve(__dirname, 'dist')
const svgPath = path.resolve(__dirname, 'mdi/icons/svg')

const toPascalCase = (str) => {
const tplFile = path.resolve(__dirname, 'build.tpl')
const pkgFile = path.resolve(__dirname, 'package.json')

function toPascalCase(str) {
return str.toLowerCase()
.split(/-/g).map(token =>
token.charAt(0).toUpperCase() + token.slice(1))
.join('')
}

const copyPackage = () => fs.readFile(pkgFile, (err, pkgRaw) => {
const pkgObj = JSON.parse(pkgRaw)

// Nobody cares for errors... nobody
fs.writeFile(path.resolve(distPath, 'package.json'), JSON.stringify(Object.keys(pkgObj)
.map((key) => {
if (!/script|devDependencies|dependencies/.test(key)) {
return pkgObj[key]
}
})
))
})

const buildIcons = (components) => fs.readFile(path.resolve('./build.tpl'), (err, tpl) => {
for (const component of components) {
fs.writeFileSync(
Expand All @@ -20,6 +37,8 @@ const buildIcons = (components) => fs.readFile(path.resolve('./build.tpl'), (err
.replace(/\{\{path\}\}/g, component.path)
)
}

copyPackage()
})

fs.readdir(svgPath, (a, svgs) => {
Expand Down

0 comments on commit fffaaab

Please sign in to comment.