Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmielnik committed Jun 7, 2021
1 parent b0e5a30 commit 1943f4d
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 124 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
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
68 changes: 0 additions & 68 deletions Boiler.js

This file was deleted.

21 changes: 21 additions & 0 deletions bin/bojler.js
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);
49 changes: 0 additions & 49 deletions boil.js

This file was deleted.

8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 27 additions & 6 deletions package.json
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"
}
}
44 changes: 44 additions & 0 deletions src/Boiler.js
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;
8 changes: 8 additions & 0 deletions src/boil.js
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;
10 changes: 10 additions & 0 deletions src/index.js
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
};
25 changes: 25 additions & 0 deletions src/lib/index.js
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
};

0 comments on commit 1943f4d

Please sign in to comment.