Skip to content

Commit 2458400

Browse files
author
Joseph Atkins-Turkish
committed
Allow importing sourceless package.json projects.
1 parent 3dfd8e5 commit 2458400

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ide/utils/project.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def rank_manifest_path(dirname, kind):
3939

4040

4141
def find_project_root_and_manifest(project_items):
42-
""" Given the contents of an archive, find a valid Pebble project.
42+
""" Given the contents of an archive, find a (potentially) valid Pebble project.
43+
A potentially valid Pebble project is either:
44+
- An appinfo.json file next to an 'src/' directory which contains app sources
45+
- A package.json file which has a 'pebble' key.
46+
The function chooses the most shallow possible project and prefers package.json to appinfo.json if both are present.
4347
:param project_items: A list of BaseProjectItems
4448
:return: A tuple of (path_to_project, manifest BaseProjectItem)
4549
"""
@@ -62,9 +66,10 @@ def find_project_root_and_manifest(project_items):
6266
# Choose the most shallow manifest file which has a non-empty source directory.
6367
sorted_manifests = sorted(found_manifests, key=lambda x: rank_manifest_path(*x[0]))
6468
for (base, kind), item in sorted_manifests:
65-
src_dir = os.path.join(base, SRC_DIR) + os.sep
69+
if kind == "package.json":
70+
return os.path.join(base, ''), item
71+
src_dir = os.path.join(base, SRC_DIR, '')
6672
for src_path in found_src_files:
6773
if src_path.startswith(src_dir):
68-
base = base + os.sep if base else ""
69-
return base, item
74+
return os.path.join(base, ''), item
7075
raise InvalidProjectArchiveException(_("No project root found."))

0 commit comments

Comments
 (0)