当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ini.parse函数代码示例

本文整理汇总了TypeScript中ini.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: promisify

 return new Promise<Config>(async (resolve, reject) => {
   try {
     const data = await promisify(fs.readFile)(CONFIG_PATH[scope], 'utf-8')
     resolve(ini.parse(data))
   } catch (err) {
     reject(err)
   }
 })
开发者ID:uetchy,项目名称:git-account,代码行数:8,代码来源:gitconfig.ts

示例2: setDefaults

    /**
     * Loads the default settings from file.
     */
    public static setDefaults(options: IOptions): void {

        Logger.log.debug("Settings.setDefaults: start.");

        // default the encryptor to the passthrough encryptor if not set.
        options.useEncryption = options.encryptor ? true : false;
        options.encryptor = options.encryptor || new PassthroughEncryptor();

        // check for local settings
        if (fs.existsSync(Settings.getConfigFilePath())) {

            let config: any = ini.parse(fs.readFileSync(Settings.getConfigFilePath(), "utf-8"));

            // load the url from config else use the default cloco one.
            options.url = options.url || config.settings.url;
            options.subscription = options.subscription || config.preferences.subscription;
            options.application = options.application || config.preferences.application;
            options.environment = options.environment || config.preferences.environment;

            if (!options.credentials) {
                options.credentials = new Credentials();
                options.credentials.key = config.credentials.cloco_client_key;
                options.credentials.secret = config.credentials.cloco_client_secret;
            }

            if (!options.tokens) {
                options.tokens = new Tokens();
            }
        }

        // if url not set then use the default cloco url.
        options.url = options.url || "https://api.cloco.io";

        // set the interval for checking the cache expiry.
        options.cacheCheckInterval = options.cacheCheckInterval || 60000;

        // ensure that a subscription is set.
        if (!options.subscription) {
            throw new SettingsError("Could not load setting: subscription.", "options.subscription");
        }

        // ensure that an application is set.
        if (!options.application) {
            throw new SettingsError("Could not load setting: application.", "options.application");
        }

        // ensure that an environment is set.
        if (!options.environment) {
            throw new SettingsError("Could not load setting: environment.", "options.environment");
        }

        if (!options.credentials || !options.credentials.key || !options.credentials.secret) {
            throw new SettingsError("No credentials available", "options.credentials");
        }

        Logger.log.debug("Settings.setDefaults: end.");
    }
开发者ID:cloudconfig,项目名称:cloco-node,代码行数:60,代码来源:settings.ts

示例3: main

