Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the -d option to init command #11

Merged
merged 2 commits into from
Dec 30, 2023
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.5 - WIP

- Adding the option `-d` for the `init` command to initialize the ebook in a different directory

## 1.0.4 - 28th December 2023

- Adding the option for customizing the working path (the directory with the assets folder)
Expand Down
39 changes: 32 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ composer require hi-folks/ibis-next

Once the tool is installed, you will find the `vendor/` directory where you can find your new tool (`vendor/bin/ibis-next`).

Now you can initialize properly the directory via the `init` command for automatically creating the configuration file, the assets folder, and the content folder (for creating your Markdown files).
To launch the `init`` command:
If you install Ibis Next locally, in a specific directory, to launch and run Ibis Next you need to define the path like this:

~~~shell
./vendor/bin/ibis-next init
./vendor/bin/ibis-next list
~~~

### Installing ibis-next globally
Expand All @@ -59,7 +58,23 @@ Instead, if you prefer to install the composer package globally you can add the
composer global require hi-folks/ibis-next
~~~

Then, run this command inside an **empty directory**:
If you install Ibis Next globally, to launch and run Ibis Next you can use the `ibis-next` like this:

~~~shell
ibis-next list
~~~

## Initializing the ebook


Now you can initialize properly the directory via the `init` command for automatically creating the configuration file, the assets folder, and the content folder (for creating your Markdown files).
If you installed Ibis Next locally, to launch the `init` command:

~~~shell
./vendor/bin/ibis-next init
~~~

If you installed Ibis Next globally, you can run the `init` command inside an empty directory:

~~~shell
ibis-next init
Expand All @@ -78,6 +93,16 @@ This will create the following files and directories:

You may configure your book by editing the `ibis.php` configuration file.

### Setting a specific directory

If you want to initialize a specific empty directory (not the current one), you can use the `-d` option while you are running the `init` command, for example:

~~~shell
ibis-next init -d ../some-other-directory
~~~

This is helpful for example if you want to install Ibis Next once and you want to create and manage multiple books.

## Writing Your eBook

The `init` command will create sample .md files inside the `content` folder. You can explore those files to see how you can write your book.
Expand All @@ -88,15 +113,15 @@ Inside the `content` directory, you can write multiple `.md` files. Ibis uses th
~~~markdown
# Part 1

<h1> tags define the start of a part. A separate PDF page will be generated to print the part title and any content below.
`<h1>` tags define the start of a part. A separate PDF page will be generated to print the part title and any content below.

## Chapter 1

<h2> tags define the start of a chapter. A chapter starts on a new page always.
`<h2>` tags define the start of a chapter. A chapter starts on a new page always.

### Starting with Ibis

<h3> tags define different titles inside a chapter.
`<h3>` tags define different titles inside a chapter.
~~~

### Adding different quotes
Expand Down
29 changes: 27 additions & 2 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class InitCommand extends Command
Expand All @@ -13,6 +14,7 @@ class InitCommand extends Command

private ?\Illuminate\Filesystem\Filesystem $disk = null;


/**
* Configure the command.
*
Expand All @@ -22,7 +24,14 @@ protected function configure()
{
$this
->setName('init')
->setDescription('Initialize a new project in the current directory.');
->addOption(
'workingdir',
'd',
InputOption::VALUE_OPTIONAL,
'The path of the working directory where `ibis.php` and `assets` directory will be created',
''
)
->setDescription('Initialize a new project in the working directory (current dir by default).');
}

/**
Expand All @@ -36,7 +45,23 @@ public function execute(InputInterface $input, OutputInterface $output): int
$this->disk = new Filesystem();
$this->output = $output;

$currentPath = getcwd();
$workingPath = $input->getOption('workingdir');
if ($workingPath === "") {
$workingPath = "./";
} elseif (!is_dir($workingPath)) {
$workingPath = "./";
}
$ibisConfigPath = $workingPath . '/ibis.php';
$contentPath = $workingPath . '/content/';

$this->output->writeln('<info>Creating config/assets directory as: ' . $workingPath . '</info>');
$this->output->writeln('<info>Creating config file as: ' . $ibisConfigPath . '</info>');
$this->output->writeln('<info>Creating content directory as: ' . $contentPath . '</info>');




$currentPath = $workingPath;

if ($this->disk->isDirectory($currentPath . '/assets')) {
$this->output->writeln('');
Expand Down
Loading