Skip to content

Commit d4a4480

Browse files
committed
use original filename in export
1 parent 1f9f897 commit d4a4480

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

commands/currentdoc/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const CurrentDoc = env => () => {
6464
return {
6565
name: codename,
6666
content: code.split( /\r?\n/g ), // get code lines array
67-
error: ''
67+
error: '',
68+
fileName: fullname
6869
}
6970

7071
}

commands/export/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ const mkdir = require('./mkdir-p-sync') // mkdir -p 'path/to/file'
77
// see module.exports
88
let api = {
99
getDocNames: ( opts, cb ) => cb( null, {} ),
10-
getDoc: ( docname, cb ) => cb( null, {} )
10+
getDoc: ( docname, cb ) => cb( null, {} )
1111
}
1212

1313
// see module.exports
14-
let log = (...msg) => console.log('cos.export:', ...msg )
14+
let log = (...msg) => console.log('cos.export:', ...msg )
1515
// export options
1616
let root = '.'
1717
let folder = 'src'
1818
let atelier = false
19-
let doc2file = docname => docname
19+
let doc2file = docname => docname
2020

21-
// Export one document
21+
// Export one document
2222
const ExportDoc = ( doc, next ) => ({ error, data }) => {
2323

2424
if ( error ){
2525
log( `${ JSON.stringify( error ) }\n` )
2626
return
2727
}
2828

29-
const { content, status } = data.result
29+
const { content, status } = data.result
3030

3131
// atelier: 'mypkg.subpkg.myclass.cls' => 'mypkg/subpkg/myclass.cls'
3232
const filename = doc2file( doc.name )
33-
const fullname = [ root, folder, doc.cat, filename ].join( path.sep )
33+
const fullname = doc.fileName || ([ root, folder, doc.cat, filename ].join( path.sep ))
3434
const folders = path.dirname( fullname )
3535

3636
if ( !fs.existsSync( folders ) ) mkdir( folders )
@@ -86,14 +86,14 @@ module.exports = env => {
8686
const exportAll = () => {
8787

8888
if ( !root ){
89-
log( `COS.EXPORT: Open folder before export - Ctrl+K, Ctrl+O` )
90-
return
89+
log( `COS.EXPORT: Open folder before export - Ctrl+K, Ctrl+O` )
90+
return
9191
}
9292

9393
init()
9494

9595
log( '\nLoad documents list ...' )
96-
api.getDocNames(
96+
api.getDocNames(
9797

9898
{ category, generated, filter }, //doclist options
9999
( error, data ) => doclist( { error, data } ) //callback wrapper
@@ -103,4 +103,4 @@ module.exports = env => {
103103

104104
return { exportAll, ExportDoc }
105105

106-
}
106+
}

extension.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ const vscode = require('vscode')
22
const { workspace, window } = vscode
33
const http = require('http')
44

5-
const API = require('cos-api4node')
5+
const API = require('cos-api4node')
66
const LOG = require( './log' )
77
const languages = require('./package.json')[ 'contributes' ][ 'languages' ].map( lang => lang.id )
88
const panel = require( './status-bar-panel' )
99
const CmdExport = require( './commands/export' )
10-
const { CurrentDoc }= require( './commands/currentdoc' )
11-
const IsApiError = require( './is-api-error' )
10+
const { CurrentDoc }= require( './commands/currentdoc' )
11+
const IsApiError = require( './is-api-error' )
1212

1313
const activate = context => {
1414

1515
const log = LOG( window )
1616

1717
const Config = workspace => {
1818

19-
let options = null;
19+
let options = null;
2020
const init = () =>{ options = workspace.getConfiguration( 'cos' ) }
2121
init()
2222

2323
return {
2424

25-
init,
25+
init,
2626
conn: () => {
2727
const _conn = options.get( 'conn' )
28-
_conn.toString = () => JSON.stringify( Object.assign( {}, _conn, { password: '***' } ), null, 4 )
28+
_conn.toString = () => JSON.stringify( Object.assign( {}, _conn, { password: '***' } ), null, 4 )
2929
return _conn
3030
},
3131
export: () => {
@@ -56,19 +56,19 @@ const activate = context => {
5656

5757
const currentDoc = CurrentDoc({ window, languages, log })
5858

59-
const Save = ({ name, log }) => ( err, data ) => {
59+
const Save = ({ name, log, fileName }) => ( err, data ) => {
6060

6161
// IsApiError, ExportDoc - global
6262
const isGetDocError = IsApiError( name, 'getDoc', log )
6363
if ( isGetDocError({ err, data }) ) return
6464

6565
const completed = () => log( 'Completed.' )
66-
const exportDoc = ExportDoc( { name, cat: data.result.cat }, completed )
66+
const exportDoc = ExportDoc( { name, cat: data.result.cat, fileName }, completed )
6767

6868
exportDoc( { err, data } )
6969
}
7070

71-
const Export = ( { api, name, log } ) => ( err, data ) => {
71+
const Export = ( { api, name, log, fileName } ) => ( err, data ) => {
7272
// IsApiError, Save - from upper scope
7373
const isCompileError = IsApiError( name, 'compile', log )
7474
if ( isCompileError({ err, data }) ) return;
@@ -77,17 +77,17 @@ const activate = context => {
7777
// so, just export again
7878
data.console.forEach( ci => log( ci ) ) //output compilation log
7979
//log( ` Export ${ name }` )
80-
const save = Save( { name, log } )
80+
const save = Save( { name, log, fileName } )
8181
api.getDoc( name, save )
8282
}
8383

84-
const Compile = ( { api, name, log } ) => ( err, data ) => {
84+
const Compile = ( { api, name, log, fileName } ) => ( err, data ) => {
8585

8686
// IsApiError, Export
8787
const isImportError = IsApiError( name, 'import', log )
8888
if ( isImportError({ err, data }) ) return;
8989

90-
const exportCurrent = Export( { api, name, log } )
90+
const exportCurrent = Export( { api, name, log, fileName } )
9191
//log( `Compile ${ name }` )
9292
api.compile( name, exportCurrent )
9393

@@ -98,15 +98,15 @@ const activate = context => {
9898
const importCompileExport = () => {
9999

100100
// api, Compile, log
101-
const { name, content, error } = currentDoc()
101+
const { name, content, error, fileName } = currentDoc()
102102
if ( error ) return log( error )
103103

104-
const compile = Compile({ api, name, log } )
104+
const compile = Compile({ api, name, log, fileName } )
105105
//log( ` Import ${ name }` )
106-
api.putDoc( name,
107-
{ enc: false, content },
108-
{ ignoreConflict: true },
109-
compile
106+
api.putDoc( name,
107+
{ enc: false, content },
108+
{ ignoreConflict: true },
109+
compile
110110
)
111111

112112
}
@@ -118,4 +118,4 @@ const activate = context => {
118118

119119
}
120120

121-
module.exports = { activate, deactivate: () => {} }
121+
module.exports = { activate, deactivate: () => {} }

0 commit comments

Comments
 (0)