Compare commits

..

No commits in common. "f4b7366d4994ee542cf4c87807e5eec4871a75c0" and "f0a67a5d84b4f84ba5fd0e7b669b66af60351d49" have entirely different histories.

8 changed files with 47 additions and 70 deletions

View File

@ -1,57 +1,60 @@
# @sapphirecode/snippeteer # 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 ## Installation
> npm i -g @sapphirecode/snippeteer 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)
## Requirements ```npmrc
@scode:registry=https://npm.scode.ovh
```
installed on the system: then install the module using the following command
- yarn ```sh
- git npm i -g @scode/snippeteer
```
## Usage ## Usage
run `snippeteer` in console and choose a snippet, all necessary parameters will ```sh
be asked interactively snippeteer [snippet] [..args]
```
### Snippets All snippets will be executed relative to your current working directory!
#### copyright ## Snippets
add copyright notice to .js, .ts and .mjs files, as well was generating a ### Snippet
license file and adding fields like author and license to the package.json
#### jenkins Creates a new snippet template
create a generic jenkinsfile ```sh
snippeteer snippet [name]
```
for node projects: automatically generates a jenkinsfile and jenkins.js for easy ### Node
use in jenkins.
necessary scripts in the package.json: Creates a new nodejs project
- ci: `yarn --frozen-lockfile && node jenkins.js` ```sh
- compile: `tsc` or snippeteer node [name]
`tsc --allowJs --declaration --emitDeclarationOnly index.js`, ... ```
compile should be the general compile task, for typescript: tsc, for commonjs: ### Jenkins
creating type definitions, ...
#### node Adds files necessary for jenkins
initializes a node project with the standard structure used by sapphirecode optionally with a js script for npm modules by adding 'node' as argument
modules
#### readme ```sh
snippeteer jenkins [node]
```
create a template readme file ### Vue
## License Adds files, dependencies and scripts for vue to a nodejs project
BSD-3-Clause © Timo Hocker <timo@scode.ovh> ```sh
snippeteer vue
```

View File

@ -6,6 +6,5 @@
*/ */
export interface Snippet { export interface Snippet {
is_active(): boolean;
start(cwd: string): Promise<void>; start(cwd: string): Promise<void>;
} }

View File

@ -12,22 +12,17 @@ import { Snippet } from './Snippet';
(async (): Promise<void> => { (async (): Promise<void> => {
const snippets = await fs.readdir (path.join (__dirname, 'snippets')); const snippets = await fs.readdir (path.join (__dirname, 'snippets'));
const runners: Record<string, Snippet> = {}; const snippet = await new AutoComplete (
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', name: 'snippet',
message: 'choose a snippet', message: 'choose a snippet',
choices: snippets.filter ((s) => runners[s].is_active ()) choices: snippets
}) }
)
.run (); .run ();
runners[snippet].start (process.cwd ()); const runner
= new (await import (`./snippets/${snippet}/index.js`)).default as Snippet;
runner.start (process.cwd ());
}) () }) ()
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
.catch ((e) => console.log (e)); .catch ((e) => console.log (e));

View File

@ -19,10 +19,6 @@ import { FileMapper } from './file_mapper';
import { CopyrightOptions } from './copyright_options'; import { CopyrightOptions } from './copyright_options';
export default class Copyright implements Snippet { export default class Copyright implements Snippet {
public is_active (): boolean {
return true;
}
private _options: CopyrightOptions | null = null; private _options: CopyrightOptions | null = null;
private _cwd = ''; private _cwd = '';
private _loaded_from_config = false; private _loaded_from_config = false;

View File

@ -8,11 +8,7 @@
import { Snippet } from '../../Snippet'; import { Snippet } from '../../Snippet';
export default class Database implements Snippet { export default class Database implements Snippet {
public is_active (): boolean {
return false;
}
public start (): Promise<void> { public start (): Promise<void> {
return Promise.resolve (); return new Promise ((res) => res ());
} }
} }

View File

@ -12,10 +12,6 @@ import { apply_template, modify_json } from '../../Helper';
import { general, node } from './Assets'; import { general, node } from './Assets';
export default class Jenkins implements Snippet { export default class Jenkins implements Snippet {
public is_active (): boolean {
return true;
}
public async start (): Promise<void> { public async start (): Promise<void> {
const is_node = await new Confirm ({ const is_node = await new Confirm ({
message: 'is the current project using nodejs?', message: 'is the current project using nodejs?',

View File

@ -56,10 +56,6 @@ async function init_package (
} }
export default class Node implements Snippet { export default class Node implements Snippet {
public is_active (): boolean {
return true;
}
public async start (): Promise<void> { public async start (): Promise<void> {
const folder = await new Input ( const folder = await new Input (
{ message: 'project name (leave empty for current folder):' } { message: 'project name (leave empty for current folder):' }

View File

@ -4,10 +4,6 @@ import { modify_json, apply_template } from '../../Helper';
import { get_readme } from './Assets'; import { get_readme } from './Assets';
export default class Readme implements Snippet { export default class Readme implements Snippet {
public is_active (): boolean {
return true;
}
public async start (): Promise<void> { public async start (): Promise<void> {
const dev = await new Confirm ({ const dev = await new Confirm ({
message: 'is the package used as dev dependency?', message: 'is the package used as dev dependency?',