1
- import JSZip from 'jszip' ;
1
+ import type JSZip from 'jszip' ;
2
2
import type { GenericOptions } from './build-generic' ;
3
3
import type { Contract } from './contract' ;
4
- import { printContract , removeCreateLevelAttributes } from './print' ;
5
- import { compatibleSorobanVersion , contractsVersionTag } from './utils/version' ;
6
- import {
7
- addDependenciesWith ,
8
- allStellarDependencies ,
9
- contractOptionsToContractName ,
10
- createRustLibFile ,
11
- printContractCargo ,
12
- printRustNameTest ,
13
- } from './zip-shared' ;
4
+ import { createRustZipEnvironment } from './zip-rust' ;
14
5
15
- function getAddressArgs ( c : Contract ) : string [ ] {
16
- return c . constructorArgs
17
- . filter ( constructorArg => constructorArg . type ?. toLowerCase ( ) === 'address' )
18
- . map ( constructorArg => constructorArg . name ) ;
19
- }
20
-
21
- const setupSh = ( c : Contract , opts : GenericOptions , scaffoldContractName : string ) => {
22
- const environmentsFileUpdate = ( setUpContract : Contract , setUpScaffoldContractName : string ) => `
23
- # Update environments.toml: remove original contracts and insert wizard's contract
24
- setup_environment() {
25
- local file="environments.toml"
26
- local temp
27
- temp="$(mktemp)"
28
-
29
- local in_dev_contracts=0
30
- local skip_entry=0
31
- local contract_entry_inserted=0
32
- insert_contract_entry() {
33
- {
34
- printf '%s\\n' "[development.contracts.${ setUpScaffoldContractName } _contract]" \\
35
- "client = true" "" \\
36
- "# If your contract has a \\\`__constructor\\\`, specify your arguments to it here." \\
37
- "# These are the same arguments you could pass after the \\\`--\\\` in a call to" \\
38
- "# \\\`stellar contract deploy\\\`" \\
39
- "# Only available in \\\`development\\\` and \\\`test\\\` environments" \\
40
- ${
41
- setUpContract . constructorArgs . length
42
- ? // Mind the spacing
43
- `"# TODO add appropriate values for for the constructors arguments" \\
44
- "constructor_args = \\"\\"\\"" \\
45
- "${ setUpContract . constructorArgs . map ( constructorArg => `--${ constructorArg . name } \\"ADD_${ constructorArg . name . toLocaleUpperCase ( ) } _${ constructorArg . type ?. toLocaleUpperCase ( ) || 'ARGUMENT' } _HERE\\"` ) . join ( ' ' ) } " \\
46
- "\\"\\"\\"" \\
47
- ""`
48
- : '""'
49
- }
50
- } >> "$temp"
51
- }
52
-
53
- while IFS= read -r line; do
54
- if [[ $contract_entry_inserted -eq 0 && $line == '[staging.network]' ]]; then
55
- insert_contract_entry
56
- contract_entry_inserted=1
57
- fi
58
-
59
- if [[ $line =~ ^\\[development\\.contracts\\]$ ]]; then
60
- printf '%s\\n' "$line" >> "$temp"
61
- in_dev_contracts=1
62
- skip_entry=0
63
- continue
64
- fi
65
-
66
- if [[ $line =~ ^\\[[^]]+\\]$ ]]; then
67
- if (( in_dev_contracts )) && [[ $line =~ ^\\[development\\.contracts\\..+\\]$ ]]; then
68
- skip_entry=1
69
- in_dev_contracts=0
70
- continue
71
- fi
72
- in_dev_contracts=0
73
- skip_entry=0
74
- printf '%s\\n' "$line" >> "$temp"
75
- continue
76
- fi
77
-
78
- if (( skip_entry )); then
79
- continue
80
- fi
81
-
82
- if (( in_dev_contracts )); then
83
- if [[ $line =~ ^[[:space:]]*# ]]; then
84
- printf '%s\\n' "$line" >> "$temp"
85
- fi
86
- continue
87
- fi
88
-
89
- printf '%s\\n' "$line" >> "$temp"
90
- done < "$file"
91
-
92
- mv "$temp" "$file"
93
- }
94
- ` ;
95
-
96
- const updateWorkspaceCargo = `update_cargo() {
97
- cp Cargo.toml Cargo.toml.bak
98
-
99
- cat <<EOF > deps.tmp
100
- ${ addDependenciesWith ( `{ git = "https://github.com/OpenZeppelin/stellar-contracts", tag = "${ contractsVersionTag } " }` , allStellarDependencies ) } ${ addDependenciesWith ( `{ version = "${ compatibleSorobanVersion } " }` , [ 'soroban' ] ) }
101
- EOF
102
-
103
- awk '
104
- BEGIN {
105
- inserted = 0
106
- deps = ""
107
- while ((getline line < "deps.tmp") > 0) {
108
- deps = deps line "\\n"
109
- }
110
- close("deps.tmp")
111
- }
112
- /^\\[workspace.dependencies\\]/ {
113
- in_deps = 1
114
- print
115
- if (!inserted) {
116
- printf "%s", deps
117
- inserted = 1
118
- }
119
- next
120
- }
121
- /^\\[/ { in_deps = 0 }
122
- in_deps { next }
123
- { print }
124
- ' Cargo.toml.bak > Cargo.toml
125
-
126
- rm deps.tmp
127
- rm Cargo.toml.bak
128
- }` ;
129
-
130
- return `\
6
+ const setupSh = `\
131
7
#!/usr/bin/env bash
132
8
#
133
9
# setup.sh
134
- #
135
- # This script is meant to set up a Scaffold project and insert the Wizard's contracts in the project
10
+ #
11
+ # This script is meant to set up a Scaffold project with the Wizard's contracts
136
12
137
13
check_is_installed() {
138
14
if ! which "$1" &> /dev/null; then
@@ -143,18 +19,7 @@ check_is_installed() {
143
19
}
144
20
145
21
scaffold() {
146
- tmp_folder="tmp"
147
- stellar scaffold init "$tmp_folder"
148
-
149
- rm -rf "$tmp_folder/contracts"
150
-
151
- local current_directory
152
- current_directory="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
153
-
154
- shopt -s dotglob
155
-
156
- cp -a "$current_directory/$tmp_folder"/. "$current_directory"/
157
- rm -rf "$current_directory/$tmp_folder"
22
+ stellar-scaffold upgrade
158
23
}
159
24
160
25
init_git(){
@@ -163,10 +28,6 @@ init_git(){
163
28
git commit -m "openzeppelin: add wizard output" --quiet
164
29
}
165
30
166
- ${ environmentsFileUpdate ( c , scaffoldContractName ) }
167
-
168
- ${ updateWorkspaceCargo }
169
-
170
31
build_contracts() {
171
32
cargo build
172
33
}
196
57
echo "🏗️ Building Scaffold project"
197
58
198
59
scaffold
199
-
200
- setup_environment
201
-
202
- update_cargo
203
60
204
61
build_contracts
205
62
@@ -212,15 +69,11 @@ else
212
69
echo "✅ Scaffold project already initialized."
213
70
fi
214
71
` ;
215
- } ;
216
-
217
- const readme = ( c : Contract ) => {
218
- const hasTodosToResolve = ( c : Contract ) => getAddressArgs ( c ) . length > 0 ;
219
72
220
- return `\
73
+ const wizardReadme = `\
221
74
# Sample Scaffold Project
222
75
223
- This project demonstrates a basic Scaffold use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/), a test for that contract, and a script that initiate a Stellar Scaffold project with this contract. [Scaffold Stellar](https://github.com/AhaLabs/scaffold-stellar?tab=readme-ov-file#scaffold-stellar) is a convention-over-configuration toolkit for blockchain and distributed application development on the Stellar network. It provides a seamless development experience through CLI tools, smart contract management, and deployment utilities.
76
+ This project demonstrates a basic Scaffold use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/), a test for that contract, and a script that initiates a Stellar Scaffold project with this contract. [Scaffold Stellar](https://github.com/AhaLabs/scaffold-stellar?tab=readme-ov-file#scaffold-stellar) is a convention-over-configuration toolkit for blockchain and distributed application development on the Stellar network. It provides a seamless development experience through CLI tools, smart contract management, and deployment utilities.
224
77
225
78
## Installing dependencies
226
79
@@ -235,7 +88,6 @@ This project demonstrates a basic Scaffold use case. It comes with a contract ge
235
88
\`\`\`
236
89
bash setup.sh
237
90
\`\`\`
238
- ${ hasTodosToResolve ( c ) ? '\n## Resolve any TODOs \n\nSearch for any TODO comments in the project and resolve them (search for TODO with your code editor).\n' : '' }
239
91
240
92
## Testing the contract
241
93
@@ -255,19 +107,13 @@ stellar scaffold watch --build-clients
255
107
npm run dev
256
108
\`\`\`
257
109
` ;
258
- } ;
259
-
260
- export async function zipScaffold ( c : Contract , opts : GenericOptions ) {
261
- const zip = new JSZip ( ) ;
262
110
263
- const scaffoldContractName = contractOptionsToContractName ( opts ?. kind || 'contract' ) ;
264
-
265
- zip . file ( `contracts/${ scaffoldContractName } /src/contract.rs` , removeCreateLevelAttributes ( printContract ( c ) ) ) ;
266
- zip . file ( `contracts/${ scaffoldContractName } /src/test.rs` , printRustNameTest ( c ) ) ;
267
- zip . file ( `contracts/${ scaffoldContractName } /src/lib.rs` , createRustLibFile ) ;
268
- zip . file ( `contracts/${ scaffoldContractName } /Cargo.toml` , printContractCargo ( scaffoldContractName ) ) ;
269
- zip . file ( 'setup.sh' , setupSh ( c , opts , scaffoldContractName ) ) ;
270
- zip . file ( 'README-WIZARD.md' , readme ( c ) ) ;
111
+ const addScaffoldProjectFiles = ( zip : JSZip ) => {
112
+ zip . file ( 'README-WIZARD.md' , wizardReadme ) ;
113
+ zip . file ( 'setup.sh' , setupSh ) ;
271
114
272
115
return zip ;
273
- }
116
+ } ;
117
+
118
+ export const zipScaffoldProject = async ( c : Contract , opts : GenericOptions ) =>
119
+ addScaffoldProjectFiles ( createRustZipEnvironment ( c , opts ) ) ;
0 commit comments