Skip to content

Commit 846f8bd

Browse files
authored
Create examples.html
1 parent 62cceb1 commit 846f8bd

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

src/examples.html

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// <!--
2+
/**
3+
* ScriptSync Library
4+
* @version 2.0.4
5+
* @description This script performs an update,
6+
* adding new files from the template project
7+
* to the current user script.
8+
* @author https://t.me/sergnovi
9+
* @see https://github.com/githnow
10+
*/
11+
12+
/* WITH LIBRARY CONNECTED */
13+
14+
// copy files from the library
15+
function UPDATER_Example_1() {
16+
17+
/* Initialize the template script */
18+
var updater = ScriptSync.assignTemplate();
19+
20+
// showing the library script_id
21+
console.log("Library id:", updater.getTemplateId());
22+
23+
// copying library files to this script
24+
const filesToCopy = ["lib_common", "lib_types"];
25+
for (let file of filesToCopy) {
26+
updater.AddNewFile(file);
27+
}
28+
29+
const sliceForSource = 30; // trim 'source' fields
30+
updater.viewChanges(sliceForSource); // shows the changes
31+
32+
updater.commit(); // apply the changes
33+
}
34+
35+
36+
37+
// copy files from your template script
38+
function UPDATER_Example_2() {
39+
40+
/* Initialize your template script */
41+
const script_id = "my-111-cmY0uvR_teMplATre-scRiPt1_IDaaH0sHoulD4BEoHeErReee";
42+
var updater = ScriptSync.assignTemplate(script_id);
43+
44+
// showing your template_id
45+
console.log("My template_id:", updater.getTemplateId());
46+
47+
// copying files in the template to this script
48+
const filesToCopy = ["my_code", "my_index", "my_json"];
49+
for (let file of filesToCopy) {
50+
updater.AddNewFile(file);
51+
}
52+
53+
const ignoreErrors = true; // optional
54+
updater.commit(ignoreErrors); // apply any changes
55+
56+
}
57+
58+
59+
60+
// copy files from your template script
61+
function UPDATER_Example_3() {
62+
63+
/* Initialize your template script */
64+
const script_id = "my-111-cmY0uvR_teMplATre-scRiPt1_IDaaH0sHoulD4BEoHeErReee";
65+
var updater = ScriptSync.assignTemplate(script_id);
66+
67+
// updating or adding the 'my_file' file FROM TEMPLATE & renaming it to script_js
68+
updater.AddNewFile("my_file").renameFile("my_file", "myfile", "gs");
69+
70+
// creating a new file & renaming
71+
updater.createBlankFile("the_code").renameFile("the_code", "code");
72+
73+
updater.commit(); // apply any changes
74+
75+
}
76+
77+
78+
79+
// add a custom source code to user script
80+
function UPDATER_Example_4() {
81+
82+
/* Initialize your template script */
83+
const template_script_id = "my-111-cmY0uvR_teMplATre-scRiPt1_IDaaH0sHoulD4BEoHeErReee";
84+
var updater = ScriptSync.assignTemplate(template_script_id);
85+
86+
// any working code, not that
87+
const myFunc = {
88+
def: function defined() {
89+
console.log("hey");
90+
/* Comments included too */
91+
mayn.get(file) = function(file) {
92+
file.attr = "active";
93+
file.retr = function ret_() {
94+
console.log(file.attr);
95+
}
96+
}
97+
}
98+
}
99+
100+
// creating a new file & renaming
101+
updater.createBlankFile("the_code", "html")
102+
.renameFile("the_code", "sample_code", "gs") // optional here
103+
.setCustomSource("sample_code", myFunc.def)
104+
.viewChanges(30); // optional here
105+
106+
107+
// waiting for interruption by user
108+
Utilities.sleep(10000);
109+
110+
111+
// apply the changes
112+
const ignoreErrors = true; // optional
113+
const result = updater.commit(ignoreErrors);
114+
console.log(result);
115+
}
116+
117+
118+
119+
// add a custom source code to user script
120+
function UPDATER_Example_5() {
121+
122+
// get files in the current script
123+
ScriptSync.IO_GetScriptFiles()
124+
125+
/* Initialize your template script */
126+
const template_script_id = "my-111-cmY0uvR_teMplATre-scRiPt1_IDaaH0sHoulD4BEoHeErReee";
127+
var updater = ScriptSync.assignTemplate(template_script_id);
128+
129+
130+
const myCustomCode = "function Log() { console.log('Hey2') }";
131+
const [my_new_file, ext] = ['the_code_hey', 'gs'];
132+
133+
// creating a new file & renaming
134+
updater.createBlankFile(my_new_file, ext)
135+
.setCustomSource(my_new_file, myCustomCode)
136+
.viewChanges(30);
137+
138+
139+
// waiting for interruption by user
140+
Utilities.sleep(10000);
141+
142+
143+
var result;
144+
145+
// no commit, no changes
146+
// result = updater.commit();
147+
148+
console.log(result);
149+
}
150+
151+
152+
153+
/* WITHIN LIBRARY */
154+
// You can use internal class methods with prefix `_`.
155+
// The 'lib_prototype' file is used to link to the script.
156+
// Due to the fact that Apps Script does not load the desc-
157+
// ription of methods inside the class, we have to come up
158+
// with a dynamic binding.
159+
function InLib_Example() {
160+
const updater = assignTemplate("your-script-id");
161+
updater._AddNewFile("appsscript");
162+
updater._renameFile("myfile","myfile1");
163+
updater._viewChanges(10);
164+
/* [...] */
165+
}
166+
167+
168+
169+
170+
// thanks for watching ⭐
171+
// -->

0 commit comments

Comments
 (0)