From 4e76cf3d5cfa0eb6733323bafa05bc1c2df57d51 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Mon, 11 May 2020 12:01:39 +0200 Subject: [PATCH] disable wip snippets --- README.md | 62 ++++++--------------------------- lib/Snippet.ts | 1 + lib/index.ts | 25 +++++++------ lib/snippets/copyright/index.ts | 4 +++ lib/snippets/database/index.ts | 6 +++- lib/snippets/jenkins/index.ts | 4 +++ lib/snippets/node/index.ts | 4 +++ lib/snippets/readme/index.ts | 4 +++ 8 files changed, 47 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index fbb68d3..16f1e45 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,18 @@ -# Snippeteer +# @sapphirecode/snippeteer + +[![Package quality](https://packagequality.com/shield/@sapphirecode/snippeteer.svg)](https://packagequality.com/#?package=@sapphirecode/snippeteer) + +> macros for setting up projects or project parts ## Installation -to work with the @scode scope you have to add the following line to your npmrc. -for this particular one you'll have to add it to the global npmrc stored in your home folder (~/.npmrc) - -```npmrc -@scode:registry=https://npm.scode.ovh -``` - -then install the module using the following command - -```sh -npm i -g @scode/snippeteer -``` +> npm i -g @sapphirecode/snippeteer ## Usage -```sh -snippeteer [snippet] [..args] -``` +run `snippeteer` in console and choose a snippet, all necessary parameters will +be asked interactively -All snippets will be executed relative to your current working directory! +## License -## Snippets - -### Snippet - -Creates a new snippet template - -```sh -snippeteer snippet [name] -``` - -### Node - -Creates a new nodejs project - -```sh -snippeteer node [name] -``` - -### Jenkins - -Adds files necessary for jenkins - -optionally with a js script for npm modules by adding 'node' as argument - -```sh -snippeteer jenkins [node] -``` - -### Vue - -Adds files, dependencies and scripts for vue to a nodejs project - -```sh -snippeteer vue -``` +BSD-3-Clause © Timo Hocker diff --git a/lib/Snippet.ts b/lib/Snippet.ts index b5f71bb..5504ae5 100644 --- a/lib/Snippet.ts +++ b/lib/Snippet.ts @@ -6,5 +6,6 @@ */ export interface Snippet { + is_active(): boolean; start(cwd: string): Promise; } diff --git a/lib/index.ts b/lib/index.ts index 5550ffd..9323208 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -12,17 +12,22 @@ import { Snippet } from './Snippet'; (async (): Promise => { const snippets = await fs.readdir (path.join (__dirname, 'snippets')); - const snippet = await new AutoComplete ( - { - name: 'snippet', - message: 'choose a snippet', - choices: snippets - } - ) + const runners: Record = {}; + 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 ()) + }) .run (); - const runner - = new (await import (`./snippets/${snippet}/index.js`)).default as Snippet; - runner.start (process.cwd ()); + runners[snippet].start (process.cwd ()); }) () // eslint-disable-next-line no-console .catch ((e) => console.log (e)); diff --git a/lib/snippets/copyright/index.ts b/lib/snippets/copyright/index.ts index c273c8e..5fb2379 100644 --- a/lib/snippets/copyright/index.ts +++ b/lib/snippets/copyright/index.ts @@ -19,6 +19,10 @@ import { FileMapper } from './file_mapper'; import { CopyrightOptions } from './copyright_options'; export default class Copyright implements Snippet { + public is_active (): boolean { + return true; + } + private _options: CopyrightOptions | null = null; private _cwd = ''; private _loaded_from_config = false; diff --git a/lib/snippets/database/index.ts b/lib/snippets/database/index.ts index dc59e37..9794721 100644 --- a/lib/snippets/database/index.ts +++ b/lib/snippets/database/index.ts @@ -8,7 +8,11 @@ import { Snippet } from '../../Snippet'; export default class Database implements Snippet { + public is_active (): boolean { + return false; + } + public start (): Promise { - return new Promise ((res) => res ()); + return Promise.resolve (); } } diff --git a/lib/snippets/jenkins/index.ts b/lib/snippets/jenkins/index.ts index ba62ab7..127992c 100644 --- a/lib/snippets/jenkins/index.ts +++ b/lib/snippets/jenkins/index.ts @@ -12,6 +12,10 @@ import { apply_template, modify_json } from '../../Helper'; import { general, node } from './Assets'; export default class Jenkins implements Snippet { + public is_active (): boolean { + return true; + } + public async start (): Promise { const is_node = await new Confirm ({ message: 'is the current project using nodejs?', diff --git a/lib/snippets/node/index.ts b/lib/snippets/node/index.ts index b4bee26..67e9fb1 100644 --- a/lib/snippets/node/index.ts +++ b/lib/snippets/node/index.ts @@ -56,6 +56,10 @@ async function init_package ( } export default class Node implements Snippet { + public is_active (): boolean { + return true; + } + public async start (): Promise { const folder = await new Input ( { message: 'project name (leave empty for current folder):' } diff --git a/lib/snippets/readme/index.ts b/lib/snippets/readme/index.ts index 503a4b2..217ccc3 100644 --- a/lib/snippets/readme/index.ts +++ b/lib/snippets/readme/index.ts @@ -4,6 +4,10 @@ import { modify_json, apply_template } from '../../Helper'; import { get_readme } from './Assets'; export default class Readme implements Snippet { + public is_active (): boolean { + return true; + } + public async start (): Promise { const dev = await new Confirm ({ message: 'is the package used as dev dependency?',