2020-04-18 17:43:13 +02:00

47 lines
1.5 KiB
TypeScript

/*
* 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 <timo@scode.ovh>, April 2020
*/
import path from 'path';
import { Input } from 'enquirer';
import { Snippet } from '../../Snippet';
import { apply_template, modify_json, run_command } from '../../Helper';
import eslintrc from './template/eslintrc.asset';
import npmrc from './template/npmrc.asset';
import index from './template/index.asset';
import gitignore from './template/gitignore.asset';
export class Node implements Snippet {
public async start (): Promise<void> {
const folder = await new Input (
{ message: 'project name (leave empty for current folder):' }
)
.run ();
await apply_template (eslintrc, path.join (folder, '.eslintrc.js'));
await apply_template (npmrc, path.join (folder, '.npmrc'));
await apply_template (index, path.join (folder, 'index.js'));
await apply_template (gitignore, path.join (folder, '.gitignore'));
await run_command ('git init', folder);
await run_command ('yarn init -y', folder);
await run_command (
'yarn add --dev @scode/eslint-config eslint nyc ava',
folder
);
await modify_json ((obj: Record<string, unknown>) => {
obj.scripts = {
lint: 'eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs',
test: 'nyc ava'
};
return obj;
}, path.join (folder, 'package.json'));
}
}