@softboxlab/moo-cli
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -14,6 +14,7 @@ "use strict"; | ||
const Mustache = __importStar(require("mustache")); | ||
const comp_js_1 = __importDefault(require("../templates/react/comp.js")); | ||
const func_js_1 = __importDefault(require("../templates/react/func.js")); | ||
const test_js_1 = __importDefault(require("../templates/react/test.js")); | ||
const default_path_1 = require("../utils/default-path"); | ||
const write_file_1 = __importDefault(require("../utils/write-file")); | ||
const react_template_1 = __importDefault(require("./react-template")); | ||
const vue_template_1 = __importDefault(require("./vue-template")); | ||
const isOnRootPath = () => (default_path_1.isFileOnCurrentDirectory('package.json')); | ||
const getFileExtension = ({ vue }) => { | ||
@@ -26,25 +27,39 @@ return vue | ||
if (framework === 'react') { | ||
return type === 'comp' | ||
? comp_js_1.default | ||
: comp_js_1.default === 'test' | ||
? func_js_1.default | ||
: test_js_1.default; | ||
return react_template_1.default(type); | ||
} | ||
if (framework === 'vue') { | ||
return vue_template_1.default(type); | ||
} | ||
throw new Error('could not find path'); | ||
}; | ||
exports.default = async (framework, options) => { | ||
const { name, test, dest, functional } = options; | ||
const isValidBuild = (dest, name) => { | ||
if (!dest || !name) { | ||
console.log('Could not create amazing stuff due to some arguments missing: either name or dest'); | ||
return; | ||
return false; | ||
} | ||
const type = functional | ||
? 'func' | ||
: 'comp'; | ||
if (!isOnRootPath()) { | ||
console.log('Sorry! Run moo-cli on your root directoy (same place where you can find the `package.json` file)'); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
const createComponentFile = (framework, type, name, dest, options) => { | ||
const fileTemplate = Mustache.render(getTemplate(framework, type), options); | ||
write_file_1.default(fileTemplate, name, getFileExtension(options), dest); | ||
if (test) { | ||
const testTemplate = Mustache.render(getTemplate(framework, 'test'), options); | ||
write_file_1.default(testTemplate, name, 'test.js', dest); | ||
}; | ||
const createTestFile = (framework, name, dest, options) => { | ||
const testTemplate = Mustache.render(getTemplate(framework, 'test'), options); | ||
write_file_1.default(testTemplate, name, 'test.js', dest); | ||
}; | ||
exports.default = async (framework, options) => { | ||
const { name, test, dest, functional } = options; | ||
if (isValidBuild(dest, name)) { | ||
const type = functional | ||
? 'func' | ||
: 'comp'; | ||
createComponentFile(framework, type, name, dest, options); | ||
if (test) { | ||
createTestFile(framework, name, dest, options); | ||
} | ||
} | ||
}; |
@@ -24,2 +24,6 @@ #!/usr/bin/env node | ||
.option('-m, --menu', 'Open menu') | ||
.parse(process.argv); | ||
commander_1.default | ||
.command('build <name>') | ||
.description('build a .js or .vue file in production mode with zero config') | ||
.option('-d, --dest [dir]', 'output directory (default: src/components)', './src/components') | ||
@@ -33,5 +37,2 @@ .option('-r, --react', 'build something for react') | ||
.option('-t, --test', 'set test flag (this will build some tests for ya (if it can...))') | ||
.parse(process.argv) | ||
.command('build <name>') | ||
.description('build a .js or .vue file in production mode with zero config') | ||
.action((name, cmd) => { | ||
@@ -38,0 +39,0 @@ const args = clean_1.default(cmd); |
@@ -9,3 +9,3 @@ "use strict"; | ||
return { | ||
}; | ||
}{{#airbnb}};{{/airbnb}} | ||
}{{/flux}} | ||
@@ -12,0 +12,0 @@ |
@@ -6,3 +6,2 @@ "use strict"; | ||
import {{name}} from '../{{name}}'{{#airbnb}};{{/airbnb}} | ||
test('should render the {{name}} component', async () => { | ||
@@ -9,0 +8,0 @@ const wrapper = shallow( |
@@ -11,6 +11,8 @@ "use strict"; | ||
const path = __importStar(require("path")); | ||
const shelljs_1 = require("shelljs"); | ||
const resolve = (from, to) => path.resolve(from, to); | ||
const ROOT_PATH = resolve(process.cwd(), './'); | ||
exports.default = (to) => path.relative(ROOT_PATH, to); | ||
exports.isFileOnCurrentDirectory = (file) => (Boolean(shelljs_1.ls('./*.json').filter((el) => el.toLowerCase().indexOf(file.toLowerCase()) !== -1).length)); | ||
exports.pathInSrc = (to) => (resolve(ROOT_PATH, `src/${to}`)); | ||
exports.projectRootPath = (currentPath) => (currentPath.split('/').reduce((acc) => path.join(acc, '..'), '')); |
{ | ||
"name": "@softboxlab/moo-cli", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A MOOvelous CLI", | ||
@@ -16,2 +16,3 @@ "main": "dist/index.js", | ||
"build": "npm run check && npm run lint && tsc", | ||
"coverage": "yarn test --coverage", | ||
"test": "jest", | ||
@@ -55,2 +56,21 @@ "travis-deploy-once": "travis-deploy-once", | ||
}, | ||
"jest": { | ||
"roots": [ | ||
"<rootDir>/src" | ||
], | ||
"verbose": true, | ||
"testEnvironment": "node", | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
] | ||
}, | ||
"devDependencies": { | ||
@@ -69,8 +89,6 @@ "@types/commander": "^2.12.2", | ||
"lint-staged": "^7.2.0", | ||
"ts-jest": "^23.0.1", | ||
"ts-jest": "^23.1.3", | ||
"tslint": "^5.11.0", | ||
"tslint-eslint-rules": "^5.3.1", | ||
"typescript": "^2.9.2", | ||
"travis-deploy-once": "^5.0.1", | ||
"semantic-release": "^15.9.3" | ||
"typescript": "^2.9.2" | ||
}, | ||
@@ -77,0 +95,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
16
40
821
180801