2020-04-16 07:45:48 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
2020-05-07 18:40:35 +02:00
|
|
|
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
2020-04-16 07:45:48 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-15 20:21:00 +02:00
|
|
|
import path from 'path';
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
import { AutoComplete } from 'enquirer';
|
|
|
|
import { Snippet } from './Snippet';
|
|
|
|
|
|
|
|
(async (): Promise<void> => {
|
|
|
|
const snippets = await fs.readdir (path.join (__dirname, 'snippets'));
|
2020-05-11 12:01:39 +02:00
|
|
|
const runners: Record<string, Snippet> = {};
|
|
|
|
await Promise.all (
|
|
|
|
snippets.map (async (s) => {
|
|
|
|
const runner = (new (
|
|
|
|
await import (`./snippets/${s}/index.js`)
|
|
|
|
).default) as Snippet;
|
|
|
|
runners[s] = runner;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const snippet = await new AutoComplete ({
|
|
|
|
name: 'snippet',
|
|
|
|
message: 'choose a snippet',
|
|
|
|
choices: snippets.filter ((s) => runners[s].is_active ())
|
|
|
|
})
|
2020-04-15 20:21:00 +02:00
|
|
|
.run ();
|
2020-05-11 12:01:39 +02:00
|
|
|
runners[snippet].start (process.cwd ());
|
2020-04-27 10:18:12 +02:00
|
|
|
}) ()
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
.catch ((e) => console.log (e));
|