54 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-04-18 17:24:41 +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.
* 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';
2020-04-23 17:07:54 +02:00
import { eslintrc, gitignore, npmrc, tsconfig } from './Assets';
2020-04-18 17:24:41 +02:00
2020-04-18 19:00:27 +02:00
export default class Node implements Snippet {
2020-04-18 17:24:41 +02:00
public async start (): Promise<void> {
const folder = await new Input (
{ message: 'project name (leave empty for current folder):' }
)
.run ();
2020-04-23 16:19:31 +02:00
const use_ts = await new confirm ({
message: 'use typescript?',
initial: false
})
.run ();
2020-04-18 17:24:41 +02:00
await apply_template (eslintrc, path.join (folder, '.eslintrc.js'));
await apply_template (npmrc, path.join (folder, '.npmrc'));
await apply_template (gitignore, path.join (folder, '.gitignore'));
2020-04-23 16:19:31 +02:00
if (use_ts)
await apply_template (tsconfig, path.join (folder, 'tsconfig.json'));
2020-04-18 17:24:41 +02:00
2020-04-18 19:00:27 +02:00
run_command ('git init', folder);
run_command ('yarn init -y', folder);
run_command (
2020-04-23 16:19:31 +02:00
`yarn add --dev @scode/eslint-config${use_ts
? '-ts typescript @ava/typescript'
: ''} eslint nyc ava`,
2020-04-18 17:24:41 +02:00
folder
);
2020-04-18 17:43:13 +02:00
await modify_json ((obj: Record<string, unknown>) => {
2020-04-18 17:24:41 +02:00
obj.scripts = {
lint: 'eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs',
test: 'nyc ava'
};
2020-04-23 16:38:29 +02:00
if (use_ts)
obj.scripts.compile = 'tsc';
2020-04-18 17:24:41 +02:00
return obj;
}, path.join (folder, 'package.json'));
}
}