snippeteer/index.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-01-15 14:14:54 +01:00
#!/usr/bin/env node
2020-01-18 21:14:40 +01:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
2020-03-25 16:45:44 +01:00
* This file is part of Snippeteer which is released under BSD-3-Clause.
2020-01-18 21:14:40 +01:00
* See file 'LICENSE' for full license details.
2020-03-25 16:45:44 +01:00
* Created by Timo Hocker <timo@scode.ovh>, March 2020
2020-01-18 21:14:40 +01:00
*/
2020-01-15 14:09:29 +01:00
/* eslint-disable no-console */
/* eslint-disable global-require */
/* eslint-disable no-sync */
2020-01-30 10:57:34 +01:00
'use strict';
2020-01-15 14:09:29 +01:00
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`);
2020-01-15 15:43:23 +01:00
const folder = process.cwd ();
2020-01-15 14:09:29 +01:00
2020-01-15 14:46:10 +01:00
if (!snippet.assert (folder, args)) {
2020-03-04 11:34:08 +01:00
console.log ('snippet rejected arguments');
2020-01-15 14:09:29 +01:00
return;
}
2020-01-15 14:46:10 +01:00
snippet.run (folder, args);
2020-01-15 14:09:29 +01:00
}
main ();