/**
* @file @todo should be doing this `async` not `sync` for blocking fs @@perf
*/
// @todo
// crawl('si/src/pages')
// crawl('ui-component-library/dist/components')
// crawl('reference-store/dist/views')
import { walk, write } from 'flipfile'
import { resolveToRoot, exists } from './deps'
// @todo from chain-able
function includesAny(...list: string[]) {
return function includesForAny(target: string) {
return list.some(item => item.includes(target) || target.includes(item))
}
}
export function isAbsolutePathWeWant(absolutePath: string): boolean {
const hasExtensions = includesAny('.js', '.jsx', '.ts', '.tsx', '.json')
return hasExtensions(absolutePath)
}
export function createManifest() {
console.debug('createManifest')
const manifestFile = resolveToRoot('.tmp/manifest.composer.json')
const pathConfig = {
reference: resolveToRoot('node_modules/@skava/ui/dist/components'),
ui: resolveToRoot('node_modules/@skava/ui/dist/components'),
local: resolveToRoot('src/ui'),
}
const results = []
Object.keys(pathConfig).forEach(key => {
if (!exists(pathConfig[key])) {
console.warn('[composer] missing: ', pathConfig[key])
} else {
walk(pathConfig[key])
.filter(isAbsolutePathWeWant)
.forEach(x => results.push(x))
}
})
console.log(results)
}