@salesforce/lds-core-release 0.1.0-dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.txt ADDED
@@ -0,0 +1,82 @@
1
+ Terms of Use
2
+
3
+ Copyright 2022 Salesforce, Inc. All rights reserved.
4
+
5
+ These Terms of Use govern the download, installation, and/or use of this
6
+ software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
7
+ last updated on April 15, 2022, and constitute a legally binding
8
+ agreement between you and Salesforce. If you do not agree to these Terms of
9
+ Use, do not install or use the Software.
10
+
11
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
12
+ copyright license to reproduce, prepare derivative works of, publicly
13
+ display, publicly perform, sublicense, and distribute the Software and
14
+ derivative works subject to these Terms. These Terms shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ Subject to the limited rights expressly granted hereunder, Salesforce
18
+ reserves all rights, title, and interest in and to all intellectual
19
+ property subsisting in the Software. No rights are granted to you hereunder
20
+ other than as expressly set forth herein. Users residing in countries on
21
+ the United States Office of Foreign Assets Control sanction list, or which
22
+ are otherwise subject to a US export embargo, may not use the Software.
23
+
24
+ Implementation of the Software may require development work, for which you
25
+ are responsible. The Software may contain bugs, errors and
26
+ incompatibilities and is made available on an AS IS basis without support,
27
+ updates, or service level commitments.
28
+
29
+ Salesforce reserves the right at any time to modify, suspend, or
30
+ discontinue, the Software (or any part thereof) with or without notice. You
31
+ agree that Salesforce shall not be liable to you or to any third party for
32
+ any modification, suspension, or discontinuance.
33
+
34
+ You agree to defend Salesforce against any claim, demand, suit or
35
+ proceeding made or brought against Salesforce by a third party arising out
36
+ of or accruing from (a) your use of the Software, and (b) any application
37
+ you develop with the Software that infringes any copyright, trademark,
38
+ trade secret, trade dress, patent, or other intellectual property right of
39
+ any person or defames any person or violates their rights of publicity or
40
+ privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
41
+ from any damages, attorney fees, and costs finally awarded against
42
+ Salesforce as a result of, or for any amounts paid by Salesforce under a
43
+ settlement approved by you in writing of, a Claim Against Salesforce,
44
+ provided Salesforce (x) promptly gives you written notice of the Claim
45
+ Against Salesforce, (y) gives you sole control of the defense and
46
+ settlement of the Claim Against Salesforce (except that you may not settle
47
+ any Claim Against Salesforce unless it unconditionally releases Salesforce
48
+ of all liability), and (z) gives you all reasonable assistance, at your
49
+ expense.
50
+
51
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
52
+ SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
54
+ INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
55
+ PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
56
+ OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
57
+ CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
58
+ HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
59
+
60
+ These Terms of Use shall be governed exclusively by the internal laws of
61
+ the State of California, without regard to its conflicts of laws
62
+ rules. Each party hereby consents to the exclusive jurisdiction of the
63
+ state and federal courts located in San Francisco County, California to
64
+ adjudicate any dispute arising out of or relating to these Terms of Use and
65
+ the download, installation, and/or use of the Software. Except as expressly
66
+ stated herein, these Terms of Use constitute the entire agreement between
67
+ the parties, and supersede all prior and contemporaneous agreements,
68
+ proposals, or representations, written or oral, concerning their subject
69
+ matter. No modification, amendment, or waiver of any provision of these
70
+ Terms of Use shall be effective unless it is by an update to these Terms of
71
+ Use that Salesforce makes available, or is in writing and signed by the
72
+ party against whom the modification, amendment, or waiver is to be
73
+ asserted.
74
+
75
+ Data Privacy: Salesforce may collect, process, and store device,
76
+ system, and other information related to your use of the Software. This
77
+ information includes, but is not limited to, IP address, user metrics, and
78
+ other data ("Usage Data"). Salesforce may use Usage Data for analytics,
79
+ product development, and marketing purposes. You acknowledge that files
80
+ generated in conjunction with the Software may contain sensitive or
81
+ confidential data, and you are solely responsible for anonymizing and
82
+ protecting such data.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # LDS Core Release
2
+
3
+ This package defines a portable [python script](./src/release.py) along with assets to successfully update core with the latest lds-lightning-platform assets. It can be used for local development, integration testing, and the LDS weekly release. Usage is documented [here](../../docs/release/core-release-tasks.md)
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@salesforce/lds-core-release",
3
+ "private": false,
4
+ "version": "0.1.0-dev1",
5
+ "license": "SEE LICENSE IN LICENSE.txt",
6
+ "description": "LDS release System",
7
+ "scripts": {
8
+ "release:python": "python3 ./src/release.py"
9
+ },
10
+ "volta": {
11
+ "extends": "../../package.json"
12
+ },
13
+ "sfdc": {
14
+ "overrides": {
15
+ "artifactDirectory": "src",
16
+ "outputDir": "lds",
17
+ "artifactPaths": "**/*.{py,txt}",
18
+ "artifacts": {
19
+ "release.py": {
20
+ "output": {
21
+ "path": "release.py"
22
+ }
23
+ },
24
+ "assets/js-meta.txt": {
25
+ "output": {
26
+ "path": "assets/js-meta.txt",
27
+ "dir": "assets"
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ ~ Copyright 2022 salesforce.com, inc.
4
+ ~ All Rights Reserved
5
+ ~ Company Confidential
6
+ -->
7
+
8
+ <LightningComponentBundle xmlns="xmlns=http://soap.sforce.com/2006/04/metadata">
9
+ <isExposed>true</isExposed>
10
+ </LightningComponentBundle>
package/src/release.py ADDED
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env python3
2
+ import subprocess;
3
+ import errno;
4
+ from string import Template
5
+ from pathlib import Path
6
+ from typing import List
7
+ from functools import lru_cache
8
+ import asyncio
9
+ import argparse
10
+
11
+ # resolve static files used by the script
12
+ script_path = Path(__file__).resolve()
13
+ script_directory = script_path.parent
14
+ assets_path = script_directory / 'assets'
15
+
16
+ async def usingPerforce(coreDir):
17
+ isPerforceDir = True
18
+ try:
19
+ # Run the 'p4 where ...' command using subprocess
20
+ result = subprocess.run(['p4 where ...'], cwd=coreDir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
21
+ # Check if the error message indicates the directory is not under client's root
22
+ if "is not under client's root" in result.stderr:
23
+ print('Client root error!')
24
+ isPerforceDir = False
25
+
26
+ except subprocess.CalledProcessError as e:
27
+ print('Got an error trying to verify p4 workspace. Assuming Git.')
28
+ print(e)
29
+ # Handle any errors, but we assume that if 'p4 where' fails, it's not a Perforce directory
30
+ isPerforceDir = False
31
+
32
+ return isPerforceDir
33
+
34
+ async def checkoutFileP4(corePath: Path, coreDir: Path):
35
+ # Check if the file exists
36
+ if not corePath.exists():
37
+ # If it doesn't exist, add it to Perforce
38
+ print('New file in perforce. Attempting add.')
39
+ p4_command = [f'p4 add {corePath}']
40
+
41
+ try:
42
+ subprocess.run(p4_command, cwd=coreDir, check=True, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
43
+ except subprocess.CalledProcessError as e:
44
+ print(f"Error adding file to Perforce: {e}")
45
+ return
46
+
47
+ # Create the directory structure if it doesn't exist
48
+ corePath.parent.mkdir(parents=True, exist_ok=True)
49
+
50
+ # Create an empty file
51
+ try:
52
+ corePath.touch()
53
+ except OSError as e:
54
+ if e.errno == errno.EACCES:
55
+ print(f"File is not writable. Make sure to run 'p4 edit {corePath}'.")
56
+ else:
57
+ print(f"Error creating file: {e}")
58
+ else:
59
+ # If the file exists, edit it in Perforce
60
+ p4_command = [f'p4 edit {corePath}']
61
+
62
+ try:
63
+ subprocess.run(p4_command, cwd=coreDir, check=True, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
64
+ except subprocess.CalledProcessError as e:
65
+ print(f"Error editing file in Perforce: {e}")
66
+
67
+ # Check if the file is writable
68
+ try:
69
+ corePath.touch(mode=0o666, exist_ok=True)
70
+ except OSError as e:
71
+ if e.errno == errno.EACCES:
72
+ print(f"File is not writable. Make sure to run 'p4 edit {corePath}'.")
73
+ else:
74
+ print(f"Error checking file access: {e}")
75
+
76
+ # Python 3 script that does the LDS release.
77
+ async def copy_release(source_dir: Path, destination_dir: Path, useP4: bool):
78
+ try:
79
+ new_modules = []
80
+
81
+ # Copy files from the source directory to the destination directory
82
+ for file in Path(source_dir).rglob("*.js"):
83
+ print(f"File detected: {file}")
84
+
85
+ relative_path = file.relative_to(source_dir)
86
+ destination_file = destination_dir / relative_path
87
+
88
+ if(useP4):
89
+ await checkoutFileP4(destination_file, destination_dir)
90
+
91
+ destination_file.parent.mkdir(parents=True, exist_ok=True)
92
+ destination_file.touch(mode= 0o666 ,exist_ok=True)
93
+
94
+ # Copy the file
95
+ destination_file.write_bytes(file.read_bytes())
96
+ # Get the directory name (module name)
97
+ module_name = destination_file.parent.name
98
+ metajs_xml_filename_template = Template("$module.js-meta.xml")
99
+ metajs_xml_filename = metajs_xml_filename_template.substitute(module=module_name)
100
+
101
+ # # Check if a meta xml file exists in the module.
102
+ meta_xml_file = destination_file.parent / metajs_xml_filename
103
+ if not meta_xml_file.exists() and requires_js_meta(meta_xml_file):
104
+ new_modules.append(module_name)
105
+ # Create the meta xml file if missing
106
+ meta_xml_template_bytes = read_js_meta_template()
107
+ if(useP4):
108
+ await checkoutFileP4(meta_xml_file, destination_dir)
109
+ meta_xml_file.touch(mode= 0o666 ,exist_ok=True)
110
+ meta_xml_file.write_bytes(meta_xml_template_bytes)
111
+
112
+ print("Release copied successfully!")
113
+ return new_modules
114
+ except Exception as e:
115
+ raise SystemExit(f"An error occurred while copying the release: {e}")
116
+
117
+ @lru_cache(1)
118
+ def read_js_meta_template():
119
+ js_meta_path = assets_path / 'js-meta.txt'
120
+ return js_meta_path.read_bytes()
121
+
122
+ @lru_cache(1)
123
+ def read_miniftests_template():
124
+ miniftests_path = assets_path / 'miniftests.lst'
125
+ return miniftests_path.read_bytes()
126
+
127
+ def requires_js_meta(file: Path):
128
+ if "Adapters" in file.name:
129
+ return True
130
+ else:
131
+ return False
132
+
133
+ def replace_string_in_file(file_path: Path, old_string: str, new_string: str, success_string: str ="String replaced successfully!"):
134
+ try:
135
+ # Read the contents of the file
136
+ with open(file_path, 'r') as file:
137
+ file_contents = file.read()
138
+
139
+ # Replace the old string with the new string
140
+ modified_contents = file_contents.replace(old_string, new_string)
141
+
142
+ # Write the modified contents back to the file
143
+ with open(file_path, 'w') as file:
144
+ file.write(modified_contents)
145
+
146
+ print(success_string)
147
+
148
+ except Exception as e:
149
+ print("An error occurred while replacing the string:", e)
150
+
151
+ async def update_ownership_yml(destination_filepath: Path, new_modules: List[str], useP4: bool):
152
+ ownershipYamlPath = destination_filepath / 'ui-force-components' / 'java' / 'resources' / 'ownership.yaml'
153
+ newEntriesString = "\n".join([f" - modules/force/{module}/**" for module in new_modules]) + "\n - modules/force/ldsBindings/**"
154
+ if useP4:
155
+ await checkoutFileP4(ownershipYamlPath, destination_filepath)
156
+ ownershipYamlPath.chmod(0o666)
157
+ replace_string_in_file(ownershipYamlPath, ' - modules/force/ldsBindings/**', newEntriesString, "Updated ownership.yml")
158
+ return
159
+
160
+ async def update_lwc_workflow_test(destination_filepath: Path, new_modules: List[str], useP4: bool):
161
+ lwcWorkflowTestPath = destination_filepath / 'aura-impl-sfdc' / 'test' / 'func' / 'java' / 'src' / 'aura' / 'impl' / 'sfdc' / 'modules' / 'LWCWorkflowTest.java'
162
+ newEntriesString = "\n".join([f' "force/{module}",' for module in new_modules]) + '\n "force/ldsBindings",'
163
+ if useP4:
164
+ await checkoutFileP4(lwcWorkflowTestPath, destination_filepath)
165
+
166
+ lwcWorkflowTestPath.chmod(0o666)
167
+ replace_string_in_file(lwcWorkflowTestPath, ' "force/ldsBindings",', newEntriesString, "Updated LWCWorkflowTest")
168
+ return
169
+
170
+ async def main():
171
+ parser = argparse.ArgumentParser(description="The release script for LDS")
172
+ parser.add_argument("-o", "--outputDir", help="Path to the output directory generated by yarn build:core-artifacts")
173
+ parser.add_argument("-c", "--coreDir", help="Path to the target core directory")
174
+ args, unknown = parser.parse_known_args()
175
+
176
+ source_filepath = Path(args.outputDir or input("Enter the location of the LDS release artifact. Default: ./output: ") or './output').expanduser()
177
+ print("LDS Release artifact path:", source_filepath)
178
+ if not (source_filepath / 'sfdc').exists():
179
+ raise SystemExit(f"LDS release artifact directory({source_filepath}) does not seem to exist. Did you provide the correct path? Did you run yarn build:core-artifacts?")
180
+ destination_filepath = Path(args.coreDir or input("Enter the core filepath. Default: /opt/workspace/core-public/core: ") or '/opt/workspace/core-public/core').expanduser()
181
+ print("Destination filepath:", destination_filepath)
182
+ if not (destination_filepath / 'ui-force-components').exists():
183
+ raise SystemExit(f"Destination core directory does not seem to contain ui-force-components. Did you provide the correct path to your core directory?")
184
+ # Print the entered filepaths
185
+
186
+
187
+ useP4 = await usingPerforce(destination_filepath)
188
+ new_modules = await copy_release(source_filepath / 'sfdc', destination_filepath, useP4)
189
+
190
+ if(len(new_modules) == 0):
191
+ print(f"No new modules detected")
192
+ return
193
+ else:
194
+ print(f"New modules added: {new_modules}")
195
+ await update_ownership_yml(destination_filepath, new_modules, useP4)
196
+ await update_lwc_workflow_test(destination_filepath, new_modules, useP4)
197
+
198
+ asyncio.run(main())