async function main(): Promise<void> {
    tl.setResourcePath(path.join(__dirname, "task.json"));
    try {
        // Local feeds
        const internalFeeds = await auth.getInternalAuthInfoArray("feedList");
        // external service endpoints
        const externalEndpoints = await auth.getExternalAuthInfoArray("externalSources");
        // combination of both internal and external
        const newEndpointsToAdd = internalFeeds.concat(externalEndpoints);

        let pypircPath = utils.getPypircPath();

        // Case when there are multiple twine auth tasks in a build
        if (tl.exist(pypircPath)) {
            // merge two tasks
            tl.debug(tl.loc("Info_StartParsingExistingPypircFile", pypircPath));
            let fileContent = ini.parse(fs.readFileSync(pypircPath, "utf-8"));

            // Adding new endpoints to already existing .pypirc file.
            for (const entry of newEndpointsToAdd){
                if (entry.packageSource.feedName in fileContent){
                    // Hard fail if there is a name collision from service endpoint
                    throw new Error(tl.loc("Error_DuplicateEntryForExternalFeed",
                    entry.packageSource.feedName));
                }

                fileContent[entry.packageSource.feedName] = new Repository(
                    entry.packageSource.feedUri,
                    entry.username,
                    entry.password);
                fileContent["distutils"]["index-servers"] += " " + entry.packageSource.feedName;
            }

            let encodedStr = ini.encode(fileContent);
            fs.writeFileSync(pypircPath, encodedStr);
        }
        else {
            // create new
            fs.writeFileSync(pypircPath, formPypircFormatFromData(newEndpointsToAdd));
            tl.setVariable("PYPIRC_PATH", pypircPath, false);
            tl.debug(tl.loc("VariableSetForPypirc", pypircPath));
        }

        // Configuring the pypirc file
        console.log(tl.loc("Info_SuccessAddingAuth", internalFeeds.length, externalEndpoints.length));
    }
    catch (error) {
        tl.error(error);
        tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToAddAuthentication"));
        return;
    } finally{
        _logTwineAuthStartupVariables();
    }
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:54,代码来源:twineauthenticatemain.ts

示例4: GetRegistries

export function GetRegistries(npmrc: string): string[] {
    let registries: string[] = [];
    let config = ini.parse(fs.readFileSync(npmrc).toString());

    for (let key in config) {
        let colonIndex = key.indexOf(':');
        if (key.substring(colonIndex + 1).toLowerCase() === 'registry') {
            config[key] = NormalizeRegistry(config[key]);
            registries.push(config[key]);
        }
    }

    // save the .npmrc with normalized registries
    tl.writeFile(npmrc, ini.stringify(config));
    return registries;
}
开发者ID:grawcho,项目名称:vso-agent-tasks,代码行数:16,代码来源:npmrcparser.ts

示例5: open

export function fromINIFile
	( filename:string
	):any|Error
	{
		const raw = open(filename);
		if(!raw){return;}
		if(isError(raw)){
			return raw;
		}
		else{
			try{
				return ini.parse(raw);
			}catch(e){
				return e;
			}
		}
	}
开发者ID:Xananax,项目名称:wpack,代码行数:17,代码来源:Opts_fromFile.ts

示例6: proxyFromNpm

// only https proxy
async function proxyFromNpm() {
  let data = ""
  try {
    data = await readFile(path.join(homedir(), ".npmrc"), "utf-8")
  }
  catch (ignored) {
    return null
  }

  if (!data) {
    return null
  }

  try {
    const config = parseIni(data)
    return config["https-proxy"] || config.proxy
  }
  catch (e) {
    // used in nsis auto-updater, do not use .util.warn here
    console.warn(e)
    return null
  }
}
开发者ID:jwheare,项目名称:electron-builder,代码行数:24,代码来源:nodeHttpExecutor.ts

示例7: readOptions

function readOptions(
  logger: logging.LoggerApi,
  yarn = false,
  showPotentials = false,
): Record<string, string> {
  const cwd = process.cwd();
  const baseFilename = yarn ? 'yarnrc' : 'npmrc';
  const dotFilename = '.' + baseFilename;

  let globalPrefix: string;
  if (process.env.PREFIX) {
    globalPrefix = process.env.PREFIX;
  } else {
    globalPrefix = path.dirname(process.execPath);
    if (process.platform !== 'win32') {
      globalPrefix = path.dirname(globalPrefix);
    }
  }

  const defaultConfigLocations = [
    path.join(globalPrefix, 'etc', baseFilename),
    path.join(homedir(), dotFilename),
  ];

  const projectConfigLocations: string[] = [
    path.join(cwd, dotFilename),
  ];
  const root = path.parse(cwd).root;
  for (let curDir = path.dirname(cwd); curDir && curDir !== root; curDir = path.dirname(curDir)) {
    projectConfigLocations.unshift(path.join(curDir, dotFilename));
  }

  if (showPotentials) {
    logger.info(`Locating potential ${baseFilename} files:`);
  }

  let options: { [key: string]: string } = {};
  for (const location of [...defaultConfigLocations, ...projectConfigLocations]) {
    if (existsSync(location)) {
      if (showPotentials) {
        logger.info(`Trying '${location}'...found.`);
      }

      const data = readFileSync(location, 'utf8');
      options = {
        ...options,
        ...(yarn ? lockfile.parse(data) : ini.parse(data)),
      };

      if (options.cafile) {
        const cafile = path.resolve(path.dirname(location), options.cafile);
        delete options.cafile;
        try {
          options.ca = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
        } catch { }
      }
    } else if (showPotentials) {
      logger.info(`Trying '${location}'...not found.`);
    }
  }

  // Substitute any environment variable references
  for (const key in options) {
    if (typeof options[key] === 'string') {
      options[key] = options[key].replace(/\$\{([^\}]+)\}/, (_, name) => process.env[name] || '');
    }
  }

  return options;
}
开发者ID:angular,项目名称:angular-cli,代码行数:70,代码来源:npm.ts

示例8: get_client

function get_client(authfile, subscription, type) {

    // define the client to return
    let client;

    if (existsSync(authfile)) {

        // read in the configuration file
        let credentials = iniParse(readFileSync(authfile, "utf-8"));

        // ensure that the specified subscription can be found in the file
        if (subscription in credentials) {

            // get the required settings from the credentials file
            let clientId = credentials[subscription].client_id;
            let clientSecret = credentials[subscription].client_secret;
            let tenantId = credentials[subscription].tenant_id;

            // create token credentials with access to Azure
            let azureTokenCreds = new ApplicationTokenCredentials(clientId, tenantId, clientSecret);

            // create the necessary storage client
            if (type === "storage") {
                client = new StorageManagementClient(azureTokenCreds, subscription);
            } else if (type === "resource") {
                client = new ResourceManagementClient(azureTokenCreds, subscription);
            } else {
                client = false;
            }
        } else {
            console.log("Unable to find subscription \"%s\" in auth file: %s", subscription, authfile);
            client = false;
        }
    } else {
        console.log("Unable to find credentials file: %s", authfile);
        client = false;
    }

    return client;
}
开发者ID:ehanlon,项目名称:azure-managed-automate,代码行数:40,代码来源:deploy.ts


注:本文中的ini.parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。