|
| 1 | +__author__ = 'sb' |
| 2 | + |
| 3 | +from django.core.management.base import BaseCommand |
| 4 | +from django.conf import settings |
| 5 | +import os |
| 6 | +import json |
| 7 | + |
| 8 | +class NeedFrontEndDirCommand(BaseCommand): |
| 9 | + def __init__(self, stdout=None, stderr=None, no_color=False): |
| 10 | + super().__init__(stdout, stderr, no_color) |
| 11 | + if not settings.FRONTEND_DIR: |
| 12 | + self.stdout.write(self.style.ERROR('Please set FRONTEND_DIR in settings.py')) |
| 13 | + quit() |
| 14 | + if not os.path.isdir(settings.FRONTEND_DIR): |
| 15 | + self.stdout.write(self.style.ERROR('FRONTEND_DIR not found')) |
| 16 | + self.stdout.write(self.style.ERROR('FRONTEND_DIR is: {}'.format(settings.FRONTEND_DIR))) |
| 17 | + quit() |
| 18 | + |
| 19 | + |
| 20 | +class NeedPackageJsonCommand(NeedFrontEndDirCommand): |
| 21 | + package_json_filepath = '' |
| 22 | + package_json_obj = {} |
| 23 | + |
| 24 | + def __init__(self, stdout=None, stderr=None, no_color=False): |
| 25 | + super().__init__(stdout, stderr, no_color) |
| 26 | + self.package_json_filepath = os.path.join(settings.FRONTEND_DIR,'package.json') |
| 27 | + if not os.path.exists(self.package_json_filepath): |
| 28 | + self.stdout.write(self.style.ERROR('File package.json not found in FRONTEND_DIR')) |
| 29 | + self.stdout.write(self.style.ERROR('May should run "npm init" ?')) |
| 30 | + self.stdout.write(self.style.ERROR('Full package.json path:{}'.format(self.package_json_filepath))) |
| 31 | + quit() |
| 32 | + try: |
| 33 | + fh = open(self.package_json_filepath) |
| 34 | + self.package_json_obj = json.load(fh) |
| 35 | + fh.close() |
| 36 | + except: |
| 37 | + self.stdout.write(self.style.ERROR('Can\'t decode json from package.json')) |
| 38 | + self.stdout.write(self.style.ERROR('May should run "npm init" ?')) |
| 39 | + self.stdout.write(self.style.ERROR('Full package.json path:{}'.format(self.package_json_filepath))) |
| 40 | + quit() |
| 41 | + |
0 commit comments