Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

# macOS
.DS_Store
24 changes: 24 additions & 0 deletions content/vanilla-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
15 changes: 15 additions & 0 deletions content/vanilla-app/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions content/vanilla-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions content/vanilla-app/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import './style.css'

document.querySelector('#app').innerHTML = `
<h1>Hello Vite!</h1>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
`
18 changes: 18 additions & 0 deletions content/vanilla-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "vanilla-app",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^2.9.9"
},
"main": "main.js",
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
8 changes: 8 additions & 0 deletions content/vanilla-app/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
35 changes: 20 additions & 15 deletions src/executeCommand.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
const { exec } = require('child_process');
const process = require('process');

const executeCommand = (command) =>
const executeCommand = (command, options = {}) =>
new Promise((resolve) => {
exec(`${command}`, (error, stdout, stderr) => {
if (error) {
exec(
`${command}`,
{ cwd: options?.cwd || process.cwd() },
(error, stdout, stderr) => {
if (error) {
resolve({
success: false,
});
}
if (stderr) {
resolve({
success: false,
});
}
resolve({
success: false,
success: true,
output: stdout,
});
}
if (stderr) {
resolve({
success: false,
});
}
resolve({
success: true,
output: stdout,
});
});
},
);
});

module.exports = executeCommand;
22 changes: 22 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chalk = require('chalk');
const { program } = require('commander');
const onCreateProject = require('./onCreateProject');
const onEditorConfig = require('./onEditorConfig');
const onESLint = require('./onESLint');
const onGitHubActions = require('./onGitHubActions');
Expand Down Expand Up @@ -103,4 +104,25 @@ program
)
.action(onGitHubActions);

program
.command('create project')
.description(
`
${chalk.blue.bold.underline('WHAT IT DOES')}:
Based on list of questionnaires, generates a project template using Vite.js
Ref: https://github.com/vitejs/vite/blob/main/packages/create-vite/README.md

${chalk.yellow.underline('Supported Templates')}:
- vanilla (generates a vanilla JavaScript project w/ support for HTML, CSS and JavaScript)

${chalk.blue.bold.underline('BEFORE YOU RUN')}:
- only run this command from the root of your project, otherwise project may not setup properly
`,
)
.option(
'-CT, --create-tag',
'automatically bumps patch version and creates tag on merge to `master` branch',
)
.action(onCreateProject);

program.parse();
6 changes: 3 additions & 3 deletions src/initializeGit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ const chalk = require('chalk');
const executeCommand = require('./executeCommand');
const isGitInitialized = require('./isGitInitialized');

const initializeGit = async () => {
if (isGitInitialized()) {
const initializeGit = async ({ path } = {}) => {
if (isGitInitialized(path)) {
console.log(
chalk.gray.bold(
`(ℹ) Looks like \`git\` is already initialized, skipping`,
),
);
} else {
console.log(chalk.gray('> Initializing git...'));
await executeCommand('git init');
await executeCommand('git init', { cwd: path });
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/isGitInitialized.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const process = require('process');
const doesDirectoryExist = require('./doesDirectoryExist');

const isGitInitialized = () =>
doesDirectoryExist(path.join(process.cwd(), '.git'));
const isGitInitialized = (p = process.cwd()) =>
doesDirectoryExist(path.join(p, '.git'));

module.exports = isGitInitialized;
89 changes: 89 additions & 0 deletions src/onCreateProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const path = require('path');
const process = require('process');
const chalk = require('chalk');
const { copySync } = require('fs-extra');
const inquirer = require('inquirer');
const doesDirectoryExist = require('./doesDirectoryExist');
const initializeGit = require('./initializeGit');

const createVanillaProject = ({ name, gitInit } = {}) => {
console.log(chalk.red('Generating `vanilla` project...'));
copySync(
path.join(process.cwd(), 'content/vanilla-app'),
path.join(process.cwd(), `${name}`),
);
if (gitInit) {
initializeGit({ path: path.join(process.cwd(), `${name}`) });
}
console.log(
chalk.green.bold('✅ Success! `vanilla` project has been created!'),
);
};

const onCreateProject = () => {
console.log(chalk.green.bold("👉 Let's create a project..."));
return inquirer
.prompt([
{
type: 'input',
name: 'name',
message: `${chalk.blue('Name?')} (i.e., 'todo-app')`,
validate(value) {
if (
!value ||
typeof value !== 'string' ||
!value.length ||
!/^[a-zA-Z-\d]+$/.test(value)
) {
return 'Please enter a valid project name (only letter, numbers and hyphens allowed)';
}
if (doesDirectoryExist(path.join(process.cwd(), `${value}`))) {
return `(ℹ) Looks like \`${value}\` directory already exists. Please retry creating a project with a different name`;
}
return true;
},
},
{
type: 'list',
name: 'template',
message: `${chalk.blue('Choose a template?')}`,
choices: [
{
key: 'v',
name: `${chalk.yellow.bold(
'Vanilla',
)} (generates a vanilla JavaScript project w/ support for HTML, CSS and JavaScript)`,
value: 'vanilla',
},
],
},
{
type: 'list',
name: 'gitInit',
message: `${chalk.blue.bold(
'Do you want to initialize git in your project?',
)}`,
choices: [
{
name: 'true',
value: true,
},
{
name: 'false',
value: false,
},
],
},
])
.then((projectOptions = {}) => {
const { name, template, gitInit = false } = projectOptions;
if (template === 'vanilla') {
createVanillaProject({ name, gitInit });
}
})
.catch((error) => {
throw error;
});
};

module.exports = onCreateProject;