in source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/scripts/build_s3_cdk_dist.py [0:0]
def source_code_package(ctx, ignore, solution_name):
"""Use this to build the source package folder and zip file"""
env = BuildEnvironment()
env.clean_for_open_source()
# set up some default ignore directories
ignored = [
"**/cdk.out/*",
"**/__pycache__/*",
"*.pyc",
"*.pyo",
"*.pyd",
"**/.gradle/*",
"**/.idea/*",
"**/.coverage/*",
"**/.pytest_cache/*",
"**/*.egg-info",
"**/__pycache__",
]
ignored.extend(ignore)
required_files = [
"LICENSE.txt",
"NOTICE.txt",
"README.md",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.md",
"CHANGELOG.md",
".gitignore",
]
# copy source directory
try:
copytree(
env.source_dir, os.path.join(env.open_source_dir, "source"), ignore=ignored
)
copytree(env.github_dir, os.path.join(env.open_source_dir, ".github"))
except FileNotFoundError:
raise click.ClickException(
"The solution requires a `source` folder and a `.github` folder"
)
# copy all required files
for name in required_files:
try:
shutil.copyfile(
Path(env.source_dir).parent / name, Path(env.open_source_dir) / name
)
except FileNotFoundError:
raise click.ClickException(
f"The solution is missing the required file {name}"
)
# copy the required run-unit-tests.sh
(Path(env.open_source_dir) / "deployment").mkdir()
try:
shutil.copyfile(
Path(env.template_dir) / "run-unit-tests.sh",
Path(env.open_source_dir) / "deployment" / "run-unit-tests.sh",
)
except FileNotFoundError:
raise click.ClickException(
f"The solution is missing deployment/run-unit-tests.sh"
)
shutil.make_archive(
base_name=os.path.join(env.template_dir, solution_name),
format="zip",
root_dir=os.path.join(env.open_source_dir),
logger=logger,
)
# finalize by deleting the open-source folder data and copying the zip file over
env.clean_for_open_source()
shutil.move(
os.path.join(env.template_dir, f"{solution_name}.zip"), env.open_source_dir
)