@@ -53,6 +53,8 @@ export const getGeneratedCode = createSelector([
53
53
getReplayEnabled , getDescriptorOptions , getInspectorSettings , getIndentString ,
54
54
] , ( selected , autoActive , treePath , replayEnabled , descOptions , settings , tab ) => {
55
55
56
+ let shouldShowTokenify = false ;
57
+
56
58
function makeNicePropertyPath ( segments : string [ ] ) : string {
57
59
const regex = / ^ [ a - z A - Z _ $ ] [ 0 - 9 a - z A - Z _ $ ] * $ / m;
58
60
@@ -93,27 +95,27 @@ export const getGeneratedCode = createSelector([
93
95
94
96
const res : BatchPlayCommandOptionsExtended = { } ;
95
97
96
- if ( hasAnySync ) { res . synchronousExecution = true ; }
97
- else if ( hasAnyAsync ) { res . synchronousExecution = false ; }
98
+ if ( hasAnySync ) { res . synchronousExecution = true ; }
99
+ else if ( hasAnyAsync ) { res . synchronousExecution = false ; }
98
100
99
- if ( modalIsExecute ) { res . modalBehavior = "execute" ; }
100
- else if ( modalIsWait ) { res . modalBehavior = "wait" ; }
101
- else if ( ! modalIsDefault ) { res . modalBehavior = "fail" ; }
101
+ if ( modalIsExecute ) { res . modalBehavior = "execute" ; }
102
+ else if ( modalIsWait ) { res . modalBehavior = "wait" ; }
103
+ else if ( ! modalIsDefault ) { res . modalBehavior = "fail" ; }
102
104
103
105
return res ;
104
106
}
105
107
106
108
// adds indentation
107
- function idt ( str :string ) :string {
109
+ function idt ( str : string ) : string {
108
110
return str . split ( "\n" ) . map ( l => tab + l ) . join ( "\n" ) ;
109
111
}
110
112
111
- function udt ( str : string ) : string {
113
+ function udt ( str : string ) : string {
112
114
return str . split ( "\n" ) . map ( l => l . replace ( tab , "" ) ) . join ( "\n" ) ;
113
115
}
114
116
115
117
// replaces quotes
116
- function qts ( str :string ) :string {
118
+ function qts ( str : string ) : string {
117
119
if ( settings . singleQuotes ) {
118
120
str = str . replaceAll ( `"` , `'` ) ;
119
121
}
@@ -124,13 +126,23 @@ export const getGeneratedCode = createSelector([
124
126
const wrappers = settings . codeWrappers ;
125
127
126
128
if ( selected . length >= 1 || autoActive ) {
127
- let data :any = null , iDesc : IDescriptor [ ] = [ ] ;
129
+ let data : any = null , iDesc : IDescriptor [ ] = [ ] ;
128
130
129
131
const stringifyOptions = {
130
132
singleQuotes : settings . singleQuotes ,
131
133
indent : tab ,
134
+ transform : ( input : any | object , prop : number | string | symbol , originalResult : string ) => {
135
+ if ( settings . tokenify && prop === "_path" ) {
136
+ shouldShowTokenify = true ;
137
+ console . log ( input , originalResult ) ;
138
+ const res = qts ( `await tokenify("${ input . _path . replaceAll ( "\\" , "/" ) } ")` ) ;
139
+ return res ;
140
+ }
141
+ return originalResult ;
142
+ } ,
132
143
} ;
133
144
145
+ const tokenifyInfo = "// Please make sure that file system access permission in manifest.json has correct value.\n\n" ;
134
146
const playAbleInfo = "// Alchemist can't generate code from the reply of replay and from dispatched code." ;
135
147
const notifierWarning = "// Events recognized as notifiers are not re-playable in most of the cases. There is high chance that generated code won't work.\n\n" ;
136
148
@@ -139,7 +151,7 @@ export const getGeneratedCode = createSelector([
139
151
} else if ( autoActive ) {
140
152
iDesc = [ autoActive ] ;
141
153
}
142
- if ( iDesc . some ( item => [ "replies" , "dispatcher" ] . includes ( item . originalReference . type ) ) ) {
154
+ if ( iDesc . some ( item => [ "replies" , "dispatcher" ] . includes ( item . originalReference . type ) ) ) {
143
155
return playAbleInfo ;
144
156
}
145
157
data = iDesc . map ( item => addPerItemOptions ( item ) ) ;
@@ -149,20 +161,20 @@ export const getGeneratedCode = createSelector([
149
161
if ( Array . isArray ( data ) ) {
150
162
data . forEach ( d => {
151
163
if ( settings . hideDontRecord ) {
152
- delete d . dontRecord ;
164
+ delete d . dontRecord ;
153
165
}
154
166
if ( settings . hideForceNotify ) {
155
- delete d . forceNotify ;
167
+ delete d . forceNotify ;
156
168
}
157
169
if ( settings . hide_isCommand ) {
158
170
delete d . _isCommand ;
159
- }
171
+ }
160
172
} ) ;
161
173
}
162
174
163
175
for ( let i = 0 ; i < data . length ; i ++ ) {
164
176
const item = data [ i ] ;
165
- RawDataConverter . convertFakeRawInCode ( item , descOptions ) ;
177
+ RawDataConverter . convertFakeRawInCode ( item , descOptions ) ;
166
178
}
167
179
168
180
let strPinned = "" ;
@@ -175,34 +187,46 @@ export const getGeneratedCode = createSelector([
175
187
const commandOptions = addCommonOptions ( iDesc ) ;
176
188
177
189
const strOptions = idt ( stringifyObject ( commandOptions , stringifyOptions ) ) ;
178
- const strDesc :string = stringifyObject ( data , stringifyOptions ) ;
190
+ const strDesc : string = stringifyObject ( data , stringifyOptions ) ;
179
191
180
192
181
193
const strExecModalImport = addModules ? qts ( `const {executeAsModal} = require("photoshop").core;\n` ) : "" ;
182
- const strBatchPlayImport = addModules ? qts ( `const {batchPlay} = require("photoshop").action;\n\n` ) : "" ;
194
+ const strBatchPlayImport = addModules ? qts ( `const {batchPlay} = require("photoshop").action;\n` ) : "" ;
195
+ const strTokenifyImport = addModules && shouldShowTokenify ? qts ( `const {localFileSystem: fs} = require("uxp").storage;\n` ) : "" ;
196
+ const strNewLine = addModules ? "\n" : "" ;
183
197
184
198
const strBatchPlay = `const result = await batchPlay(\n${ idt ( strDesc ) } ,\n${ strOptions } \n);${ strPinned } ` ;
185
199
const strActionCommand = `async function actionCommands() {\n${ idt ( strBatchPlay ) } \n}\n\n` ;
186
200
187
201
const strCall = qts ( `async function runModalFunction() {\n${ tab } await executeAsModal(actionCommands, {"commandName": "Action Commands"});\n}\n\nawait runModalFunction();\n` ) ;
202
+ const strTokenify = shouldShowTokenify ? qts ( `async function tokenify(url){\n${ tab } return fs.createSessionToken(await fs.getEntryWithUrl("file:" + url));\n}\n\n` ) : "" ;
188
203
189
204
let banner = "" ;
190
205
if ( iDesc . some ( item => item . originalReference . type === "notifier" ) ) {
191
206
banner = notifierWarning ;
192
207
}
208
+ if ( shouldShowTokenify ) {
209
+ banner += tokenifyInfo ;
210
+ }
193
211
194
212
195
- if ( wrappers === "batchPlay" ) {
213
+ if ( wrappers === "batchPlay" ) {
196
214
return (
197
215
banner +
198
216
strBatchPlayImport +
217
+ strTokenifyImport +
218
+ strNewLine +
219
+ strTokenify +
199
220
strBatchPlay
200
221
) ;
201
- } else if ( wrappers === "modal" ) {
222
+ } else if ( wrappers === "modal" ) {
202
223
return (
203
224
banner +
204
225
strExecModalImport +
205
226
strBatchPlayImport +
227
+ strTokenifyImport +
228
+ strNewLine +
229
+ strTokenify +
206
230
strActionCommand +
207
231
strCall
208
232
) ;
0 commit comments