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


TypeScript fs-extra.readFileSync函数代码示例

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


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

示例1: getStackblitzTemplate

function getStackblitzTemplate(path) {
  return fs.readFileSync(`misc/stackblitz-builder-templates/${path}`).toString();
}
开发者ID:ExFlo,项目名称:ng-boostrap,代码行数:3,代码来源:generate-stackblitzes.ts

示例2: glob

 glob(join(packagePath, '**/*.metadata.json')).forEach(path => {
   let metadata = JSON.parse(readFileSync(path, 'utf-8'));
   inlineMetadataResources(metadata, componentResources);
   writeFileSync(path , JSON.stringify(metadata), 'utf-8');
 });
开发者ID:jcannata,项目名称:material2,代码行数:5,代码来源:package-build.ts

示例3: patch

function patch(options, buildConfig) {

    console.log("Patching template files with function code");

    let template;

    // iterate around the functions array
    for (let f of buildConfig[functionsKey]) {

        console.log("Patching File: %s", f[templateFileKey]);

        // determine the full path to the file that needs to be updated
        if (!isAbsolute(f[templateFileKey])) {
            f[templateFileKey] = pathJoin(buildConfig[dirsKey][workingKey][productionKey], f[templateFileKey]);
        }

        // determine the full path to the configuration file
        if (!isAbsolute(f[configKey])) {
            f[configKey] = pathJoin(buildConfig[dirsKey][appRootKey], f[configKey]);
        }

        // if the config file exists, read in the object
        if (existsSync(f[configKey])) {
            f[configKey] = JSON.parse(readFileSync(f[configKey], "utf8"));
        } else {
            console.log("##vso[task.issue type=error]Function configutation file cannot be found: %s", f[configKey]);
        }

        // work out the full path to the specified code_file if needed
        // and set the base64 encoded value of the file in the code array
        for (let name in f[codeFilesKey]) {
            if (f[codeFilesKey].hasOwnProperty(name)) {
                if (!isAbsolute(f[codeFilesKey][name])) {
                    f[codeFilesKey][name] = pathJoin(buildConfig[dirsKey][appRootKey], f[codeFilesKey][name]);
                }

                // set the base64 encoding of the file, if it exists
                if (existsSync(f[codeFilesKey][name])) {
                    f[codeFilesKey][name] = Buffer.from(readFileSync(f[codeFilesKey][name], "utf8")).toString("base64");
                } else {
                    console.log("##vso[task.issue type=error]Function file cannot be found: %s", f[codeFilesKey][name]);
                }
            }
        }

        // Read in the template file and patch the values as defined
        if (existsSync(f[templateFileKey])) {
            template = JSON.parse(readFileSync(f[templateFileKey], "utf8"));

            // patch the parts of the template
            template[variablesKey][codeKey] = f[codeFilesKey];
            template[resourcesKey][0][propertiesKey][configKey] = f[configKey];

            // save the file
            writeFileSync(f[templateFileKey], JSON.stringify(template, null, 4), "utf8");
        } else {
            console.log("##vso[task.issue type=error]Template file cannot be found: %s", f[templateFileKey]);
        }
    }

    // Patch the mainTemplate so that it has the correct BaseURl if it has been specified in options
    let mainTemplateFile = pathJoin(buildConfig[dirsKey][workingKey][productionKey], "mainTemplate.json");
    if (existsSync(mainTemplateFile)) {
        if (options.baseurl !== "") {
            console.log("Patching main template: %s", mainTemplateFile);

            let mainTemplate = JSON.parse(readFileSync(mainTemplateFile, "utf8"));

            // patch the default value for the parameter
            mainTemplate[parametersKey][baseUrlKey][defaultValueKey] = options.baseurl;
            writeFileSync(mainTemplateFile, JSON.stringify(mainTemplate, null, 4), "utf8");
        }
    } else {
        console.log("##vso[task.issue type=error]Unable to find main template: %s", mainTemplateFile);
    }

    // Patch the createUIDefinition.json file with the API key for the verifyurl
    let uiDefinitionFile = pathJoin(buildConfig[dirsKey][workingKey][productionKey], "createUiDefinition.json");
    if (existsSync(uiDefinitionFile) && process.env.VERIFY_URL_API_KEY) {
        console.log("Patching createUIDefinition.json with API key");
        let uiDefinition = JSON.parse(readFileSync(uiDefinitionFile, "utf8"));

        // patch the parameter value
        uiDefinition[parametersKey][outputsKey][verifyURLApiKeyKey] = process.env.VERIFY_URL_API_KEY;
        writeFileSync(uiDefinitionFile, JSON.stringify(uiDefinition, null, 4), "utf8");
    }
}
开发者ID:chef-partners,项目名称:arm-chef-nodes,代码行数:87,代码来源:build.ts

