#!/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 , March 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 ();