Skip to content

Instantly share code, notes, and snippets.

@Ivanjosevera Ivanjosevera/main.js
Created May 15, 2019

What would you like to do?
import chalk from 'chalk';
import fs from 'fs';
import ncp from 'ncp';
import path from 'path';
import { promisify } from 'util';
const access = promisify(fs.access);
const copy = promisify(ncp);
async function copyTemplateFiles(options) {
return copy(options.templateDirectory, options.targetDirectory, {
clobber: false,
export async function createProject(options) {
options = {
targetDirectory: options.targetDirectory || process.cwd(),
const currentFileUrl = import.meta.url;
const templateDir = path.resolve(
new URL(currentFileUrl).pathname,
options.templateDirectory = templateDir;
try {
await access(templateDir, fs.constants.R_OK);
} catch (err) {
console.error('%s Invalid template name','ERROR'));
console.log('Copy project files');
await copyTemplateFiles(options);
console.log('%s Project ready','DONE'));
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.