|
12 | 12 | NPM_INSTALL_COMMANDS = ["npm install", "npm install meow@9.0.0"]
|
13 | 13 | BUNDLE_COMMAND = "npm run bundle --prefix=browser/components/newtab"
|
14 | 14 |
|
| 15 | + |
15 | 16 | def install_dependencies():
|
16 |
| - if not os.path.isdir(NEW_TAB_DIR): |
17 |
| - logging.error(f"Directory not found: {NEW_TAB_DIR}") |
18 |
| - raise FileNotFoundError(f"New tab directory {NEW_TAB_DIR} does not exist") |
19 |
| - |
20 |
| - for command in NPM_INSTALL_COMMANDS: |
21 |
| - try: |
22 |
| - logging.info(f"Running command: {command} in {NEW_TAB_DIR}") |
23 |
| - subprocess.run( |
24 |
| - command.split(), |
25 |
| - cwd=NEW_TAB_DIR, |
26 |
| - check=True, |
27 |
| - capture_output=True, |
28 |
| - text=True |
29 |
| - ) |
30 |
| - logging.info(f"Successfully executed: {command}") |
31 |
| - except subprocess.CalledProcessError as e: |
32 |
| - logging.error(f"Command failed: {command} - {e.stderr}") |
33 |
| - raise |
| 17 | + if not os.path.isdir(NEW_TAB_DIR): |
| 18 | + logging.error(f"Directory not found: {NEW_TAB_DIR}") |
| 19 | + raise FileNotFoundError(f"New tab directory {NEW_TAB_DIR} does not exist") |
34 | 20 |
|
35 |
| -def bundle_newtab_components(): |
36 |
| - if not os.path.isdir(ENGINE_DIR): |
37 |
| - logging.error(f"Directory not found: {ENGINE_DIR}") |
38 |
| - raise FileNotFoundError(f"Engine directory {ENGINE_DIR} does not exist") |
39 |
| - |
| 21 | + for command in NPM_INSTALL_COMMANDS: |
40 | 22 | try:
|
41 |
| - logging.info(f"Bundling newtab components in {ENGINE_DIR}") |
42 |
| - result = subprocess.run( |
43 |
| - BUNDLE_COMMAND.split(), |
44 |
| - cwd=ENGINE_DIR, |
45 |
| - check=True, |
46 |
| - capture_output=True, |
47 |
| - text=True |
48 |
| - ) |
49 |
| - logging.info(f"Bundle completed successfully: {result.stdout}") |
| 23 | + logging.info(f"Running command: {command} in {NEW_TAB_DIR}") |
| 24 | + subprocess.run( |
| 25 | + command.split(), |
| 26 | + cwd=NEW_TAB_DIR, |
| 27 | + check=True, |
| 28 | + capture_output=True, |
| 29 | + text=True |
| 30 | + ) |
| 31 | + logging.info(f"Successfully executed: {command}") |
50 | 32 | except subprocess.CalledProcessError as e:
|
51 |
| - logging.error(f"Bundle failed: {e.stderr}") |
52 |
| - raise |
| 33 | + logging.error(f"Command failed: {command} - {e.stderr}") |
| 34 | + raise |
| 35 | + |
| 36 | + |
| 37 | +def bundle_newtab_components(): |
| 38 | + if not os.path.isdir(ENGINE_DIR): |
| 39 | + logging.error(f"Directory not found: {ENGINE_DIR}") |
| 40 | + raise FileNotFoundError(f"Engine directory {ENGINE_DIR} does not exist") |
| 41 | + |
| 42 | + try: |
| 43 | + logging.info(f"Bundling newtab components in {ENGINE_DIR}") |
| 44 | + result = subprocess.run( |
| 45 | + BUNDLE_COMMAND.split(), |
| 46 | + cwd=ENGINE_DIR, |
| 47 | + check=True, |
| 48 | + capture_output=True, |
| 49 | + text=True |
| 50 | + ) |
| 51 | + logging.info(f"Bundle completed successfully: {result.stdout}") |
| 52 | + except subprocess.CalledProcessError as e: |
| 53 | + logging.error(f"Bundle failed: {e.stderr}") |
| 54 | + raise |
| 55 | + |
53 | 56 |
|
54 | 57 | def update_newtab(init: bool = True):
|
55 |
| - try: |
56 |
| - if init: |
57 |
| - logging.info("Starting dependency installation") |
58 |
| - install_dependencies() |
59 |
| - logging.info("Dependencies installed successfully") |
60 |
| - |
61 |
| - logging.info("Starting bundle process") |
62 |
| - bundle_newtab_components() |
63 |
| - logging.info("Newtab update completed successfully") |
64 |
| - |
65 |
| - except (subprocess.CalledProcessError, FileNotFoundError) as e: |
66 |
| - logging.error(f"Update process failed: {str(e)}") |
67 |
| - raise |
68 |
| - except Exception as e: |
69 |
| - logging.error(f"Unexpected error: {str(e)}") |
70 |
| - raise |
| 58 | + try: |
| 59 | + if init: |
| 60 | + logging.info("Starting dependency installation") |
| 61 | + install_dependencies() |
| 62 | + logging.info("Dependencies installed successfully") |
| 63 | + |
| 64 | + logging.info("Starting bundle process") |
| 65 | + bundle_newtab_components() |
| 66 | + logging.info("Newtab update completed successfully") |
| 67 | + |
| 68 | + except (subprocess.CalledProcessError, FileNotFoundError) as e: |
| 69 | + logging.error(f"Update process failed: {str(e)}") |
| 70 | + raise |
| 71 | + except Exception as e: |
| 72 | + logging.error(f"Unexpected error: {str(e)}") |
| 73 | + raise |
| 74 | + |
71 | 75 |
|
72 | 76 | if __name__ == "__main__":
|
73 |
| - update_newtab(init=False) |
| 77 | + update_newtab(init=False) |
0 commit comments