Skip to content

Commit

Permalink
$mol_file fix remove directory
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 10, 2024
1 parent 4936be3 commit 18124ca
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 210 deletions.
66 changes: 39 additions & 27 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ namespace $ {
@ $mol_mem_key
static root( [ root, paths ] : [root: string, paths: readonly string[] ] ) {
return this.make({
root : ()=> $mol_file.absolute( root ) ,
root : ()=> this.$.$mol_file.root( root ) ,
paths: $mol_const(paths)
})
}

static relative( root : string, paths: readonly string[] ) {
return $mol_build.root( [ $mol_file.relative( root ).path(), paths ])
return this.$.$mol_build.root( [ $mol_file.relative( root ).path(), paths ])
}

@ $mol_mem
server() {
return $mol_build_server.make({
return this.$.$mol_build_server.make({
build : $mol_const( this ) ,
})
}

root() {
return $mol_file.relative( '.' )
return this.$.$mol_file.relative( '.' )
}

paths() {
Expand Down Expand Up @@ -63,11 +63,13 @@ namespace $ {
const name = file.name()

const tree = this.$.$mol_tree2_from_string( file.text() , file.path() )
const dir = file.parent().path()

let content = ''
for( const step of tree.select( 'build' , null ).kids ) {

const res = this.$.$mol_run.spawn( { command: step.text(), dir: file.parent().path(), dirty: true } ).stdout.toString().trim()
const res = this.$.$mol_file.watch_off(() => this.$.$mol_run.spawn( { command: step.text(), dir } ), dir )
.stdout.toString().trim()
if( step.type ) content += `let ${ step.type } = ${ JSON.stringify( res ) }`

}
Expand All @@ -92,7 +94,7 @@ namespace $ {
const js_map = target.resolve( js.name() + '.map' )
const dts = target.resolve( source.name() + '.d.ts' )
const dts_map = target.resolve( dts.name() + '.map' )

const js_text = this.$.$mol_tree2_js_to_text( this.$.$mol_view_tree2_to_js( tree ) )
js.text( this.$.$mol_tree2_text_to_string( js_text ) + '\n//# sourceMappingURL=' + js_map.relate( target ) )
js_map.text( JSON.stringify( this.$.$mol_tree2_text_to_sourcemap( js_text ), null, '\t' ) )
Expand All @@ -118,7 +120,7 @@ namespace $ {
const file = $mol_file.absolute( path )
const name = file.name()
const script = file.parent().resolve( `-css/${ name }.ts` )

const id = file.relate( this.root() )
const styles = file.text()
const code = 'namespace $ { $'+`mol_style_attach( ${ JSON.stringify( id ) },\n ${ JSON.stringify( styles ) }\n) }`
Expand Down Expand Up @@ -150,7 +152,7 @@ namespace $ {

@ $mol_mem_key
mods( [ path , exclude ] : [ path : string , exclude? : readonly string[] ] ) {

const mods : $mol_file[] = []
for (const child of this.sorted_sub(path)) {

Expand Down Expand Up @@ -788,9 +790,12 @@ namespace $ {

}

@ $mol_action
protected now() { return Date.now() }

@ $mol_mem_key
bundleJS( { path , exclude , bundle } : { path : string , exclude : readonly string[] , bundle : string } ) : $mol_file[] {
const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )
var targetJS = pack.resolve( `-/${bundle}.js` )

Expand Down Expand Up @@ -850,7 +855,7 @@ namespace $ {

@ $mol_mem_key
bundleMJS( { path , exclude , bundle } : { path : string , exclude : readonly string[] , bundle : string } ) : $mol_file[] {
const start = Date.now()
const start = this.now()
const [ targetJS, targetJSMap ] = this.bundleJS({ path, exclude, bundle })
if (! targetJS) return []

Expand All @@ -865,7 +870,7 @@ namespace $ {
@ $mol_mem_key
bundleAuditJS( { path , exclude , bundle } : { path : string , exclude : readonly string[] , bundle : string } ) : $mol_file[] {

const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )

var target = pack.resolve( `-/${bundle}.audit.js` )
Expand Down Expand Up @@ -904,7 +909,7 @@ namespace $ {

@ $mol_mem_key
bundle_test_js([ path , exclude , bundle ] : [ path : string , exclude : readonly string[] , bundle : string ]) {
const start = Date.now()
const start = this.now()
const pack = $mol_file.absolute( path )

const root = this.root()
Expand Down Expand Up @@ -962,7 +967,15 @@ namespace $ {
bundleAndRunTestJS( { path , exclude , bundle } : { path : string , exclude : readonly string[] , bundle : string } ) : $mol_file[] {
const [ target , targetMap ] = this.bundle_test_js([ path, exclude, bundle ])
if( bundle === 'node' ) {
this.$.$mol_run.spawn( { command: ['node', '--enable-source-maps', '--trace-uncaught', target.relate( this.root() ) ], dir: this.root().path() } )
const dir = this.root().path()

this.$.$mol_file.watch_off(() =>
this.$.$mol_run.spawn( {
command: ['node', '--enable-source-maps', '--trace-uncaught', target.relate( this.root() ) ],
dir
} ),
dir
)
}

return [ target , targetMap ]
Expand All @@ -971,7 +984,7 @@ namespace $ {
@ $mol_mem_key
bundleTestHtml( path: string ) : $mol_file[] {

const start = Date.now()
const start = this.now()

const pack = $mol_file.absolute( path )
const source = pack.resolve( 'index.html' )
Expand Down Expand Up @@ -1005,7 +1018,7 @@ namespace $ {

@ $mol_mem_key
bundleDTS( { path , exclude , bundle } : { path : string , exclude? : readonly string[] , bundle : string } ) : $mol_file[] {
const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )

var target = pack.resolve( `-/${bundle}.d.ts` )
Expand Down Expand Up @@ -1033,7 +1046,7 @@ namespace $ {

@ $mol_mem_key
bundleViewTree( { path , exclude , bundle } : { path : string , exclude? : readonly string[] , bundle : string } ) : $mol_file[] {
const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )

var target = pack.resolve( `-/${bundle}.view.tree` )
Expand All @@ -1052,9 +1065,8 @@ namespace $ {

@ $mol_mem_key
bundleMetaTree( { path , exclude , bundle } : { path : string , exclude? : readonly string[] , bundle : string } ) : $mol_file[] {
const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )

var target = pack.resolve( `-/${bundle}.meta.tree` )

const sortedPaths = this.graph( [path , exclude ] ).sorted
Expand Down Expand Up @@ -1100,7 +1112,7 @@ namespace $ {
@ $mol_mem_key
bundleReadmeMd( [ path , exclude ] : [ path : string , exclude : readonly string[] ] ) : $mol_file[] {

const start = Date.now()
const start = this.now()

const root = this.root()
const pack = $mol_file.absolute( path )
Expand Down Expand Up @@ -1130,7 +1142,7 @@ namespace $ {

@ $mol_mem_key
bundlePackageJSON( [ path , exclude ] : [ path : string , exclude : readonly string[] ] ) : $mol_file[] {
const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )

const source = pack.resolve( `package.json` )
Expand Down Expand Up @@ -1214,7 +1226,7 @@ namespace $ {

const targets : $mol_file[] = []

const start = Date.now()
const start = this.now()
const html = pack.resolve( 'index.html' )
const tree = pack.resolve( 'index.xml.tree' )
const target = pack.resolve( '-/index.html' )
Expand Down Expand Up @@ -1258,10 +1270,10 @@ namespace $ {
}
return
}
const start = Date.now()
const start = this.now()

const target = file.clone(pack.resolve( `-/${ file.relate( root ) }` ).path())

if (! target) return
targets.push( target )
this.logBundle( target , Date.now() - start )
}
Expand All @@ -1279,7 +1291,7 @@ namespace $ {

@ $mol_mem_key
bundleCordova( [ path , exclude ] : [ path : string , exclude? : readonly string[] ] ) : $mol_file[] {
const start = Date.now()
const start = this.now()
const pack = $mol_file.absolute( path )
const cordovaOut = pack.resolve( '-' )
const cordova = pack.resolve( '-cordova' )
Expand Down Expand Up @@ -1309,7 +1321,7 @@ namespace $ {
bundleCSS( { path , exclude , bundle } : { path : string , exclude? : readonly string[] , bundle : string } ) : $mol_file[] {
if( bundle === 'node' ) return []

const start = Date.now()
const start = this.now()
var pack = $mol_file.absolute( path )
var sources = [] as $mol_file[] // this.sourcesCSS( [ path , exclude ] )

Expand Down Expand Up @@ -1368,7 +1380,7 @@ namespace $ {
)

const targets = Object.keys( locales ).map( lang => {
const start = Date.now()
const start = this.now()
const target = pack.resolve( `-/${bundle}.locale=${ lang }.json` )

const locale = locales[ lang ]
Expand Down Expand Up @@ -1407,7 +1419,7 @@ namespace $ {

@ $mol_mem_key
bundleDepsJSON( { path , exclude , bundle } : { path : string , exclude? : readonly string[] , bundle : string } ) : $mol_file[] {
const start = Date.now()
const start = this.now()
const pack = $mol_file.absolute( path )

const list = this.sourcesAll( [ path , exclude ] )
Expand Down
23 changes: 12 additions & 11 deletions build/ensure/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace $ {
}

protected override pull_run(dir: string) {
const out = this.$.$mol_run.spawn({ command: 'git rev-parse --abbrev-ref --symbolic-full-name HEAD', dir, dirty: true })
const out = this.$.$mol_run.spawn({
command: 'git rev-parse --abbrev-ref --symbolic-full-name HEAD', dir,
})
const current_branch = out.stdout.toString().trim()
// когда не на ветке - не надо пулить, например сборка во время git bisect
if (! current_branch) return false
Expand All @@ -32,7 +34,7 @@ namespace $ {
}

const timeout = this.pull_timeout()
this.$.$mol_run.spawn( { command, dir, timeout, dirty: true }).stdout.toString().trim()
this.$.$mol_run.spawn( { command, dir, timeout }).stdout.toString().trim()
return true
}

Expand Down Expand Up @@ -69,23 +71,22 @@ namespace $ {
const repo = this.repo(dir)
if (! repo) return 'master'

const res = this.$.$mol_run.spawn( { command: ['git', 'remote', 'show', repo.url ], dir, dirty: true } )
const res = this.$.$mol_run.spawn( { command: ['git', 'remote', 'show', repo.url ], dir } )

return res.stdout.toString().match( /HEAD branch: (.*?)\n/ )?.[1] ?? 'master'
}

protected override init(dir: string) {
const repo = this.repo(dir)
if (! repo) throw new Error(`"${dir}" not a repo`)
const { url, branch } = repo
this.$.$mol_run.spawn( { command: ['git', 'init'], dir } )

this.$.$mol_run.spawn( { command: ['git', 'init'], dir, dirty: true } )
const branch = repo.branch ?? this.branch_remote(dir)

const command = ['git', 'remote', 'add', '--track', branch, 'origin' , repo.url ]
this.$.$mol_run.spawn( { command, dir, dirty: true } )
// this.$.$mol_run.spawn( { command: [ 'git', 'pull', 'origin', branch ], dir, dirty: true } )
this.$.$mol_run.spawn( { command: [ 'git', 'checkout', branch ], dir, dirty: true } )
const branch_norm = branch ?? this.branch_remote(dir)

this.$.$mol_run.spawn( { command: ['git', 'remote', 'add', '--track', branch_norm, 'origin' , url ], dir } )
this.$.$mol_run.spawn( { command: [ 'git', 'pull', 'origin', branch_norm ], dir } )

return null
}

Expand All @@ -103,7 +104,7 @@ namespace $ {
]

const dir = this.root().path()
this.$.$mol_run.spawn( { command, dir, dirty: true } )
this.$.$mol_run.spawn( { command, dir } )

return null
}
Expand Down
20 changes: 13 additions & 7 deletions build/ensure/vcs/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ namespace $ {
if (this.pull_disabled) return false

try {
return this.pull_run(dir)
return this.$.$mol_file.watch_off(() => this.pull_run(dir), dir)
} catch (e) {
if (e instanceof $mol_run_error && e.cause.timeout_kill) {
this.pull_disabled = true

this.$.$mol_log3_warn({
place: `${this}.pull()`,
message: `Timeout - pull disabled`,
hint: 'Check connection',
})

this.pull_disabled = true
return true
}

Expand All @@ -75,18 +75,24 @@ namespace $ {
if( mod.exists()) {
if (! this.inited(path)) {
if (! this.repo(path) ) return false
this.init(path)

this.$.$mol_file.watch_off(() => this.init(path), path)
}

this.pull( path )
mod.reset()
for ( const sub of mod.sub() ) sub.reset()

// mod.reset()
// for ( const sub of mod.sub() ) sub.reset()

return true
}

if (this.repo(path)) {
this.clone(path)
mod.reset()

this.$.$mol_file.watch_off(() => this.clone(path), path)

// mod.reset()
// for ( const sub of mod.sub() ) sub.reset()
return true
}

Expand Down
4 changes: 3 additions & 1 deletion build/server/server.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ namespace $ {
) => boolean | void
) {
const pending_urls = {} as Record<string, Promise<unknown> | undefined>
const wrapped = $mol_wire_async(mdl)

const cb = async (
req : typeof $node.express.request ,
res : typeof $node.express.response ,
next : (err?: unknown) => any
) => {
try {
const call_next = await $mol_wire_async(mdl)(req, res)
const call_next = await wrapped(req, res)
if (! call_next) return
await Promise.resolve()
delete pending_urls[req.url]
next()
} catch (err) {
delete pending_urls[req.url]
console.error(err)
next(err)
}
}
Expand Down
Loading

0 comments on commit 18124ca

Please sign in to comment.