當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。