Skip to content

Commit f974b7b

Browse files
committed
Implements Asset Build Detection
Closes #493 - Verifies the presence of npm scripts - If present, prompts the user to choose a script to run prior to building/publishing NativePHP app. - Build command is optional and not necessarily required
1 parent b0a8aee commit f974b7b

File tree

4 files changed

+186
-18
lines changed

4 files changed

+186
-18
lines changed

resources/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "NativePHP",
2+
"name": "Laravel",
33
"version": "1.0.0",
44
"description": "A NativePHP Electron application",
55
"main": "./out/main/index.js",

resources/js/yarn.lock

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,10 @@
11211121
minimatch "^9.0.3"
11221122
plist "^3.1.0"
11231123

1124-
"@esbuild/linux-x64@0.21.5":
1124+
"@esbuild/darwin-arm64@0.21.5":
11251125
version "0.21.5"
1126-
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz"
1127-
integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==
1126+
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz"
1127+
integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==
11281128

11291129
"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0":
11301130
version "4.4.1"
@@ -1543,15 +1543,10 @@
15431543
resolved "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz"
15441544
integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==
15451545

1546-
"@rollup/rollup-linux-x64-gnu@4.29.1":
1546+
"@rollup/rollup-darwin-arm64@4.29.1":
15471547
version "4.29.1"
1548-
resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.29.1.tgz"
1549-
integrity sha512-87xYCwb0cPGZFoGiErT1eDcssByaLX4fc0z2nRM6eMtV9njAfEE6OW3UniAoDhX4Iq5xQVpE6qO9aJbCFumKYQ==
1550-
1551-
1552-
version "4.29.1"
1553-
resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.29.1.tgz"
1554-
integrity sha512-xufkSNppNOdVRCEC4WKvlR1FBDyqCSCpQeMMgv9ZyXqqtKBfkw1yfGMTUTs9Qsl6WQbJnsGboWCp7pJGkeMhKA==
1548+
resolved "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.29.1.tgz"
1549+
integrity sha512-2ORr7T31Y0Mnk6qNuwtyNmy14MunTAMx06VAPI6/Ju52W10zk1i7i5U3vlDRWjhOI5quBcrvhkCHyF76bI7kEw==
15551550

15561551
"@rushstack/eslint-patch@^1.10.4":
15571552
version "1.10.4"
@@ -1810,6 +1805,14 @@
18101805
resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz"
18111806
integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==
18121807

1808+
"@types/plist@^3.0.1":
1809+
version "3.0.5"
1810+
resolved "https://registry.npmjs.org/@types/plist/-/plist-3.0.5.tgz"
1811+
integrity sha512-E6OCaRmAe4WDmWNsL/9RMqdkkzDCY1etutkflWk4c+AcjDU07Pcz1fQwTX0TQz+Pxqn9i4L1TU3UFpjnrcDgxA==
1812+
dependencies:
1813+
"@types/node" "*"
1814+
xmlbuilder ">=11.0.1"
1815+
18131816
"@types/ps-node@^0.1.3":
18141817
version "0.1.3"
18151818
resolved "https://registry.npmjs.org/@types/ps-node/-/ps-node-0.1.3.tgz"
@@ -1854,6 +1857,11 @@
18541857
resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz"
18551858
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==
18561859

1860+
"@types/verror@^1.10.3":
1861+
version "1.10.10"
1862+
resolved "https://registry.npmjs.org/@types/verror/-/verror-1.10.10.tgz"
1863+
integrity sha512-l4MM0Jppn18hb9xmM6wwD1uTdShpf9Pn80aXTStnK1C94gtPvJcV2FrDmbOQUAQfJ1cKZHktkQUDwEqaAKXMMg==
1864+
18571865
"@types/yargs-parser@*":
18581866
version "21.0.3"
18591867
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz"
@@ -2048,7 +2056,7 @@ ajv-keywords@^3.4.1:
20482056
resolved "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz"
20492057
integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==
20502058

2051-
ajv@^6.12.0, ajv@^6.12.4, ajv@^6.9.1:
2059+
ajv@^6.10.0, ajv@^6.12.0, ajv@^6.12.4, ajv@^6.9.1:
20522060
version "6.12.6"
20532061
resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz"
20542062
integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==
@@ -2263,6 +2271,11 @@ array-union@^2.1.0:
22632271
resolved "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz"
22642272
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==
22652273

2274+
assert-plus@^1.0.0:
2275+
version "1.0.0"
2276+
resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz"
2277+
integrity sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==
2278+
22662279
astral-regex@^2.0.0:
22672280
version "2.0.0"
22682281
resolved "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz"
@@ -2517,7 +2530,7 @@ buffer-from@^1.0.0:
25172530
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz"
25182531
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
25192532

2520-
buffer@^5.5.0:
2533+
buffer@^5.1.0, buffer@^5.5.0:
25212534
version "5.7.1"
25222535
resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz"
25232536
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
@@ -2725,6 +2738,14 @@ cli-spinners@^2.5.0:
27252738
resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz"
27262739
integrity sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==
27272740

