Skip to content

Commit b58a6b0

Browse files
author
Tobias Graupner
committed
Feature-Request: Import classes like Atelier it does #12
Downloads classes in folder structure
1 parent ab14f1b commit b58a6b0

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

cos.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,21 @@ const activate = context => {
185185
return cb()
186186
}
187187

188-
let exportDir = root + '/src/'
189-
if ( !fs.existsSync( exportDir ) ) fs.mkdirSync( exportDir )
190-
exportDir += doc.cat + '/'
191-
if ( !fs.existsSync( exportDir ) ) fs.mkdirSync( exportDir )
188+
let exportDir = root + 'src/' + doc.cat + '/'
189+
190+
if (doc.cat == "CLS") {
191+
192+
let oldFilePath = doc.name.split(".");
193+
let dirElements = oldFilePath.length-2;
194+
let newFileName = oldFilePath.slice(dirElements,dirElements+2).toString().replace(/,/g ,".");
195+
let newFilePath = oldFilePath.slice(0,dirElements).toString().replace(/,/g ,"/") + "/";
196+
197+
exportDir += newFilePath;
198+
doc.name = newFileName;
199+
200+
}
201+
202+
if ( !fs.existsSync( exportDir ) ) mkdirSyncP(exportDir)
192203

193204
const filepath = exportDir + doc.name
194205
fs.writeFileSync( filepath, doc.content.join('\n') )
@@ -199,6 +210,18 @@ const activate = context => {
199210

200211
}
201212

213+
const mkdirSyncP = (pathToFile) => {
214+
if (!fs.existsSync(pathToFile)) {
215+
let dirName = "";
216+
let filePathSplit = pathToFile.split('/');
217+
for (let index = 0; index < filePathSplit.length; index++) {
218+
dirName += filePathSplit[index]+'/';
219+
if (!fs.existsSync(dirName))
220+
fs.mkdirSync(dirName);
221+
}
222+
}
223+
}
224+
202225
const load = ( doc, cb ) => {
203226

204227
const loaded = ( err, json ) => {
@@ -231,15 +254,14 @@ const activate = context => {
231254
})
232255
}
233256

234-
235257
const onGetDocs = ( err, json ) => {
236-
258+
237259
if ( err ) return log( 'getDocs ERROR' )
238260

239261
const list = json.result.content
240262
log( '' )
241263
log( 'list: ' + list.length )
242-
const docs = list.filter( doc => ( doc.cat !== 'CSP' ) && ( doc.name.substring( 0, 1 ) !== '%' ) && ( doc.name.substring( 0, 12 ) !== 'INFORMATION.' ) )
264+
const docs = list.filter( doc => ( doc.cat !== 'CSP' ) && ( doc.name.substring( 0, 1 ) !== '%' ) && ( doc.name.substring( 0, 12 ) !== 'INFORMATION.' ) )
243265
log( 'without % and CSP and INFORMATION: ' + docs.length )
244266
log( '' )
245267
exportDocs( docs, () => {

0 commit comments

Comments
 (0)