ember-cli / ember-cli-shims

DEPRECATED - ES6 import shims for Ember.js
MIT License
45 stars 60 forks source link

Generate an easy to read list of all shims included from the source #88

Closed pichfl closed 7 years ago

pichfl commented 7 years ago

While the code is obviously not made for this, it was a fun exercise to extract a markdown compatible listing of all the shims from this addon. I'm pretty sure this is a rather brutal way, but it works.

I haven't figured on the best way to do it, but this could easily be part of the publishing process of this addon to have a proper reference.

function handlerFactory(path = '') {
    return {
        get(target, name) {
            return name in target? target[name] : `${path}.${name.toString()}`;
        },
    }
}

function mapEntries(obj, cb) {
    return Object.entries(obj).map(cb);
}

const obj = {};

function listEmberCliShims() {
    global.Ember = new Proxy([
        'inject',
        'Instrumentation',
        'platform',
        'run',
        'String',
        'computed',
        'Test',
    ].reduce((acc, key) => {
        acc[key] = new Proxy({ _key: `Ember.${key}` }, handlerFactory(`Ember.${key}`));

        return acc;
    }, { _key: 'Ember' }), handlerFactory('Ember'));

    const defined = {};

    global.define = (name, [], cb) => {
        const val = cb();

        if (val.default && val.default._key) {
            val.default = val.default._key;
        }

        defined[name] = val;
    };

    global.self = {
        jQuery: 'self.jQuery',
    };

    require('ember-cli-shims/vendor/ember-cli-shims/app-shims');

    return defined;
}

function listEmberCliShimsAsMarkdown(shims) {
    return `# All shims provided by this addon

${mapEntries(shims, ([key, value]) =>
`## \`${key}\`

${mapEntries(value, ([k, v]) =>
`- \`${k}\` ${(v || '').toString()}`).join("\n")}

`
    ).join('')}`;
}

console.log(listEmberCliShimsAsMarkdown(listEmberCliShims()));

Results via node generate.js > results.md

All shims provided by this addon

ember

ember-application

ember-array

ember-array/mutable

ember-array/utils

ember-component

ember-components/checkbox

ember-components/text-area

ember-components/text-field

ember-controller

ember-controller/inject

ember-controller/proxy

ember-controllers/sortable

ember-debug

ember-debug/container-debug-adapter

ember-debug/data-adapter

ember-deprecations

ember-enumerable

ember-evented

ember-evented/on

ember-globals-resolver

ember-helper

ember-instrumentation

ember-locations/hash

ember-locations/history

ember-locations/none

ember-map

ember-metal/destroy

ember-metal/events

ember-metal/get

ember-metal/mixin

ember-metal/observer

ember-metal/on-load

ember-metal/set

ember-metal/utils

ember-object

ember-owner/get

ember-owner/set

ember-platform

ember-route

ember-router

ember-runloop

ember-service

ember-service/inject

ember-set/ordered

ember-string

ember-utils

ember-computed

ember-test

ember-test/adapter

ember-test/qunit-adapter

jquery

rsvp

rwjblue commented 7 years ago

Neat!

pichfl commented 7 years ago

@rwjblue 🎉 Thanks!

I updated to code so rogue symbol definitions no longer show in the output. If someone points me in the right direction, I'm happy to make a pull request so this can be included. Otherwise running it by hand does the job as well.