示例4:

 .then((result) => {
   console.log('Uploading archive to Skygear Cloud...');
   const uploadRequest = result.upload_request;
   artifactRequest = result.artifact_request;
   return asset.upload(uploadRequest, fs.readFileSync(tarPath));
 })
开发者ID:SkygearIO,项目名称:skycli,代码行数:6,代码来源:deploy.ts

示例5: ng

    return ng(['new', 'FooApp', '--skip-install', '--skip-git']).then(() => {
      expect(!fs.pathExistsSync('FooApp'));

      const editorConfig = fs.readFileSync('.editorconfig', 'utf8');
      expect(editorConfig).toBeDefined();
    })
开发者ID:germanomarques,项目名称:angular-cli,代码行数:6,代码来源:new.spec.ts

示例6: ng

    return ng(['new', 'FooApp', '--skip-npm', '--skip-bower', '--skip-git']).then(function () {
      expect(!existsSync('FooApp'));

      const pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
      expect(pkgJson.name).to.equal('foo-app');
    });
开发者ID:devCrossNet,项目名称:angular-cli,代码行数:6,代码来源:new.spec.ts

示例7:

 layoutContext.bottom = layoutContext.bottom.map(file => fs.readFileSync(path.resolve(this.styleguide.config.cwd, file))).join('\n');
开发者ID:janpersiel,项目名称:stylegen,代码行数:1,代码来源:StructureWriter.ts

示例8: exportKhaProject


