#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var cli_color_1 = require("@imnull/cli-color");
var index_1 = require("./index");
var COLOR_MAP = {
    'js': 'green',
    'ts': 'brightGreen',
    'wxml': 'blue',
    'wxs': 'brightBlue',
    'json': 'yellow',
    'wxss': 'magenta',
    'scss': 'brightMagenta',
};
var stringify = function (item, depth) {
    var checker = cli_color_1.colors.use(" [ ".concat(item.exists ? '✔︎' : '✕', " ]"), item.exists ? 'green' : 'red');
    var prefix = cli_color_1.colors.use('- '.repeat(depth), 'brightBlack');
    var ext = item.type.substring(1);
    var content = cli_color_1.colors.use(item.router, COLOR_MAP[ext] || 'none') + cli_color_1.colors.use(" [".concat(ext, "]"), COLOR_MAP[ext] || 'none', { bold: true });
    return checker + ' ' + prefix + content;
};
var trav = function (root) {
    (0, index_1.traverse)(root, function (item, depth) {
        console.log(stringify(item, depth));
    });
};
var main = function (rootDir, router) {
    var alias = (0, index_1.parseMinipAppAlias)(rootDir);
    var jsRoot = (0, index_1.queryJsDependsMap)(router, {
        alias: alias,
        extensions: ['.js', '.ts']
    });
    var wxmlRoot = (0, index_1.queryWxmlDependsMap)(router, {
        alias: alias,
        extensions: ['.wxs', '.wxml']
    });
    var cssRoot = (0, index_1.queryCssDependsMap)(router, {
        alias: alias,
        extensions: ['.scss', '.wxss']
    });
    var jsonRoot = (0, index_1.queryJsonDependsMap)(router, {
        alias: alias,
        extensions: ['.json']
    });
    console.log('');
    console.log(cli_color_1.colors.brightWhite("[javascript]", { bold: true }));
    trav(jsRoot);
    console.log('');
    console.log(cli_color_1.colors.brightWhite("[wxml/wxs]", { bold: true }));
    trav(wxmlRoot);
    console.log('');
    console.log(cli_color_1.colors.brightWhite("[scss/wxss]", { bold: true }));
    trav(cssRoot);
    console.log('');
    console.log(cli_color_1.colors.brightWhite("[json]", { bold: true }));
    trav(jsonRoot);
    console.log('');
};
var CLI_NAME = 'mpchk';
var logHelp = function () {
    console.log('\n', cli_color_1.colors.brightBlack("\u952E\u5165"), cli_color_1.colors.brightWhite("'".concat(CLI_NAME, " --help'")), cli_color_1.colors.brightBlack("\u53EF\u83B7\u53D6\u66F4\u591A\u5E2E\u52A9"), '\n');
};
var logDesc = function () {
    console.log('\n', cli_color_1.colors.brightYellow("\u5C0F\u7A0B\u5E8F\u4F9D\u8D56\u68C0\u67E5CLI\u5DE5\u5177", { bold: true }), cli_color_1.colors.brightBlack(" - by marvin <imnull@outlook.com> 2024-09-16"));
    console.log('\n', cli_color_1.colors.brightWhite("\u4F7F\u7528\u8BF4\u660E:"));
    console.log(cli_color_1.colors.white("   $ ".concat(CLI_NAME, " <project-root> <page-router>")), '\n');
};
var _a = process.argv, _b = _a[2], root = _b === void 0 ? '' : _b, _c = _a[3], router = _c === void 0 ? '' : _c;
if (!root) {
    console.log('\n', cli_color_1.colors.brightRed("\u7F3A\u5C11\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55(project-root)"));
    logHelp();
}
else if (root.startsWith('-')) {
    var cmd = root.replace(/^-+/, '');
    switch (cmd) {
        case 'h':
        case 'help': {
            logDesc();
            break;
        }
    }
}
else if (!router) {
    console.log('\n', cli_color_1.colors.brightRed("\u7F3A\u5C11\u5C0F\u7A0B\u5E8F\u9875\u9762\u8DEF\u7531(page-router)"));
    logHelp();
}
else {
    try {
        main(root, router);
    }
    catch (err) {
        console.log(cli_color_1.colors.brightRed("\u610F\u5916\u9519\u8BEF:\n".concat(err)));
    }
}
