Skip to content

Commit

Permalink
Merge pull request #410 from range-of-motion/409-use-npm-instead-of-yarn
Browse files Browse the repository at this point in the history
Use NPM instead of Yarn
  • Loading branch information
range-of-motion authored Aug 13, 2023
2 parents a55f8c5 + 9a64ea9 commit 82e666e
Show file tree
Hide file tree
Showing 8 changed files with 6,538 additions and 1,368 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
run: composer install --no-interaction
- name: Generate key
run: php artisan key:generate
- run: yarn install
- run: yarn build
- run: npm install --force
- run: npm run build
- name: Prepare database
run: php artisan migrate --database=testing
- name: Run PHPUnit
Expand Down Expand Up @@ -83,8 +83,8 @@ jobs:
run: composer install --no-interaction
- name: Generate key
run: php artisan key:generate
- run: yarn install
- run: yarn build
- run: npm install --force
- run: npm run build
- name: Prepare database
run: php artisan migrate --database=testing
- name: Run Dusk
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
.DS_Store
/public/build
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ RUN install-php-extensions pdo_mysql zip calendar gd
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install Node.js and Yarn
# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn
apt-get install -y nodejs

WORKDIR /var/www
35 changes: 5 additions & 30 deletions app/Console/Commands/BudgetInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace App\Console\Commands;

use Exception;
use Illuminate\Console\Command;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

class BudgetInstall extends Command
{
protected $signature = 'budget:install {--node-package-manager=}';
protected $signature = 'budget:install';
protected $description = 'Runs most of the commands needed to make Budget work';

public function __construct()
Expand All @@ -30,37 +29,13 @@ private function executeCommand($command): string
return $process->getOutput();
}

private function programExists(string $program): bool
{
try {
$this->executeCommand(['which', $program]);
} catch (Exception $e) {
return false;
}

return true;
}

public function handle(): void
{
$nodePackageManager = $this->option('node-package-manager');
$this->info('Installing Node.js packages');
$this->executeCommand(['npm', 'install']);

if (!$nodePackageManager) {
$nodePackageManager = $this->choice('Which package manager would you like to use for Node.js?', [
'npm',
'yarn',
]);
}

if (!$this->programExists($nodePackageManager)) {
$this->error('Could not find "' . $nodePackageManager . '", will not be able to compile front-end assets');
} else {
$this->info('Installing Node.js packages');
$this->executeCommand([$nodePackageManager, 'install']);

$this->info('Compiling front-end assets');
$this->executeCommand([$nodePackageManager, 'run', 'production']);
}
$this->info('Compiling front-end assets');
$this->executeCommand(['npm', 'run', 'production']);

$this->executeCommand(['cp', '.env.example', '.env']);
$this->executeCommand(['php', 'artisan', 'key:generate']);
Expand Down
14 changes: 1 addition & 13 deletions app/Console/Commands/BudgetUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,7 @@ public function handle(): void
shell_exec('php artisan migrate --force');

// Transpile front-end assets
$nodePackageManager = null;

if ($this->doesBinaryExist('npm')) {
$nodePackageManager = 'npm';
} elseif ($this->doesBinaryExist('yarn')) {
$nodePackageManager = 'yarn';
}

if (!$nodePackageManager) {
$this->warn('Neither NPM nor Yarn were found, could not update front-end assets');
} else {
shell_exec($nodePackageManager . ' install && ' . $nodePackageManager . ' run production');
}
shell_exec('npm run build');

// Destroy existing sessions
shell_exec('rm ' . storage_path() . '/framework/sessions/*');
Expand Down
4 changes: 2 additions & 2 deletions docker_boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ if [ ! -z $BUDGET_SETUP ]; then
php artisan key:generate
php artisan storage:link

yarn install
yarn build
npm install
npm run build

php artisan migrate --force
fi
Expand Down
Loading

0 comments on commit 82e666e

Please sign in to comment.