"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_core_1 = require("@iotize/schematics-core");
const path_1 = require("path");
const VARIABLE_NAME = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
/**
 *
 * @param name
 * @param options
 * @param runOptions
 */
function execIonicToolkitSchematics(name, options, runOptions = {
    dryRun: false,
    debug: false,
    verbose: false
}) {
    const execOptions = {
        options: runOptions,
        schematic: {
            collection: process.env['IOTIZE_IONIC_TOOLKIT_COLLECTION'] || path_1.resolve(__dirname, '..', '..', 'collection.json'),
            name: name,
            options: options
        },
        stderr: runOptions.stderr,
        stdout: runOptions.stdout
    };
    return schematics_core_1.execSchematicsFromSource(execOptions);
}
exports.execIonicToolkitSchematics = execIonicToolkitSchematics;
function getPackagesVersion(packageName) {
    let packageJson = path_1.resolve(path_1.dirname(require.resolve(packageName)), 'package.json');
    let { version } = require(packageJson);
    return version;
}
exports.getPackagesVersion = getPackagesVersion;
function variablenamify(name) {
    name = name.replace(/[^0-9a-zA-Z_$]/gi, '_');
    if (!name.match(VARIABLE_NAME)) {
        name = name.replace(/^.{1}/, '_');
    }
    return name;
}
exports.variablenamify = variablenamify;
function userfriendlystring(name) {
    return name.replace(/[_]/g, ' ');
}
exports.userfriendlystring = userfriendlystring;
function arrayMove(arr, old_index, new_index) {
    if (new_index >= arr.length) {
        var k = new_index - arr.length + 1;
        while (k--) {
            // arr.push(undefined);
            throw new Error(`Invalid new index: ${new_index}`);
        }
    }
    arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
    return arr;
}
exports.arrayMove = arrayMove;
;
function jsonify(input, space = 4) {
    return JSON.stringify(input, null, space);
}
exports.jsonify = jsonify;
// export function jsonifyForHtml(input: any, space: number = 4) {
//     return JSON.stringify(input, null, space).replace(/"/g, '\\"');
// }
//# sourceMappingURL=util.js.map