fs-extra#truncateSync TypeScript Examples

The following examples show how to use fs-extra#truncateSync. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: file.ts    From cli with Apache License 2.0 6 votes vote down vote up
export function saveToEnvFile(
  pathToEnv: string,
  additionalEnvironment: Record<string, unknown>
) {
  ensureFileSync(pathToEnv);
  const environment = parse(readFileSync(pathToEnv, {encoding: 'utf-8'}));

  const updatedEnvironment = {
    ...environment,
    ...additionalEnvironment,
  };

  truncateSync(pathToEnv);
  for (const [key, value] of Object.entries(updatedEnvironment)) {
    appendFileSync(pathToEnv, `${key}=${value}${EOL}`);
  }
}
Example #2
Source File: file.ts    From cli with Apache License 2.0 5 votes vote down vote up
export function flushEnvFile(projectPath: string) {
  const envPath = join(projectPath, '.env');
  const env = readFileSync(envPath, 'utf-8');
  truncateSync(envPath);
  return env;
}