- Add --apps option - Add --production option - Add --apps option for bench watch command - Add --skip_frappe in esbuildversion-14
@@ -30,6 +30,10 @@ let argv = yargs | |||
type: "string", | |||
description: "Run build for specific apps" | |||
}) | |||
.option("skip_frappe", { | |||
type: "boolean", | |||
description: "Skip building frappe assets" | |||
}) | |||
.option("watch", { | |||
type: "boolean", | |||
description: "Run in watch mode and rebuild on file changes" | |||
@@ -44,7 +48,9 @@ let argv = yargs | |||
) | |||
.version(false).argv; | |||
const APPS = !argv.apps ? app_list : argv.apps.split(","); | |||
const APPS = (!argv.apps ? app_list : argv.apps.split(",")).filter( | |||
app => !(argv.skip_frappe && app == "frappe") | |||
); | |||
const WATCH_MODE = Boolean(argv.watch); | |||
const PRODUCTION = Boolean(argv.production); | |||
const TOTAL_BUILD_TIME = `${chalk.black.bgGreen(" DONE ")} Total Build Time`; | |||
@@ -294,13 +300,13 @@ function write_meta_file(metafile) { | |||
assets_json = Object.assign({}, assets_json, out); | |||
client.set("assets_json", JSON.stringify(assets_json), err => { | |||
if (err) { | |||
log_warn("Could not update assets_json in redis_cache"); | |||
} | |||
client.unref(); | |||
if (err) { | |||
log_warn("Could not update assets_json in redis_cache"); | |||
} | |||
client.unref(); | |||
}); | |||
}); | |||
}); | |||
}); | |||
} | |||
async function notify_redis({ error, success }) { | |||
@@ -203,44 +203,36 @@ def setup(): | |||
app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules] | |||
def get_node_pacman(): | |||
exec_ = find_executable("yarn") | |||
if exec_: | |||
return exec_ | |||
raise ValueError("Yarn not found") | |||
def bundle(no_compress, app=None, make_copy=False, restore=False, verbose=False, skip_frappe=False): | |||
def bundle(mode, apps=None, make_copy=False, restore=False, verbose=False, skip_frappe=False): | |||
"""concat / minify js files""" | |||
setup() | |||
make_asset_dirs(make_copy=make_copy, restore=restore) | |||
pacman = get_node_pacman() | |||
mode = "build" if no_compress else "production" | |||
command = "{pacman} run {mode}".format(pacman=pacman, mode=mode) | |||
mode = "production" if mode == "production" else "build" | |||
command = "yarn run {mode}".format(mode=mode) | |||
if app: | |||
command += " --app {app}".format(app=app) | |||
if apps: | |||
command += " --apps {apps}".format(apps=apps) | |||
if skip_frappe: | |||
command += " --skip_frappe" | |||
frappe_app_path = os.path.abspath(os.path.join(app_paths[0], "..")) | |||
check_yarn() | |||
frappe_app_path = frappe.get_app_path("frappe", "..") | |||
frappe.commands.popen(command, cwd=frappe_app_path, env=get_node_env()) | |||
def watch(no_compress): | |||
def watch(apps=None): | |||
"""watch and rebuild if necessary""" | |||
setup() | |||
pacman = get_node_pacman() | |||
command = "yarn run watch" | |||
if apps: | |||
command += " --apps {apps}".format(apps=apps) | |||
frappe_app_path = os.path.abspath(os.path.join(app_paths[0], "..")) | |||
check_yarn() | |||
frappe_app_path = frappe.get_app_path("frappe", "..") | |||
frappe.commands.popen("{pacman} run watch".format(pacman=pacman), | |||
cwd=frappe_app_path, env=get_node_env()) | |||
frappe.commands.popen(command, cwd=frappe_app_path, env=get_node_env()) | |||
def check_yarn(): | |||
@@ -15,34 +15,45 @@ from frappe.utils import get_bench_path, update_progress_bar, cint | |||
@click.command('build') | |||
@click.option('--app', help='Build assets for app') | |||
@click.option('--app', help='Build assets for specific app') | |||
@click.option('--apps', help='Build assets for specific apps') | |||
@click.option('--make-copy', is_flag=True, default=False, help='Copy the files instead of symlinking') | |||
@click.option('--restore', is_flag=True, default=False, help='Copy the files instead of symlinking with force') | |||
@click.option('--verbose', is_flag=True, default=False, help='Verbose') | |||
@click.option('--production', is_flag=True, default=False, help='Build assets in production mode') | |||
@click.option('--force', is_flag=True, default=False, help='Force build assets instead of downloading available') | |||
def build(app=None, make_copy=False, restore=False, verbose=False, force=False): | |||
"Minify + concatenate JS and CSS files, build translations" | |||
import frappe.build | |||
@click.option('--verbose', is_flag=True, default=False, help='Verbose') | |||
def build(app=None, apps=None, make_copy=False, restore=False, production=False, verbose=False, force=False): | |||
"Compile JS and CSS source files" | |||
from frappe.build import bundle, download_frappe_assets | |||
frappe.init('') | |||
# don't minify in developer_mode for faster builds | |||
no_compress = frappe.local.conf.developer_mode or False | |||
if not apps and app: | |||
apps = app | |||
# dont try downloading assets if force used, app specified or running via CI | |||
if not (force or app or os.environ.get('CI')): | |||
if not (force or apps or os.environ.get('CI')): | |||
# skip building frappe if assets exist remotely | |||
skip_frappe = frappe.build.download_frappe_assets(verbose=verbose) | |||
skip_frappe = download_frappe_assets(verbose=verbose) | |||
else: | |||
skip_frappe = False | |||
frappe.build.bundle(no_compress, app=app, make_copy=make_copy, restore=restore, verbose=verbose, skip_frappe=skip_frappe) | |||
# don't minify in developer_mode for faster builds | |||
development = frappe.local.conf.developer_mode or frappe.local.dev_server | |||
mode = "development" if development else "production" | |||
if production: | |||
mode = "production" | |||
bundle(mode, apps=apps, make_copy=make_copy, restore=restore, verbose=verbose, skip_frappe=skip_frappe) | |||
@click.command('watch') | |||
def watch(): | |||
"Watch and concatenate JS and CSS files as and when they change" | |||
import frappe.build | |||
@click.option('--apps', help='Watch assets for specific apps') | |||
def watch(apps=None): | |||
"Watch and compile JS and CSS files as and when they change" | |||
from frappe.build import watch | |||
frappe.init('') | |||
frappe.build.watch(True) | |||
watch(apps) | |||
@click.command('clear-cache') | |||