{"size": 1713, "ext": "js", "max_stars_repo_path": "extension.js", "max_stars_repo_name": "CVarisco/vs-component-app", "max_stars_repo_stars_event_min_datetime": "2017-07-10T21:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-19T17:45:18.000Z", "max_issues_repo_path": "extension.js", "max_issues_repo_name": "CVarisco/vs-component-app", "max_issues_repo_issues_event_min_datetime": "2017-07-16T08:28:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-20T15:28:44.000Z", "max_forks_repo_path": "extension.js", "max_forks_repo_name": "CVarisco/vs-component-app", "max_forks_repo_forks_event_min_datetime": "2017-08-19T07:25:32.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-19T07:25:32.000Z"}
{"max_stars_count": 36, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 24.4714285714, "max_line_length": 86, "alphanum_fraction": 0.6654991243}
const vscode = require("vscode");
const ccarc = require("create-component-app").default;
const defaultConfig = {
  type: "class",
  jsExtension: "js",
  cssExtension: "css",
  includeTests: false,
  includeStories: false,
  indexFile: false,
  connected: false,
  componentMethods: []
};

/**
 * Get the config options from settings preference and merge with the default options.
 * @param {string} path of destination.
 */
function getConfig(path) {
  return new Promise((resolve, reject) => {
    const { ccarc } = vscode.workspace.getConfiguration();

    vscode.window.showInputBox({ value: "ComponentName" }).then(name => {
      if (!name) {
        reject("Name is undefined");
      }
      const config = Object.assign({ path, name }, defaultConfig, ccarc);
      resolve(config);
    });
  });
}

/**
 * Get the config and create the components base on config
 * @param {object} event from vscode.commands.registerCommand
 */
function createComponent(e) {
  const path = e.toJSON().fsPath;
  getConfig(path).then(
    config => {
      if (config.type === "custom") {
        ccarc.generateFilesFromCustom(config);
      }

      ccarc.generateFiles(config);
    },
    error => {
      vscode.window.showErrorMessage(error);
    }
  );
}

// this method is called when your extension is activated
function activate(context) {
  try {
    const disposable = vscode.commands.registerCommand(
      "extension.create-component-app",
      createComponent
    );

    context.subscriptions.push(disposable);
  } catch (error) {
    console.log(error);
  }
}
exports.activate = activate;

// this method is called when your extension is deactivated
function deactivate() {}
exports.deactivate = deactivate;
