-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0e5a30
commit 1943f4d
Showing
10 changed files
with
153 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
tabWidth: 2 | ||
printWidth: 100 | ||
singleQuote: true | ||
arrowParens: always | ||
trailingComma: none | ||
|
||
overrides: | ||
- files: "*.scss" | ||
options: | ||
parser: scss | ||
singleQuote: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path'); | ||
const { boil, readProjectConfig, resolvePath } = require('../src'); | ||
|
||
const argv = Array.from(process.argv); | ||
const args = argv.slice(2); | ||
const [argRootPath] = args; | ||
|
||
if (typeof argRootPath !== 'string') { | ||
throw new Error('Usage: node boil.js [path]'); | ||
} | ||
|
||
const rootPath = resolvePath(argRootPath); | ||
const config = readProjectConfig(rootPath); | ||
|
||
if (!config) { | ||
throw new Error(`No project found for "${rootPath}"`); | ||
} | ||
|
||
boil(rootPath, config); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
{ | ||
"name": "boil", | ||
"name": "bojler", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "index.js", | ||
"description": "Boil your plate up", | ||
"main": "src/index.js", | ||
"engines": { | ||
"node": ">=12.4.0" | ||
}, | ||
"bin": { | ||
"bojler": "./bin/bojler.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kamilmielnik/bojler.git" | ||
}, | ||
"author": { | ||
"name": "Kamil Mielnik", | ||
"email": "[email protected]", | ||
"url": "https://kamilmielnik.com/" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/kamilmielnik/bojler/issues" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"prettier": "prettier --list-different './src/**/*.{js,jsx,ts,tsx}'", | ||
"prettier:fix": "npm run prettier:js -- --write --no-list-different" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"mkdirp": "^1.0.4" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^2.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
|
||
class Boiler { | ||
constructor(rootPath, getTemplates) { | ||
this.rootPath = rootPath; | ||
this.getTemplates = getTemplates; | ||
} | ||
|
||
get componentName() { | ||
const names = this.rootPath.split(path.sep); | ||
const componentName = names[names.length - 1]; | ||
return componentName; | ||
} | ||
|
||
boil() { | ||
this.createRootDirectory(); | ||
this.renderTemplates(); | ||
} | ||
|
||
createRootDirectory() { | ||
mkdirp.sync(this.rootPath); | ||
} | ||
|
||
renderTemplates() { | ||
const templates = this.getTemplates({ | ||
componentName: this.componentName, | ||
rootPath: this.rootPath | ||
}); | ||
|
||
for (const [filename, renderTemplate] of Object.entries(templates)) { | ||
const filepath = path.isAbsolute(filename) ? filename : path.join(this.rootPath, filename); | ||
const template = renderTemplate({ | ||
componentName: this.componentName, | ||
template: fs.existsSync(filepath) ? fs.readFileSync(filepath, 'utf-8') : '' | ||
}); | ||
|
||
fs.writeFileSync(filepath, template); | ||
} | ||
} | ||
} | ||
|
||
module.exports = Boiler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const Boiler = require('./Boiler'); | ||
|
||
const boil = (rootPath, getTemplates) => { | ||
const boiler = new Boiler(rootPath, getTemplates); | ||
boiler.boil(); | ||
}; | ||
|
||
module.exports = boil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import boil from './boil'; | ||
import Boiler from './Boiler'; | ||
import { getConfig, resolvePath } from './lib'; | ||
|
||
module.exports = { | ||
boil, | ||
Boiler, | ||
getConfig, | ||
resolvePath | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const BOIL_DIRECTORY = path.resolve(os.homedir(), '.boil'); | ||
|
||
const resolvePath = (filepath) => { | ||
return path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath); | ||
}; | ||
|
||
const readProjectConfig = (rootPath) => { | ||
const configFilenames = fs.readdirSync(BOIL_DIRECTORY); | ||
const configs = configFilenames.map((configFilename) => { | ||
const configFilepath = path.join(BOIL_DIRECTORY, configFilename); | ||
return require(configFilepath); | ||
}); | ||
return configs.find((project) => { | ||
return rootPath.includes(project.PROJECT_PATH); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
readProjectConfig, | ||
resolvePath | ||
}; |