Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
45cd263
skeleton
nin--jin Dec 22, 2019
7babb88
$mol_source -> $mol_load
nin--jin Dec 22, 2019
70c1ece
Merge branch 'master' into new-builder
nin--jin Jun 19, 2020
8132bfd
Draft
nin--jin Sep 21, 2020
2563214
Merge branch 'master' into new-builder-dev
stan-donarise Feb 8, 2024
a595a9b
regexp upd
stan-donarise Feb 8, 2024
5505d57
$mam_convert initial; bundles belong to pack,
stan-donarise Feb 9, 2024
43843a7
$mam_root controls sources, converts and bundles
stan-donarise Feb 9, 2024
2e7bf5c
$mam_slice source_classes, convert_classes, bundle
stan-donarise Feb 9, 2024
524f9f1
$mam_bundle: remove pack prop
stan-donarise Feb 9, 2024
2e4ecf1
exclude mam.drawio.svg from bundling
stan-donarise Feb 9, 2024
013375e
$mam_convert: { file, search_deps }
stan-donarise Feb 9, 2024
69ef2c2
$mam_sourse: path dir duplication support
stan-donarise Feb 10, 2024
13e6adf
bundles
stan-donarise Feb 10, 2024
a368fb3
$mam_convert: promoted
stan-donarise Feb 10, 2024
8922530
$mam_source_meta_tree, $mam_convert_meta_tree
stan-donarise Feb 10, 2024
f49cada
$mam_source_ts: deps by AST
stan-donarise Feb 10, 2024
8341b21
$mam_bundle_audit_js
stan-donarise Feb 10, 2024
bc5a258
$mam_source: instances instead of singleton
stan-donarise Feb 10, 2024
d70e1ac
$mam_convert: instances instead of singleton
stan-donarise Feb 10, 2024
5bb874f
$mam_convert: promoted -> generated_sources
stan-donarise Feb 10, 2024
240816d
add bundles, sources, converts
stan-donarise Feb 10, 2024
1c23709
$mam_source_ts: deps from `require `
stan-donarise Feb 10, 2024
50f5790
$mam_source_glsl
stan-donarise Feb 10, 2024
5da83e7
chore
stan-donarise Feb 11, 2024
9898f6d
formatting
stan-donarise Feb 11, 2024
7c95eed
fix node_deps seach
stan-donarise Feb 11, 2024
900d99f
$mam_source_css fix, chore
stan-donarise Feb 11, 2024
a84646b
$mam_source_view_ts
stan-donarise Feb 11, 2024
8fba32d
a
Jul 22, 2025
c7a9186
fix types its alive
Jul 22, 2025
7e8deb1
npm start mam/start is work
Aug 22, 2025
11efdf9
del unused
Aug 22, 2025
4547ab9
try to fix 1 use jsx
Aug 22, 2025
ee5b68e
remove mol submodule
Aug 22, 2025
5ac32bf
f
Aug 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"port": 9229,
"program": "${workspaceRoot}/mol/build/-/node.js"
},
{
"type": "node",
"request": "launch",
"name": "MAM start",
"runtimeArgs": ["--inspect-brk=9229"],
"port": 9229,
"program": "${workspaceRoot}/mam/start/-/node.js",
"args": ["mam/start"]
},
{
"type": "chrome",
"request": "launch",
Expand Down
10 changes: 5 additions & 5 deletions mam.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Error.stackTraceLimit = 50;
Error.stackTraceLimit = 1;

declare let _$_: { new(): {} } & typeof globalThis
declare let _$_: { new (): {} } & typeof globalThis;
declare class $ extends _$_ {}

namespace $ {
export type $ = typeof $$
export type $ = typeof $$;
export declare class $$ extends $ {}
namespace $$ {
export type $$ = $
export type $$ = $;
}
}

module.exports = $
module.exports = $;
284 changes: 284 additions & 0 deletions mam/_mam.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions mam/bundle/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace $ {

/** Makes one bundle from all required sources. */
export class $mam_bundle extends $mol_object2 {

@ $mol_mem
root() {
return undefined as any as $mam_root
}

/** Used when the generated bundles should be the same for any slice of pack */
@ $mol_mem_key
generated_for_pack( pack: $mam_package ) {
return [] as $mol_file[]
}

/** Generated bundle by slice */
@ $mol_mem_key
generated( slice: $mam_slice ) {
return this.generated_for_pack( slice.pack() )
}

log( target: $mol_file, duration: number ) {

const path = target.relate( this.root().dir() )

this.$.$mol_log3_done({
place: this,
duration: `${duration}ms`,
message: `Built`,
path,
})

}

}

}
162 changes: 162 additions & 0 deletions mam/bundle/bundle_audit_js.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
namespace $ {
export class $mam_bundle_audit_js extends $mam_bundle {
@$mol_mem_key
generated(slice: $mam_slice) {
const start = Date.now();

const prefix = slice.prefix();

const output = slice.pack().output();
const target = output.resolve(`${prefix}.audit.js`);

this.ts_service(slice)?.recheck();

const errors = [] as Error[];

const paths = this.ts_paths(slice);

for (const path of paths) {
if (/\.d\.ts/.test(path)) continue;
this.root()
.convert([this.$.$mam_convert_ts, $mol_file.absolute(path)])
?.transpile_out();
// this.js_content( path ) // recheck on file change

const error = this.on_error(path);
if (!error) continue;

errors.push(new Error(error));
this.on_error(path, null); // ts will refill it on change
}

this.log(target, Date.now() - start);

if (errors.length) {
$mol_fail_hidden(
new $mol_error_mix(`Build fail ${slice.pack().dir().relate(slice.root().dir())}`, ...errors),
);
}

target.text(`console.info( '%c ▫ $mol_build ▫ Audit passed', 'color:forestgreen; font-weight:bolder' )`);

return [target];
}

@$mol_mem_key
ts_paths(slice: $mam_slice) {
const sources = [...slice.files()].filter((src) => /\.(?:d\.ts|ts|tsx)$/.test(src.name()));

if (/node/.test(slice.prefix())) {
const lines = [] as string[];
for (let dep of (slice as $mam_slice_node).node_deps()) {
lines.push("\t" + JSON.stringify(dep) + ": typeof import\( " + JSON.stringify(dep) + " )");
}
if (lines.length > 0) {
const node_types = slice.pack().dir().resolve(`-node/deps.d.ts`);
node_types.text("interface $node {\n " + lines.join("\n") + "\n}");
sources.push(node_types);
}
}

return sources.map((src) => src.path());
}

@$mol_mem_key
ts_service(slice: $mam_slice) {
const paths = this.ts_paths(slice);
if (!paths.length) return null;

const watchers = new Map<string, (path: string, kind: number) => void>();
let run = () => {};

var host = $node.typescript.createWatchCompilerHost(
paths,

{
...this.root().ts_options(),
// emitDeclarationOnly: true,
noEmit: true,
},

{
...$node.typescript.sys,
watchDirectory: (path, cb) => {
// console.log('watchDirectory', path )
watchers.set(path, cb);
return { close() {} };
},
writeFile: (path, data) => {
$mol_file.relative(path).text(data, "virt");
},
setTimeout: (cb: any) => {
// console.log('setTimeout' )
run = cb;
},
watchFile: (path: string, cb: (path: string, kind: number) => any) => {
// console.log('watchFile', path )
watchers.set(path, cb);
return { close() {} };
},
},

$node.typescript.createSemanticDiagnosticsBuilderProgram,

(diagnostic) => {
if (diagnostic.file) {
const error = $node.typescript.formatDiagnostic(diagnostic, {
getCurrentDirectory: () => this.root().dir().path(),
getCanonicalFileName: (path: string) => path.toLowerCase(),
getNewLine: () => "\n",
});
// console.log('XXX', error )
this.on_error(diagnostic.file.getSourceFile().fileName, error);
} else {
this.$.$mol_log3_fail({
place: `${this}.tsService()`,
message: String(diagnostic.messageText),
});
}
},

() => {}, //watch reports

[], // project refs

{
// watch options
synchronousWatchDirectory: true,
watchFile: 5,
watchDirectory: 0,
},
);

const service = $node.typescript.createWatchProgram(host);

const versions = {} as Record<string, number>;

return {
recheck: () => {
for (const path of paths) {
const version = $node.fs.statSync(path).mtime.valueOf();
// this.js_error( path, null )
if (versions[path] && versions[path] !== version) {
const watcher = watchers.get(path);
if (watcher) watcher(path, 2);
}
versions[path] = version;
}
run();
},
destructor: () => service.close(),
};
}

@$mol_mem_key
on_error(path: string, next = null as null | string) {
this.root()
.convert([this.$.$mam_convert_ts, $mol_file.absolute(path)])
?.transpile_out();
return next;
}
}
}
48 changes: 48 additions & 0 deletions mam/bundle/bundle_css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace $ {

export class $mam_bundle_css extends $mam_bundle {

@ $mol_mem_key
generated( slice: $mam_slice ) {
const start = Date.now()

const prefix = slice.prefix()
const output = slice.pack().output()

var sources = [] as $mol_file[] // this.sourcesCSS( { path, exclude } )

var target = output.resolve( `${prefix}.css` )
var targetMap = output.resolve( `${prefix}.css.map` )

// var root: any = null //$node['postcss'].root({})
// sources.forEach(
// src => {
// var root2 = $node['postcss'].parse( src.content(), { from: src.path() } )
// root = root ? root.append( root2 ): root2
// }
// )

// var processor = $node['postcss']([
// $node[ 'postcss-custom-properties' ]({
// preserve: true,
// }),
// $node[ 'postcss-color-function' ](),
// ])
// var result = processor.process( root, { to: target.relate(), map: { inline: false } } )

const result = {
css: '/* CSS compiles into js bundle now! */',
map: '/* CSS compiles into js bundle now! */',
}

target.text( result.css )
targetMap.text( JSON.stringify( result.map, null, '\t' ) )

this.log( target, Date.now() - start )

return [ target, targetMap ]
}

}

}
38 changes: 38 additions & 0 deletions mam/bundle/bundle_dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace $ {

export class $mam_bundle_dts extends $mam_bundle {

@ $mol_mem_key
generated( slice: $mam_slice ) {
const start = Date.now()

// const script = this.pack().output().resolve( `${prefix}.d.ts` )
// const map = this.pack().output().resolve( `${prefix}.d.ts.map` )

const prefix = slice.prefix()

const target = slice.pack().output().resolve( `${ prefix }.d.ts` )

const sources = [ ... slice.files() ].filter( file => /\.d\.ts$/.test( file.name() ) )
if( sources.length === 0 ) return []

const concater = new $mol_sourcemap_builder( target.parent().path() )

sources.forEach(
function( src ) {
if( ! src.exists() || ! src.text() ) return
concater.add( src.text(), src.relate( target.parent() ) )
}
)

target.text( concater.content + '\nexport = $;' )

this.log( target, Date.now() - start )

return [ target ]
// return [ script, map ]
}

}

}
43 changes: 43 additions & 0 deletions mam/bundle/bundle_files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace $ {
export class $mam_bundle_files extends $mam_bundle {
@$mol_mem_key
generated(slice: $mam_slice) {
const prefix = slice.prefix();
const output = slice.pack().output();

const root_dir = this.root().dir();

const targets: $mol_file[] = [];

const files = [...slice.files()].filter((file) => /meta.tree$/.test(file.name()));
files.forEach((source) => {
const tree = $mol_tree2.fromString(source.text(), source.path());

const pushFile = (file: $mol_file) => {
const start = Date.now();
const target = output.resolve(file.relate(root_dir));
target.buffer(file.buffer());
targets.push(target);
this.log(target, Date.now() - start);
};

const addFilesRecursive = (file: $mol_file) => {
if (!file.exists()) return;
if (file.type() === "dir") {
file.sub().forEach((sub) => {
addFilesRecursive(sub);
});
} else {
pushFile(file);
}
};

tree.select("deploy").kids.forEach((deploy: $mol_tree2) => {
addFilesRecursive(root_dir.resolve(deploy.value.replace(/^\//, "")));
});
});

return targets;
}
}
}
Loading