diff --git a/index.js b/index.js index 7312a0f..dcbabf4 100644 --- a/index.js +++ b/index.js @@ -23,34 +23,34 @@ async function main() { const __dirname = dirname(fileURLToPath(import.meta.url)); actions.intro(); // - const project_name = await input({ message: 'Name your project:' }); - const selected_template = await select({ + const projectName = await input({ message: 'Name your project:' }); + const selectedTemplate = await select({ message: 'Select your template', choices: PROJECTS, }); - const template_path = `${__dirname}/src/templates/${selected_template}`; - mkdir(`${CURRENT_DIRECTORY}/${project_name}`); + const templatePath = `${__dirname}/src/templates/${selectedTemplate}`; + mkdir(`${CURRENT_DIRECTORY}/${projectName}`); - actions.create_resources(template_path, project_name); + actions.createResources(templatePath, projectName); // - const install_dependencies = await confirm({ + const installDependencies = await confirm({ message: 'Install dependencies ?', }); - if (install_dependencies) { - actions.install_dependencies(project_name); + if (installDependencies) { + actions.installDependencies(projectName); } - const init_rep = await confirm({ + const initRepo = await confirm({ message: 'Initialize repository ?', }); - if (init_rep) { - actions.init_repo(project_name); + if (initRepo) { + actions.initRepo(projectName); } - actions.outro(project_name); + actions.outro(projectName); } main(); diff --git a/src/actions.js b/src/actions.js index 1d1fd61..4c716d0 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,12 +1,12 @@ import { log, info, success, warn } from './console.js'; import { copy, - get_file_extension, - is_media_file, + getFileExtension, + isMediaFile, mkdir, - read_file, - run_command, - write_file, + readFile, + runCommand, + writeFile, } from './utils.js'; import * as fs from 'fs'; @@ -23,66 +23,66 @@ function intro() { log(''); } -function create_resources(target_path, project_name) { - const resources_to_create = fs.readdirSync(target_path); +function createResources(targetPath, projectName) { + const resourcesToCreate = fs.readdirSync(targetPath); // - resources_to_create.forEach((resource) => { - const resource_path = `${target_path}/${resource}`; - const resource_stats = fs.statSync(resource_path); + resourcesToCreate.forEach((resource) => { + const resourcePath = `${targetPath}/${resource}`; + const resourceStats = fs.statSync(resourcePath); - if (resource_stats.isDirectory()) { - mkdir(`${CURRENT_DIRECTORY}/${project_name}/${resource}`); - create_resources( - `${target_path}/${resource}`, - `${project_name}/${resource}` + if (resourceStats.isDirectory()) { + mkdir(`${CURRENT_DIRECTORY}/${projectName}/${resource}`); + createResources( + `${targetPath}/${resource}`, + `${projectName}/${resource}` ); - } else if (resource_stats.isFile()) { - const file_extension = get_file_extension(resource_path); + } else if (resourceStats.isFile()) { + const fileExtension = getFileExtension(resourcePath); - if (is_media_file(file_extension)) { - copy(resource_path, `${CURRENT_DIRECTORY}/${project_name}/${resource}`); + if (isMediaFile(fileExtension)) { + copy(resourcePath, `${CURRENT_DIRECTORY}/${projectName}/${resource}`); } else { // if (resource === 'package.json') { - const package_json = JSON.parse( - read_file(`${target_path}/package.json`) + const packageJSON = JSON.parse( + readFile(`${targetPath}/package.json`) ); - package_json.name = project_name; - write_file( - `${CURRENT_DIRECTORY}/${project_name}/package.json`, - JSON.stringify(package_json, null, 2) + packageJSON.name = projectName; + writeFile( + `${CURRENT_DIRECTORY}/${projectName}/package.json`, + JSON.stringify(packageJSON, null, 2) ); } else { if (resource === 'gitignore') { resource = '.gitignore'; } - const file_content = read_file(resource_path); - const write_path = `${CURRENT_DIRECTORY}/${project_name}/${resource}`; - write_file(write_path, file_content); + const fileContent = readFile(resourcePath); + const writePath = `${CURRENT_DIRECTORY}/${projectName}/${resource}`; + writeFile(writePath, fileContent); } } } }); } -function install_dependencies(project_name) { - const installed = run_command(`cd ${project_name} && npm i`); +function installDependencies(projectName) { + const installed = runCommand(`cd ${projectName} && npm i`); if (!installed) warn('Unable to install dependencies'); } -function init_repo(project_name) { - const installed = run_command(`cd ${project_name} && git init`); +function initRepo(projectName) { + const installed = runCommand(`cd ${projectName} && git init`); if (!installed) warn('Unable to init repo'); } -function outro(project_name) { +function outro(projectName) { log(''); success(' Ready! '); - log(`- cd ${project_name}`); + log(`- cd ${projectName}`); log(`- npm run dev`); } export const actions = { intro, - create_resources, - init_repo, - install_dependencies, + createResources, + initRepo, + installDependencies, outro, }; diff --git a/src/templates/javascript/src/sample/scenes/level.scene.js b/src/templates/javascript/src/sample/scenes/level.scene.js index 12da067..47c3620 100644 --- a/src/templates/javascript/src/sample/scenes/level.scene.js +++ b/src/templates/javascript/src/sample/scenes/level.scene.js @@ -40,7 +40,7 @@ export class LevelScene extends Scene { const paddle = this.createPaddle(engine); paddle.on('postupdate', () => { - const offsetX = 10; + const offsetX = 0; const hitLimits = { screenLeft: paddle.pos.x - paddle.width / 2 < 0 + offsetX, screenRight: paddle.pos.x + paddle.width / 2 > engine.drawWidth, diff --git a/src/utils.js b/src/utils.js index b3849df..afee3c0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -3,7 +3,7 @@ import { execSync } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; -export function run_command(command) { +export function runCommand(command) { try { execSync(`${command}`, { stdio: 'inherit' }); } catch (e) { @@ -13,27 +13,26 @@ export function run_command(command) { } return true; } -export function get_file_extension(filePath) { +export function getFileExtension(filePath) { return path.extname(filePath).slice(1); } -export function is_media_file(file_extension) { - const media_extensions = ['png', 'mp3', 'wav', 'ogg', 'ico']; - const result = media_extensions.some( - (media_ext) => media_ext === file_extension.toLowerCase() +export function isMediaFile(fileExtension) { + const mediaExtensions = ['png', 'mp3', 'wav', 'ogg', 'ico']; + const result = mediaExtensions.some( + (extension) => extension === fileExtension.toLowerCase() ); return result; } export function mkdir(path) { fs.mkdirSync(path); } -export function read_file(path, encoding = 'utf-8') { +export function readFile(path, encoding = 'utf-8') { return fs.readFileSync(path, encoding); } -export function write_file(path, content, encoding = 'utf-8') { +export function writeFile(path, content, encoding = 'utf-8') { fs.writeFileSync(path, content, encoding); } export function copy(from, to) { - // fs.copyFileSync(from, to); const sourceStream = fs.createReadStream(from); const destinationStream = fs.createWriteStream(to);