Skip to content

Commit

Permalink
Merge pull request #7 from roedesh/develop
Browse files Browse the repository at this point in the history
Libtransistor support
  • Loading branch information
roedesh authored Jun 21, 2018
2 parents c66a048 + 39e6a76 commit c7eaeec
Show file tree
Hide file tree
Showing 24 changed files with 511 additions and 79 deletions.
54 changes: 44 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
[![Build status](https://travis-ci.org/roedesh/nxstart.svg?branch=master)](https://travis-ci.org/roedesh/nxstart)

## Features
- Generate a C/C++ ([libnx](https://github.com/switchbrew/libnx)) project using `nxstart cpp`
- Generate a Javascript ([BrewJS](https://github.com/BrewJS)) project using `nxstart js`
- Generate a [libnx](https://github.com/switchbrew/libnx) (C++) project using `nxstart libnx`
- Generate a [libtransistor](https://github.com/reswitched/libtransistor) (C) project using `nxstart libt`
- Generate a [BrewJS](https://github.com/BrewJS) (Javascript) project using `nxstart brewjs`
- Generate a [PyNX](https://github.com/nx-python/PyNX) (Python) project using `nxstart pynx`

## Installation

Expand All @@ -31,17 +33,19 @@ python setup.py install
```
You may need to run the above commands with ``sudo``.

## Creating a C/C++ (libnx) project
Run `nxstart cpp`. It will ask for a project name, author name and if you are
## Creating a libnx (C++) project
Run `nxstart libnx`. It will ask for a project name, author name and if you are
using CLion (IDE by Jetbrains). If you say yes to CLion, `CMakeLists.txt` will be included.

The following project structure will be created:

```
project
│ .editorconfig
│ .gitignore
│ CMakeLists.txt // Only if you use CLion
│ Makefile
│ icon.jpg
│ Makefile
│ README.md
└───data
Expand All @@ -52,19 +56,51 @@ project
│ main.cpp // Your main application file
```

## Creating a Javascript (BrewJS) project
Run `nxstart js`. It will ask for a project name and author name. The following project structure will be created:
## Creating a libtransistor (C) project
Run `nxstart libt`. It will ask for a project name, author name and if you are
using CLion (IDE by Jetbrains). If you say yes to CLion, `CMakeLists.txt` will be included.

The following project structure will be created:

```
project
│ .editorconfig
│ .editorconfig
│ .gitignore
│ CMakeLists.txt // Only if you use CLion
│ icon.jpg
│ main.c // Your main application file
│ Makefile
│ README.md
```

## Creating a BrewJS (Javascript) project
Run `nxstart brewjs`. It will ask for a project name and author name. The following project structure will be created:

```
project
│ .editorconfig
│ .gitignore
│ HOW-TO-RUN.txt // Explains how to run a BrewJS app on the Switch
│ index.js // Your main application file
│ README.md
└───assets
```

## Creating a PyNX (Python) project
Run `nxstart pynx`. It will ask for a project name and author name. The following project structure will be created:

```
project
│ .editorconfig
│ .gitignore
│ main.py // Your main application file
│ README.md
```

## Skip prompts
To skip the prompts, provide the necessary flags. For example:
```bash
Expand All @@ -76,5 +112,3 @@ Or if you don't use CLion:
nxstart -n "My new project" -a "John Doe" cpp --no-clion
```

Support for
[PyNX](https://github.com/nx-python/PyNX) projects will be added soon.
106 changes: 76 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ nx-start

Project generator for Nintendo Switch homebrews. A work in progress.

.. image:: https://travis-ci.org/roedesh/nxstart.svg?branch=master
:target: https://travis-ci.org/roedesh/nxstart



Features
========
- Generate a libnx (C++) project using ``nxstart libnx``
- Generate a libtransistor (C) project using ``nxstart libt``
- Generate a BrewJS (Javascript) project using ``nxstart brewjs``
- Generate a PyNX (Python) project using ``nxstart pynx``


Installation
============

Expand All @@ -29,41 +42,78 @@ Or, you can `download the source code <https://github.com/roedesh/nxstart>`_ for
You may need to run the above commands with ``sudo``.

Creating a C++ (libnx) project
===============
Run ``nxstart cpp``. It will ask for a project name, author name and if you are
Creating a libnx (C++) project
==============================
Run ``nxstart libnx``. It will ask for a project name, author name and if you are
using CLion (IDE by Jetbrains). If you say yes to CLion, ``CMakeLists.txt`` will be included.

The following project structure will be created:

.. code-block:: bash
project
│ CMakeLists.txt // Only if you use CLion
│ Makefile
│ icon.jpg
│ README.md
└───data
└───include
└───source
│ main.cpp // Your main application file
Creating a JS (BrewJS) project
===============
Run ``nxstart js``. It will ask for a project name, author name. The following project structure will be created:
project
│ .editorconfig
│ .gitignore
│ CMakeLists.txt // Only if you use CLion
│ Makefile
│ icon.jpg
│ README.md
└───data
└───include
└───source
│ main.cpp // Your main application file
Creating a libtransistor (C) project
====================================
Run ``nxstart libt``. It will ask for a project name, author name and if you are
using CLion (IDE by Jetbrains). If you say yes to CLion, ``CMakeLists.txt`` will be included.
The following project structure will be created:
.. code-block:: bash
project
│ .editorconfig
│ HOW-TO-RUN.txt // Explains how to run a BrewJS app on the Switch.
│ index.js // Your main application file
└───assets
project
│ .editorconfig
│ .gitignore
│ CMakeLists.txt // Only if you use CLion
│ main.c
│ Makefile
│ icon.jpg
│ README.md
Creating a BrewJS (Javascript) project
======================================
Run ``nxstart brewjs``. It will ask for a project name, author name. The following project structure will be created:
.. code-block:: bash
project
│ .editorconfig
│ .gitignore
│ HOW-TO-RUN.txt // Explains how to run a BrewJS app on the Switch.
│ index.js // Your main application file
│ README.md
└───assets
Creating a PyNX (Python) project
================================
Run ``nxstart pynx``. It will ask for a project name, author name. The following project structure will be created:
.. code-block:: bash
project
│ .editorconfig
│ .gitignore
│ main.py // Your main application file
│ README.md
Skip prompts
===============
Expand All @@ -78,7 +128,3 @@ Or if you don't use CLion:
.. code-block:: bash
$ nxstart -n "My new project" -a "John Doe" cpp --no-clion
Support for
`PyNX <https://github.com/nx-python/PyNX>`_ projects will be added soon.
27 changes: 25 additions & 2 deletions nxstart/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,36 @@ def libnx(name, author, clion, cwd):
filebuilder.generic.create_readme_file(folder_path, name)

if clion:
filebuilder.libnx.modify_cmake_lists_file(folder_path, folder_name)
filebuilder.generic.modify_cmake_lists_file(folder_path, folder_name)
else:
filebuilder.libnx.remove_cmake_lists_file(folder_path)
filebuilder.generic.remove_cmake_lists_file(folder_path)

click.echo("Successfully created the libnx project!")


def libt(name, author, clion, cwd):
"""
Function that holds the logic for the 'libt' command.
:param name: Name of the project
:param author: Name of the author
:param clion: Using CLion
:param cwd: Current working directory
"""
folder_name, folder_path = generate_folder_name_and_path(name, cwd)
check_and_create_directory(folder_path)

filebuilder.libt.create_libt_project(folder_path, name, author)
filebuilder.generic.create_readme_file(folder_path, name)

if clion:
filebuilder.generic.modify_cmake_lists_file(folder_path, folder_name)
else:
filebuilder.generic.remove_cmake_lists_file(folder_path)

click.echo("Successfully created the libtransistor project!")


def brewjs(name, author, cwd):
"""
Function that holds the logic for the 'brewjs' command.
Expand Down
28 changes: 19 additions & 9 deletions nxstart/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import click
import os

import py
import pytest
import sys

from nxstart import app


Expand All @@ -28,18 +32,24 @@ def __init__(self):
help='The full name of the author')
@pass_context
def cli(ctx, name, author):
ctx.name = name
ctx.author = author


@cli.command('libnx', short_help='create a new libnx project (C++)')
@click.option('--clion/--no-clion', default=False, prompt='Are you using CLion?', help='include CMakeLists.txt')
@pass_context
def libnx(ctx, clion):
"""
Main command group.
Command for generating a libnx project.
:param ctx: Context
:param name: Project name
:param author: Project author
:param clion: Using CLion
"""
ctx.name = name
ctx.author = author
app.libnx(ctx.name, ctx.author, clion, ctx.cwd)


@cli.command('libnx', short_help='generate a new libnx project')
@cli.command('libt', short_help='create a new libtransistor project (C)')
@click.option('--clion/--no-clion', default=False, prompt='Are you using CLion?', help='include CMakeLists.txt')
@pass_context
def libnx(ctx, clion):
Expand All @@ -52,7 +62,7 @@ def libnx(ctx, clion):
app.libnx(ctx.name, ctx.author, clion, ctx.cwd)


@cli.command('brewjs', short_help='generate a new BrewJS project')
@cli.command('brewjs', short_help='create a new BrewJS project (Javascript)')
@pass_context
def brewjs(ctx):
"""
Expand All @@ -63,11 +73,11 @@ def brewjs(ctx):
app.brewjs(ctx.name, ctx.author, ctx.cwd)


@cli.command('pynx', short_help='generate a new PyNX project')
@cli.command('pynx', short_help='create a new PyNX project (Python)')
@pass_context
def pynx(ctx):
"""
Command for generating a BrewJS project.
Command for generating a PyNX project.
:param ctx: Context
"""
Expand Down
2 changes: 1 addition & 1 deletion nxstart/filebuilder/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from nxstart.filebuilder import libnx, generic, brewjs, pynx
from nxstart.filebuilder import libnx, libt, generic, brewjs, pynx
21 changes: 21 additions & 0 deletions nxstart/filebuilder/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@ def create_readme_file(folder_path, name):
replace_in_file(new_readme_file, new_readme_file_replacements)


def remove_cmake_lists_file(folder_path):
"""
Removes the CMakeLists.txt file inside the folder at folder_path.
:param folder_path: Path to created folder
"""
cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt')
os.remove(cmake_lists_file)


def modify_cmake_lists_file(folder_path, folder_name):
"""
Modifies the CMakeLists.txt file from folder_path, and will use folder_name as the project name.
:param folder_path: Path to created folder
:param folder_name: Project folder name
"""
cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt')
cmake_lists_file_replacements = {
'FOLDER_NAME_PLACEHOLDER': folder_name
}
replace_in_file(cmake_lists_file, cmake_lists_file_replacements)
24 changes: 0 additions & 24 deletions nxstart/filebuilder/libnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,3 @@ def create_libnx_project(folder_path, name, author):
'APP_AUTHOR_PLACEHOLDER': author
}
replace_in_file(makefile, makefile_replacements)


def remove_cmake_lists_file(folder_path):
"""
Removes the CMakeLists.txt file inside the folder at folder_path.
:param folder_path: Path to created folder
"""
cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt')
os.remove(cmake_lists_file)


def modify_cmake_lists_file(folder_path, folder_name):
"""
Modifies the CMakeLists.txt file from folder_path, and will use folder_name as the project name.
:param folder_path: Path to created folder
:param folder_name: Project folder name
"""
cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt')
cmake_lists_file_replacements = {
'FOLDER_NAME_PLACEHOLDER': folder_name
}
replace_in_file(cmake_lists_file, cmake_lists_file_replacements)
Loading

0 comments on commit c7eaeec

Please sign in to comment.