Explorar el Código

fix: bench build command

- Add --apps option
- Add --production option
- Add --apps option for bench watch command
- Add --skip_frappe in esbuild
version-14
Faris Ansari hace 4 años
padre
commit
9f4edaedbb
Se han modificado 3 ficheros con 48 adiciones y 39 borrados
  1. +12
    -6
      esbuild/esbuild.js
  2. +11
    -19
      frappe/build.py
  3. +25
    -14
      frappe/commands/utils.py

+ 12
- 6
esbuild/esbuild.js Ver fichero

@@ -30,6 +30,10 @@ let argv = yargs
type: "string", type: "string",
description: "Run build for specific apps" description: "Run build for specific apps"
}) })
.option("skip_frappe", {
type: "boolean",
description: "Skip building frappe assets"
})
.option("watch", { .option("watch", {
type: "boolean", type: "boolean",
description: "Run in watch mode and rebuild on file changes" description: "Run in watch mode and rebuild on file changes"
@@ -44,7 +48,9 @@ let argv = yargs
) )
.version(false).argv; .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 WATCH_MODE = Boolean(argv.watch);
const PRODUCTION = Boolean(argv.production); const PRODUCTION = Boolean(argv.production);
const TOTAL_BUILD_TIME = `${chalk.black.bgGreen(" DONE ")} Total Build Time`; 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); assets_json = Object.assign({}, assets_json, out);


client.set("assets_json", JSON.stringify(assets_json), err => { 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 }) { async function notify_redis({ error, success }) {


+ 11
- 19
frappe/build.py Ver fichero

@@ -203,44 +203,36 @@ def setup():
app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules] 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""" """concat / minify js files"""
setup() setup()
make_asset_dirs(make_copy=make_copy, restore=restore) 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: if skip_frappe:
command += " --skip_frappe" command += " --skip_frappe"


frappe_app_path = os.path.abspath(os.path.join(app_paths[0], ".."))
check_yarn() check_yarn()
frappe_app_path = frappe.get_app_path("frappe", "..")
frappe.commands.popen(command, cwd=frappe_app_path, env=get_node_env()) 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""" """watch and rebuild if necessary"""
setup() 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() check_yarn()
frappe_app_path = frappe.get_app_path("frappe", "..") 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(): def check_yarn():


+ 25
- 14
frappe/commands/utils.py Ver fichero

@@ -15,34 +15,45 @@ from frappe.utils import get_bench_path, update_progress_bar, cint




@click.command('build') @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('--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('--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') @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('') 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 # 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 building frappe if assets exist remotely
skip_frappe = frappe.build.download_frappe_assets(verbose=verbose)
skip_frappe = download_frappe_assets(verbose=verbose)
else: else:
skip_frappe = False 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') @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.init('')
frappe.build.watch(True)
watch(apps)




@click.command('clear-cache') @click.command('clear-cache')


Cargando…
Cancelar
Guardar