hashicorp-copywrite[bot] 5fb9df1640
[COMPLIANCE] License changes (#18443)
* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 09:12:13 -04:00

91 lines
2.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { runInDebug } from '@ember/debug';
export const walk = function (routes) {
const keys = Object.keys(routes);
keys.forEach((item, i) => {
if (item === '_options') {
return;
}
if (routes[item] === null) {
return;
}
const options = routes[item]._options;
let cb;
if (Object.keys(routes[item]).length > 1) {
cb = function () {
walk.apply(this, [routes[item]]);
};
}
this.route(item, options, cb);
});
if (typeof routes.index === 'undefined') {
routes.index = {
_options: {
path: '',
},
};
}
};
/**
* Drop in for the Router.map callback e.g. `Router.map(walk(routes))`
* Uses { walk } to recursively walk through a JSON object of routes
* and use `Router.route` to define your routes for your ember application
*
* @param {object} routes - JSON representation of routes
*/
export default function (routes) {
return function () {
walk.apply(this, [routes]);
};
}
export let dump = (routes) => {};
runInDebug(() => {
const indent = function (num) {
return Array(num).fill(' ', 0, num).join('');
};
/**
* String dumper to produce Router.map code
* Uses { walk } to recursively walk through a JSON object of routes
* to produce the code necessary to define your routes for your ember application
*
* @param {object} routes - JSON representation of routes
* @example `console.log(dump(routes));`
*/
dump = function (routes) {
let level = 2;
const obj = {
out: '',
route: function (name, options, cb) {
this.out += `${indent(level)}this.route('${name}', ${JSON.stringify(options)}`;
if (cb) {
level++;
this.out += `, function() {
`;
cb.apply(this, []);
level--;
this.out += `${indent(level)}});
`;
} else {
this.out += ');';
}
this.out += `
`;
},
};
walk.apply(obj, [routes]);
return `Router.map(
function() {
${obj.out}
}
);`;
};
});