//.........这里部分代码省略.........
	for (let source of project.sources) {
		exporter.addSourceDirectory(source);
	}
	for (let library of project.libraries) {
		exporter.addLibrary(library);
	}
	exporter.parameters = exporter.parameters.concat(project.parameters);
	project.scriptdir = options.kha;
	if (baseTarget !== Platform.Java && baseTarget !== Platform.WPF) {
		project.addShaders('Sources/Shaders/**', {});
	}

	for (let callback of Callbacks.preAssetConversion) {
		callback();
	}

	let assetConverter = new AssetConverter(exporter, options, project.assetMatchers);
	lastAssetConverter = assetConverter;
	let assets = await assetConverter.run(options.watch, temp);

	let shaderDir = path.join(options.to, exporter.sysdir() + '-resources');
	if (target === Platform.Unity) {
		shaderDir = path.join(options.to, exporter.sysdir(), 'Assets', 'Shaders');
	}

	for (let callback of Callbacks.preShaderCompilation) {
		callback();
	}
	fs.ensureDirSync(shaderDir);

	let oldResources: any = null;
	let recompileAllShaders = false;
	try {
		oldResources = JSON.parse(fs.readFileSync(path.join(options.to, exporter.sysdir() + '-resources', 'files.json'), 'utf8'));
		for (let file of oldResources.files) {
			if (file.type === 'shader') {
				if (!file.files || file.files.length === 0) {
					recompileAllShaders = true;
					break;
				}
			}
		}
	}
	catch (error) {

	}

	let exportedShaders: CompiledShader[] = [];
	if (!options.noshaders) {
		if (fs.existsSync(path.join(options.from, 'Backends'))) {
			let libdirs = fs.readdirSync(path.join(options.from, 'Backends'));
			for (let ld in libdirs) {
				let libdir = path.join(options.from, 'Backends', libdirs[ld]);
				if (fs.statSync(libdir).isDirectory()) {
					let exe = path.join(libdir, 'krafix', 'krafix-' + options.target + '.exe');
					if (fs.existsSync(exe)) {
						options.krafix = exe;
					}
				}
			}
		}

		let shaderCompiler = new ShaderCompiler(exporter, options.target, options.krafix, shaderDir, temp,
		buildDir, options, project.shaderMatchers);
		lastShaderCompiler = shaderCompiler;
		try {
开发者ID:luboslenco,项目名称:khamake,代码行数:67,代码来源:main.ts

示例9: deploy

async function deploy(config, subscription) {

    // read the local control file to determine the name of the resource group
    // to delete and then create
    let deploySettings = JSON.parse(readFileSync(config[controlFileKey], "utf8"));
    if (!(config[resourceGroupKey][resourceGroupNameKey] in deploySettings)) {
        deploySettings[config[resourceGroupKey][name]] = {iterationKey: 0};
    }

    // determine the name of the resource group to delete
    let rgNameExisting = sprintf("%s-%s", config[resourceGroupKey][resourceGroupNameKey], deploySettings[config[resourceGroupKey][resourceGroupNameKey]][iterationKey]);

    // create the necessary resource manager client
    let rmClient = get_client(config[optionsKey][authFileKey], subscription, "resource");

    // determine if the rg exists
    if (rmClient !== false) {
        console.log("Resource Group: %s", rgNameExisting);

        let exists = await new Promise<boolean>((resolve, reject) => {
            rmClient.resourceGroups.checkExistence(rgNameExisting, (error, exists) => {
                if (error) {
                    return reject(sprintf("Failed to check the resource group status. Error: %s", Utils.getError(error)));
                }
                resolve(exists);
            });
        });

        if (exists) {
            console.log("\texists, deleting");

            let deleteStatus = new Promise<void> ((resolve, reject) => {
                rmClient.resourceGroups.deleteMethod(rgNameExisting, (error) => {
                    if (error) {
                        return reject(sprintf("Failed to delete the resource group. Error: %s", Utils.getError(error)));
                    }
                    resolve();
                });
            });

        } else {
            console.log("\tdoes not exist");
        }

        // determine the next iteration and therefore the name of the new RG
        deploySettings[config[resourceGroupKey][resourceGroupNameKey]][iterationKey] += 1;
        let rgName = sprintf("%s-%s", config[resourceGroupKey][resourceGroupNameKey], deploySettings[config[resourceGroupKey][resourceGroupNameKey]][iterationKey]);

        // write out the new iteration to the deployment file
        writeFileSync(config[controlFileKey], JSON.stringify(deploySettings), "utf8");

        // create the rg
        console.log("Creating Resource Group: %s", rgName);
        console.log("\tLocation: %s", config[resourceGroupKey][locationKey]);

        await new Promise<void> ((resolve, reject) => {
            // define the parameters for the new RG
            let parameters = {
                location: config[optionsKey][locationKey],
                name: rgName,
            };

            rmClient.resourceGroups.createOrUpdate(rgName, parameters, (error) => {
                if (error) {
                    return reject(sprintf("Failed to create the resource group. Error: %s", Utils.getError(error)));
                }
                resolve();
            });
        });

        // perform the deployment of the template and parameters
        // read in the parameters file
        let templateParameters;
        console.log("Reading parameters file: %s", config[resourceGroupKey][parametersFileKey]);
        if (existsSync(config[resourceGroupKey][parametersFileKey])) {
            templateParameters = JSON.parse(readFileSync(config[resourceGroupKey][parametersFileKey], "utf8"));
        } else {
            console.error("\tcannot find file");
            process.exit(3);
        }

        // determine the template-uri
        let templateUri = sprintf("https://%s.blob.core.windows.net/%s/%s", config[storageAccountKey][storageAccountNameKey], config[storageAccountKey][containerNameKey], config[optionsKey][templateFileKey]);

        console.log("Deploying template: %s", templateUri);

        // create the deployment parameters
        let deploymentParemeters = {
            properties: {
                mode: "Incremental",
                parameters: templateParameters[parametersKey],
                templateLink: {
                    uri: templateUri,
                },
            },
        };

        // create a deployment name
        let dateNow = new Date().toISOString().replace(/-|T.*/g, "");
        let deploymentName = sprintf("%s-%s", rgName.toLocaleLowerCase(), dateNow);
//.........这里部分代码省略.........
开发者ID:chef-partners,项目名称:arm-chef-nodes,代码行数:101,代码来源:deploy.ts

示例10: graphql

import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools'
import { graphql, ExecutionResult } from 'graphql'
import * as fs from 'fs-extra'

const typeDefs = fs.readFileSync(__dirname + '/cluster.graphql', 'utf-8')

const schema = makeExecutableSchema({ typeDefs })

addMockFunctionsToSchema({
  schema,
  mocks: {
    Migration: () => ({
      revision: 5,
    }),
  },
})

export const MockGraphQLClient = () => {
  return {
    request(query, variables) {
      return graphql(schema, query, {}, {}, variables) as any
    },
  }
}

export { ExecutionResult }
开发者ID:ahmb84,项目名称:prisma,代码行数:26,代码来源:mock-client.ts


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