-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdoExtraction.gs
152 lines (121 loc) · 4.07 KB
/
doExtraction.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"use strict";
function triggerBatch(){
doExtraction();
doLibraries();
doGit();
// if you want a summary sheet - this with your own sheet ID etc.
doSheet();
}
/**
* RUN FIRST
*
* examine all the scripts owned by me on drive
* extract their source code id they've been updated after the current contents of the script dump
* update or create info.json to describe whats' been done
* each folder will be equivalent to a project
* each file will be a .js or a .html from the project
*/
function doExtraction () {
// this is the extractor
var extractor = getExtractor();
// for each of the search areas
var scripts = SETTINGS.PARENT.SCRIPTS.reduce(function(p,c) {
// where to get the input from
extractor.setSearch(c);
// get all the scripts that I own
var scriptChunk = extractor.getAllMyScripts();
if(!scriptChunk.success) {
throw 'failed to get scripts ' + JSON.stringify(scriptChunk);
}
return cUseful.arrayAppend(p,scriptChunk.data.items);
}, []);
// now scripts contains an array of {id:'xxx'} - these are what need to be processes
// this does all the work - extracts all the sources and returns their infos
var infos = extractor.getInfosAndExtract (scripts);
sumLog(infos);
}
/**
* get an extractor object
* @return {ScriptExtractor} the extractor
*/
function getExtractor () {
const scriptApi = new cScriptApi.ScriptApi()
.init (ScriptApp.getOAuthToken , UrlFetchApp, {
cacheCrusher:new cUseful.CrusherPluginCacheService()
.init ({
store:CacheService.getUserCache()
})
})
.setCaching(true);
const dj = new cDriveJsonApi.DriveJsonApi().setAccessToken(ScriptApp.getOAuthToken());
const se = new ScriptExtractor(dj, SETTINGS.EXTRACT.TO,scriptApi) ;
return se;
}
/* just to a summary of what happened
*/
function sumLog(infos) {
// summarize
Logger.log('These projected were extracted on ' + new Date().toLocaleString() +
' from ' + SETTINGS.PARENT.SCRIPTS + ' to ' + SETTINGS.EXTRACT.TO + '\n' +
infos.filter(function(d) {
return d.extracted;
})
.map(function(d) {
return d.title + ':Last version was from ' + new Date(d.modifiedDate).toLocaleString();
}).join("\n"));
Logger.log('These projected were skipped on ' + new Date().toLocaleString() +
' from ' + SETTINGS.PARENT.SCRIPTS + '\n' +
infos.filter(function(d) {
return !d.extracted;
})
.map(function(d) {
return d.title + ':Last version was from ' + new Date(d.modifiedDate).toLocaleString();
}).join("\n"));
}
// run last
function doSheet () {
// this is the extractor handle
var extractor = getExtractor();
// get all the info files
var result = extractor.getAllTheInfos();
if (!result.success) {
throw 'failed to get all the infos ' + JSON.stringify(result);
}
var infos = result.data.content;
writeSummarySpreadsheet ({
infos: infos,
id: '1DlKpVVYCrCPNfRbGsz6N_K3oPTgdC9gQIKi0aNb42uI',
name: 'list',
gitRoot: 'https://github.com/brucemcpherson/',
searchRoot: 'http://ramblings.mcpher.com/system/app/pages/search?scope=search-site&q=',
ideRoot: 'https://script.google.com/a/mcpher.com/d/'
})
}
function writeSummarySpreadsheet(options) {
if(!options) return;
const id = options.id;
const name = options.name;
const infos = options.infos;
const gitRoot = options.gitRoot;
const searchRoot = options.searchRoot;
const ideRoot = options.ideRoot;
if(!id || !name || !infos || !gitRoot) {
throw 'missing options from summary sheet'
}
const fiddler = new cUseful.Fiddler(SpreadsheetApp.openById(id).getSheetByName(name));
fiddler.setData(infos.map(function(f) {
return {
name: f.title,
id: f.id,
created: new Date(f.createdDate),
modified: new Date(f.modifiedDate),
noticed: new Date(f.noticed),
github: gitRoot + f.title,
ideLink: ideRoot ? ideRoot + f.id + '/edit?usp=drive_web' : '',
modules: f.modules.map(function(g) {
return g.name;
}).join(','),
searchLink: searchRoot + f.title
};
})).dumpValues();
}