Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/dsw-tdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add check for no matching files (warning and use of defaults)


## [4.16.0]

Expand Down
18 changes: 15 additions & 3 deletions packages/dsw-tdk/dsw/tdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def store_local(self, force: bool):
if self.project is None:
raise RuntimeError('No template project is initialized')
self.project.template = self.safe_template
if len(self.project.template.tdk_config.files) == 0:
self.project.template.tdk_config.use_default_files()
self.logger.warning('Using default _tdk.files in template.json, you may want '
'to change it to include relevant files')
self.logger.debug('Initiating storing local template project (force=%s)', force)
self.project.store(force=force)

Expand Down Expand Up @@ -301,6 +305,9 @@ async def _create_template_file(self, tfile: TemplateFile, project_update: bool
tfile.remote_type.value, tfile.filename.as_posix(), e)

async def store_remote_files(self):
if len(self.safe_project.safe_template.files) == 0:
self.logger.warning('No files to store, maybe you forgot to '
'update _tdk.files patterns in template.json?')
for tfile in self.safe_project.safe_template.files.values():
tfile.remote_id = None
tfile.remote_type = TemplateFileType.FILE if tfile.is_text else TemplateFileType.ASSET
Expand Down Expand Up @@ -333,6 +340,9 @@ def create_package(self, output: pathlib.Path, force: bool):
pkg.writestr(f'template/assets/{tfile.filename.as_posix()}', tfile.content)
descriptor['files'] = files
descriptor['assets'] = assets
if len(files) == 0 and len(assets) == 0:
self.logger.warning('No files or assets found in the template, maybe you forgot '
'to update _tdk.files patterns in template.json?')
timestamp = datetime.datetime.now(tz=datetime.UTC).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
descriptor['createdAt'] = timestamp
descriptor['updatedAt'] = timestamp
Expand All @@ -355,7 +365,9 @@ def extract_package(self, zip_data: bytes, template_dir: pathlib.Path | None, fo
raise RuntimeError('Malformed package: missing template.json file')
data = json.loads(template_file.read_text(encoding=DEFAULT_ENCODING))
template = Template.load_local(data)
template.tdk_config.files = ['*', '!.git/', '!.env']
template.tdk_config.use_default_files()
self.logger.warning('Using default _tdk.files in template.json, you may want '
'to change it to include relevant files')
self.logger.debug('Preparing template dir')
if template_dir is None:
template_dir = pathlib.Path.cwd() / template.id.replace(':', '_')
Expand All @@ -372,8 +384,8 @@ def extract_package(self, zip_data: bytes, template_dir: pathlib.Path | None, fo
encoding=DEFAULT_ENCODING,
)
self.logger.debug('Extracting README.md from package')
local_template_json = template_dir / 'README.md'
local_template_json.write_text(
local_readme = template_dir / 'README.md'
local_readme.write_text(
data=data['readme'].replace('\r\n', '\n'),
encoding=DEFAULT_ENCODING,
)
Expand Down
5 changes: 4 additions & 1 deletion packages/dsw-tdk/dsw/tdk/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def serialize(self):
class TDKConfig:

DEFAULT_README = 'README.md'
DEFAULT_FILES = ['*']
DEFAULT_FILES = ['*', '!.git/', '!.env']

def __init__(self, *, version: str | None = None, readme_file: str | None = None,
files: list[str] | None = None):
Expand All @@ -118,6 +118,9 @@ def load(cls, data):
files=data.get('files', cls.DEFAULT_FILES),
)

def use_default_files(self):
self.files = self.DEFAULT_FILES

def serialize(self):
return {
'version': self.version,
Expand Down
Loading