2741+
cli-truncate@^2.1.0:
2742+
version "2.1.0"
2743+
resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz"
2744+
integrity sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==
2745+
dependencies:
2746+
slice-ansi "^3.0.0"
2747+
string-width "^4.2.0"
2748+
27282749
cli-truncate@^4.0.0:
27292750
version "4.0.0"
27302751
resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-4.0.0.tgz"
@@ -2892,7 +2913,7 @@ core-js-compat@^3.38.0, core-js-compat@^3.38.1:
28922913
dependencies:
28932914
browserslist "^4.24.2"
28942915

2895-
core-util-is@~1.0.0:
2916+
core-util-is@~1.0.0, [email protected]:
28962917
version "1.0.2"
28972918
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz"
28982919
integrity sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==
@@ -2912,6 +2933,13 @@ crc-32@^1.2.0:
29122933
resolved "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz"
29132934
integrity sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==
29142935

2936+
crc@^3.8.0:
2937+
version "3.8.0"
2938+
resolved "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz"
2939+
integrity sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ==
2940+
dependencies:
2941+
buffer "^5.1.0"
2942+
29152943
crc32-stream@^4.0.2:
29162944
version "4.0.3"
29172945
resolved "https://registry.npmjs.org/crc32-stream/-/crc32-stream-4.0.3.tgz"
@@ -3119,6 +3147,20 @@ [email protected]:
31193147
optionalDependencies:
31203148
dmg-license "^1.0.11"
31213149

3150+
dmg-license@^1.0.11:
3151+
version "1.0.11"
3152+
resolved "https://registry.npmjs.org/dmg-license/-/dmg-license-1.0.11.tgz"
3153+
integrity sha512-ZdzmqwKmECOWJpqefloC5OJy1+WZBBse5+MR88z9g9Zn4VY+WYUkAyojmhzJckH5YbbZGcYIuGAkY5/Ys5OM2Q==
3154+
dependencies:
3155+
"@types/plist" "^3.0.1"
3156+
"@types/verror" "^1.10.3"
3157+
ajv "^6.10.0"
3158+
crc "^3.8.0"
3159+
iconv-corefoundation "^1.1.7"
3160+
plist "^3.0.4"
3161+
smart-buffer "^4.0.2"
3162+
verror "^1.10.0"
3163+
31223164
dot-prop@^9.0.0:
31233165
version "9.0.0"
31243166
resolved "https://registry.npmjs.org/dot-prop/-/dot-prop-9.0.0.tgz"
@@ -3720,6 +3762,11 @@ extract-zip@^2.0.0, extract-zip@^2.0.1:
37203762
optionalDependencies:
37213763
"@types/yauzl" "^2.9.1"
37223764

3765+
extsprintf@^1.2.0:
3766+
version "1.4.1"
3767+
resolved "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.1.tgz"
3768+
integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==
3769+
37233770
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
37243771
version "3.1.3"
37253772
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz"
@@ -3973,6 +4020,11 @@ fs.realpath@^1.0.0:
39734020
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
39744021
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
39754022

4023+
fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3:
4024+
version "2.3.3"
4025+
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
4026+
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
4027+
39764028
function-bind@^1.1.2:
39774029
version "1.1.2"
39784030
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
@@ -4345,6 +4397,14 @@ humanize-ms@^1.2.1:
43454397
dependencies:
43464398
ms "^2.0.0"
43474399

4400+
iconv-corefoundation@^1.1.7:
4401+
version "1.1.7"
4402+
resolved "https://registry.npmjs.org/iconv-corefoundation/-/iconv-corefoundation-1.1.7.tgz"
4403+
integrity sha512-T10qvkw0zz4wnm560lOEg0PovVqUXuOFhhHAkixw8/sycy7TJt7v/RrkEKEQnAw2viPSJu6iAkErxnzR0g8PpQ==
4404+
dependencies:
4405+
cli-truncate "^2.1.0"
4406+
node-addon-api "^1.6.3"
4407+
43484408
iconv-lite@^0.6.2:
43494409
version "0.6.3"
43504410
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz"
@@ -5663,6 +5723,11 @@ node-abi@^3.45.0:
56635723
dependencies:
56645724
semver "^7.3.5"
56655725

5726+
node-addon-api@^1.6.3:
5727+
version "1.7.2"
5728+
resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz"
5729+
integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==
5730+
56665731
node-api-version@^0.2.0:
56675732
version "0.2.0"
56685733
resolved "https://registry.npmjs.org/node-api-version/-/node-api-version-0.2.0.tgz"
@@ -5987,7 +6052,7 @@ pkg-dir@^4.2.0:
59876052
dependencies:
59886053
find-up "^4.0.0"
59896054

5990-
plist@^3.0.5, plist@^3.1.0:
6055+
plist@^3.0.4, plist@^3.0.5, plist@^3.1.0:
59916056
version "3.1.0"
59926057
resolved "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz"
59936058
integrity sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==
@@ -6687,6 +6752,15 @@ slash@^3.0.0:
66876752
resolved "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz"
66886753
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==
66896754

