Compare commits

...

2 Commits

Author SHA1 Message Date
f4b7366d49 readme 2020-05-11 12:12:28 +02:00
4e76cf3d5c disable wip snippets 2020-05-11 12:01:39 +02:00
8 changed files with 70 additions and 47 deletions

View File

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

View File

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

View File

@ -12,17 +12,22 @@ import { Snippet } from './Snippet';
(async (): Promise<void> => {
const snippets = await fs.readdir (path.join (__dirname, 'snippets'));
const snippet = await new AutoComplete (
{
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
}
)
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));

View File

@ -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;

View File

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

View File

@ -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<void> {
const is_node = await new Confirm ({
message: 'is the current project using nodejs?',

View File

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

View File

@ -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<void> {
const dev = await new Confirm ({
message: 'is the package used as dev dependency?',