You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/system/Bakery/Command/BuildAssets.php
+47-9Lines changed: 47 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,8 @@ protected function configure()
35
35
$this->setName("build-assets")
36
36
->setDescription("Build the assets using node and npm")
37
37
->setHelp("The build directory contains the scripts and configuration files required to download Javascript, CSS, and other assets used by UserFrosting. This command will install Gulp, Bower, and several other required npm packages locally. With <info>npm</info> set up with all of its required packages, it can be use it to automatically download and install the assets in the correct directories. For more info, see <comment>https://learn.userfrosting.com/basics/installation</comment>")
38
-
->addOption("compile", "c", InputOption::VALUE_NONE, "Compile the assets and asset bundles for production environment");
38
+
->addOption("compile", "c", InputOption::VALUE_NONE, "Compile the assets and asset bundles for production environment")
39
+
->addOption("force", "f", InputOption::VALUE_NONE, "Force assets compilation by deleting cached data and installed assets before proceeding");
39
40
}
40
41
41
42
/**
@@ -49,17 +50,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
49
50
// Set $path
50
51
$this->buildPath = $this->projectRoot . "/build";
51
52
53
+
// Delete cached data is requested
54
+
if ($input->getOption('force')) {
55
+
$this->clean();
56
+
}
57
+
52
58
// Perform tasks
53
59
$this->npmInstall();
54
60
$this->assetsInstall();
55
61
56
-
// Get current env mode
57
-
// N.B.: Need to touch the config service first to load dotenv values
58
-
$config = $this->ci->config;
59
-
$mode = getenv("UF_MODE") ?: '';
60
-
61
62
// Compile if requested
62
-
if ($input->getOption('compile') || $mode == "production") {
63
+
if ($input->getOption('compile') || $this->isProduction()) {
63
64
$this->buildAssets();
64
65
}
65
66
@@ -127,12 +128,49 @@ protected function checkAssets()
$this->io->error("Assets building seems to have failed. Directory `$vendorPath` is empty, but it shouldn't be. Check the above log for any errors.");
135
+
$this->io->error("Assets installation seems to have failed. Directory `$vendorPath` is empty, but it shouldn't be. Check the above log for any errors.");
135
136
exit(1);
136
137
}
138
+
139
+
// Check that `bundle.result.json` is present in production mode
if ($this->isProduction() && !file_exists($resultFile)) {
143
+
$this->io->error("Assets building seems to have failed. File `$resultFile` not found. This file is required for production envrionement. Check the above log for any errors.");
144
+
exit(1);
145
+
}
146
+
}
147
+
148
+
/**
149
+
* Run the `uf-clean` command to delete installed assets, delete compiled
150
+
* bundle config file and delete compiled assets
151
+
*
152
+
* @access protected
153
+
* @return void
154
+
*/
155
+
protectedfunctionclean()
156
+
{
157
+
$this->io->section("Cleaning cached data");
158
+
$this->io->writeln("> <comment>npm run uf-clean</comment>");
159
+
passthru("npm run uf-clean --prefix " . $this->buildPath);
160
+
}
161
+
162
+
/**
163
+
* Return if the app is in production mode
164
+
*
165
+
* @access protected
166
+
* @return bool
167
+
*/
168
+
protectedfunctionisProduction()
169
+
{
170
+
// N.B.: Need to touch the config service first to load dotenv values
0 commit comments