snippeteer/index.js
2020-03-04 11:34:08 +01:00

53 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, January 2020
*/
/* eslint-disable no-console */
/* eslint-disable global-require */
/* eslint-disable no-sync */
'use strict';
const { argv } = require ('yargs');
const path = require ('path');
const fs = require ('fs-extra');
const [
template,
...args
] = argv._;
/**
* main function
*/
function main () {
if (typeof template !== 'string') {
console.log ('please specify a template');
return;
}
if (
!fs.existsSync (path.join (__dirname, 'snippets', template))
|| !(/^[a-zA-Z]+$/u).test (template)
) {
console.log ('template does not exist');
return;
}
const snippet = require (`./snippets/${template}/index.js`);
const folder = process.cwd ();
if (!snippet.assert (folder, args)) {
console.log ('snippet rejected arguments');
return;
}
snippet.run (folder, args);
}
main ();