function exportPkg(pkg, isChild, pkgName, externImports) {
    var keys = Object.keys(pkg);
    var imports = externImports || [];

    var topLevels = [];
    var children = keys.map(function (name) {
        if (isString(pkg[name])) {
            var className = name.substring(0, name.indexOf('$'));
            if (topLevelClasses.find(function (item) {
                return pkg[name].indexOf(item) >= 0;
            })) {
                topLevels.push(name);
            }
            // a class, not a packagge
            imports.push(pkg[name]);
            if (pkgName) {
                // export as a child class in package
                // indentation + (key : value)
                return (isChild ? '        '  : '    ') + className + ' : ' + name;
            }
            else {
                // export as a class at root level
                return `export { ${name} as ${className} };`;
            }
        }
        else {
            // export as a child package
            return exportPkg(pkg[name], pkgName && true, name, imports);
        }
    });

    var importCode = (externImports ? '' : imports.join('\n') + '\n\n');
    var exportCode;
    if (pkgName) {
        if (isChild) {
            // export as a grand-child package
            exportCode = `    ${pkgName} : {\n${children.join(',\n')}\n    }`;
        }
        else {
            // export as a package at root level
            exportCode = `\nvar ${pkgName} = {\n${children.join(',\n')}\n};\nexport { ${pkgName} };\n`;
        }
    }
    else {
        // export child classes
        exportCode = children.join('\n');
    }

    topLevels.forEach(function (name) {
        var className = name.substring(0, name.indexOf('$'));
        exportCode += `export { ${name} as ${className} };\n`;
    });

    return importCode  + exportCode;
}
Export pkg to import/export codes
@param {Object} pkg package to export
@param {Boolean} isChild if it is a child package
@param {String} pkgName name of the package, if it's a child
@param {String[]} externImports imports