6755+
slice-ansi@^3.0.0:
6756+
version "3.0.0"
6757+
resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz"
6758+
integrity sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==
6759+
dependencies:
6760+
ansi-styles "^4.0.0"
6761+
astral-regex "^2.0.0"
6762+
is-fullwidth-code-point "^3.0.0"
6763+
66906764
slice-ansi@^4.0.0:
66916765
version "4.0.0"
66926766
resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz"
@@ -6704,7 +6778,7 @@ slice-ansi@^5.0.0:
67046778
ansi-styles "^6.0.0"
67056779
is-fullwidth-code-point "^4.0.0"
67066780

6707-
smart-buffer@^4.2.0:
6781+
smart-buffer@^4.0.2, smart-buffer@^4.2.0:
67086782
version "4.2.0"
67096783
resolved "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz"
67106784
integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==
@@ -7451,6 +7525,15 @@ vary@~1.1.2:
74517525
resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz"
74527526
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==
74537527

7528+
verror@^1.10.0:
7529+
version "1.10.1"
7530+
resolved "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz"
7531+
integrity sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==
7532+
dependencies:
7533+
assert-plus "^1.0.0"
7534+
core-util-is "1.0.2"
7535+
extsprintf "^1.2.0"
7536+
74547537
"vite@^4.0.0 || ^5.0.0", vite@^5.0.0:
74557538
version "5.4.11"
74567539
resolved "https://registry.npmjs.org/vite/-/vite-5.4.11.tgz"
@@ -7573,7 +7656,7 @@ xml-name-validator@^4.0.0:
75737656
resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz"
75747657
integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==
75757658

7576-
xmlbuilder@^15.1.1:
7659+
xmlbuilder@^15.1.1, xmlbuilder@>=11.0.1:
75777660
version "15.1.1"
75787661
resolved "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz"
75797662
integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==

src/Commands/BuildCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use Native\Electron\Concerns\LocatesPhpBinary;
99
use Native\Electron\Facades\Updater;
1010
use Native\Electron\Traits\InstallsAppIcon;
11+
use Native\Electron\Traits\ManagesAssetBuilding;
1112
use Native\Electron\Traits\OsAndArch;
1213

1314
class BuildCommand extends Command
1415
{
1516
use InstallsAppIcon;
1617
use LocatesPhpBinary;
18+
use ManagesAssetBuilding;
1719
use OsAndArch;
1820

1921
protected $signature = 'native:build
@@ -39,6 +41,8 @@ public function handle(): void
3941
echo $output;
4042
});
4143

44+
$this->checkAndBuildProjectAssets();
45+
4246
$os = $this->selectOs($this->argument('os'));
4347

4448
$this->installIcon();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace Native\Electron\Traits;
4+
5+
use Illuminate\Contracts\Process\ProcessResult;
6+
use Illuminate\Support\Facades\Process;
7+
use Symfony\Component\Process\Process as SymfonyProcess;
8+
9+
/**
10+
* Trait ManagesAssetBuilding
11+
* @package Native\Electron\Traits
12+
*/
13+
trait ManagesAssetBuilding
14+
{
15+
protected function detectNpmScripts()
16+
{
17+
$filePath = base_path('package.json');
18+
19+
if (!file_exists($filePath)) {
20+
return [];
21+
}
22+
23+
$packageFile = json_decode(file_get_contents($filePath), true);
24+
25+
return $packageFile['scripts'] ?? [];
26+
}
27+
28+
public function checkAndBuildProjectAssets(?string $buildCommand): null|ProcessResult
29+
{
30+
$scripts = $this->detectNpmScripts();
31+
32+
if (empty($scripts)) {
33+
return null;
34+
}
35+
36+
if (is_null($buildCommand)) {
37+
$runBuild = $this->confirm(
38+
'We\'ve detected some NPM scripts in your project. Would you like to build your project assets?',
39+
false
40+
);
41+
42+
if (!$runBuild) {
43+
return null;
44+
}
45+
46+
$buildCommand = $this->promptForAssetBuildCommand($scripts);
47+
}
48+
49+
if (!isset($scripts[$buildCommand])) {
50+
$this->error('Invalid script selected... Continuing...');
51+
52+
return null;
53+
}
54+
55+
$this->info('Building project assets…');
56+
57+
return $this->runProcess("npm run $buildCommand");
58+
}
59+
60+
private function promptForAssetBuildCommand(array $scripts): string
61+
{
62+
$this->info('Available NPM scripts:');
63+
64+
foreach ($scripts as $script => $command) {
65+
$this->line("{$script}: {$command}");
66+
}
67+
68+
return $this->choice('Which script would you like to run?', $scripts);
69+
}
70+
71+
private function runProcess(string $command): ProcessResult
72+
{
73+
// Run the process
74+
return Process::path(base_path())
75+
->forever()
76+
->tty(SymfonyProcess::isTtySupported() && ! $this->option('no-interaction'))
77+
->run($command, function (string $type, string $output) {
78+
echo $output;
79+
});
80+
}
81+
}

0 commit comments

Comments
 (0)