當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs-extra.readJsonSync函數代碼示例

本文整理匯總了TypeScript中fs-extra.readJsonSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readJsonSync函數的具體用法?TypeScript readJsonSync怎麽用?TypeScript readJsonSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了readJsonSync函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getCustomConfig

/**
 * 獲取自定義配置
 */
function getCustomConfig (cwd: string = systemConfig.cwd): { [key: string]: CustomConfig } {
  const pkgPath = getProjectPackagePath(cwd)
  const filePath = getCustomConfigFilePath(cwd)

  let customConfigFromPkg: CustomConfig = {} // for package.json
  let customConfigFromFile: CustomConfig = {} // for min.config.json

  // in package.json
  if (fs.existsSync(pkgPath)) {
    customConfigFromPkg = _.pick(fs.readJsonSync(pkgPath)['minConfig'] || {}, CUSTOM_CONFIG_MEMBER) as CustomConfig
  }

  // in min.config.json
  if (fs.existsSync(filePath)) {
    customConfigFromFile = _.pick(fs.readJsonSync(filePath), CUSTOM_CONFIG_MEMBER) as CustomConfig
  }

  // merge customConfigFromPkg and customConfigFromFile
  let customConfig = _.merge({}, customConfigFromPkg, customConfigFromFile)

  return {
    customConfig,
    customConfigFromPkg,
    customConfigFromFile
  }
}
開發者ID:bbxyard,項目名稱:bbxyard,代碼行數:29,代碼來源:config.ts

示例2: uninstall

    /**
     * uninstall the module package
     * @param module_name
     * @param callback
     */
    uninstall(module_name: string, callback: Function) {
        var modules_file = fs.readJsonSync(modules_configuration_path);
        if (modules_file[module_name] !== undefined) {

            for (var i = 0; i < modules_file[module_name].routes.length; i++) {
                try {
                    fs.unlinkSync(serverRoot + "\\routes\\" + modules_file[module_name].routes[i].path);
                } catch (e) { }
            }

            deleteFolderRecursive(global.clientAppRoot + "\\modules\\" + module_name);

            delete modules_file[module_name];
        }







        fs.writeFileSync(modules_configuration_path, JSON.stringify(modules_file));


        try {
            var manifest_file = fs.readJsonSync(global.clientAppRoot + "\\modules\\" + module_name + "\\" + consts.MANIFEST_NAME, { throws: false });
            //merge the manifest into the modules.json file
            if (manifest_file === null)
                callback("invalid json, try using ascii file");




            dal.connect(function (err: any, db: any) {
                if (manifest_file.navigation) {
                    for (var i = 0; i < manifest_file.navigation.length; i++) {
                        db.collection("Navigation").remove({ "_id": manifest_file.navigation[i]._id }, function (err: any, data: any) {


                        });
                    }
                }

            })
        
        
            //delete module folder
            this.deleteFolderRecursive(global.clientAppRoot+ "\\modules\\" + module_name + "\\");




            callback("ok");
        }
        catch (e) {
            callback("ok");
        }
    }
開發者ID:gitter-badger,項目名稱:nodulus,代碼行數:63,代碼來源:modules.ts

示例3: commit

    export function commit(message: string, options: any) {
        if (!!options.quiet) log.silence();
        let repo = cwdRepo();

        let allowEmpty = !!options.allowEmpty;
        if (repo.staged.length < 1 && !allowEmpty) {
            log.info('no changes to commit');
            return;
        }

        let authorName: string = conf.get('authorName');
        let authorEMail: string = conf.get('authorEMail');
        var noAuthor = !authorName || !authorEMail;
        if (noAuthor) {
            log.error('either author name or email is not specified!');
            return;
        }

        if (!repo.currentBranchName) {
            log.error('you can not commit in detached HEAD state. Create new branch.');
            return;
        }

        let optionConfig: string = options.reeditMessage || options.reuseMessage;
        let amend = !!options.amend;
        var oldCommitData: string[] = null;
        var basedOnSomeCommit = false;

        if (!!optionConfig) {
            let lcOption = optionConfig.toLowerCase();
            if (lcOption === "orig_head") {
                oldCommitData = fse.readJsonSync(path.join(repo.root, '.jerk', 'ORIG_HEAD'));
                basedOnSomeCommit = true;
            } else if (lcOption === "head") {
                oldCommitData = fse.readJsonSync(path.join(repo.root, '.jerk', 'HEAD'));
                basedOnSomeCommit = true;
            } else {
                let branch = repo.ref<Common.Ref>(optionConfig);
                if (!!branch) {
                    let cm = repo.commit(branch.head);
                    if (!!cm) {
                        oldCommitData = cm.data();
                        basedOnSomeCommit = true;
                    }
                } else {
                    let cm = repo.commit(optionConfig);
                    if (!!cm) {
                        oldCommitData = cm.data();
                        basedOnSomeCommit = true;
                    }
                }
            }
        }

        var commit = repo.head.commit;
        var newCommit = repo.createCommit(commit, message, authorName, authorEMail, amend, oldCommitData);
        log.success(Format.formatCommitMessage(newCommit, '%Cyellow%h%Creset: %s'));
    }
開發者ID:STALKER2010,項目名稱:jerk,代碼行數:58,代碼來源:cli.ts

示例4: forEach

forEach(tasks.getTasks(), (task) => {
    const targetNodeCommonDir = path.join(task.directory, "common");
    const taskNodeModules = path.join(task.directory, "node_modules");
    const targetPowershellCommonDir = path.join(task.directory, "ps_modules");

    const taskFilePath = path.join(task.directory, "task.json");
    const taskFile = fs.existsSync(taskFilePath) ? fs.readJsonSync(taskFilePath) : {};

    if (taskFile.execution.Node) {
        fs.ensureDirSync(targetNodeCommonDir);
        fs.ensureDirSync(taskNodeModules);
        forEach(nodeFiles, (commonFile) => {
            const targetFile = path.join(targetNodeCommonDir, commonFile);
            console.log(targetFile);
            fs.copySync(path.join(nodeCommonFilesRoot, commonFile), targetFile, { overwrite: true });
        });
    }

    if (taskFile.execution.PowerShell3) {
        fs.ensureDirSync(targetPowershellCommonDir);
        forEach(powershellFiles, (commonFile) => {
            const targetFile = path.join(targetPowershellCommonDir, commonFile);
            console.log(targetFile);
            fs.copySync(path.join(powershellCommonFilesRoot, commonFile), targetFile, { overwrite: true });
        });
    }
});
開發者ID:geeklearningio,項目名稱:gl-vsts-tasks-build-scripts,代碼行數:27,代碼來源:prebuild.ts

示例5: _processMock

 /**
  * Processes all the mocks that are present in the given directory.
  * @param {string} directory The directory containing the mocks.
  * @returns {Mock[]} mocks The mocks.
  */
 function _processMock(file: string): void {
     try {
         const mock: Mock = fs.readJsonSync(file);
         utils.updateMock(mock);
     } catch (ex) {
         console.info(file, 'contains invalid json');
     }
 }
開發者ID:mdasberg,項目名稱:ng-apimock,代碼行數:13,代碼來源:index.ts

示例6: getLastCommit

 .reduce( (versionCache, dirName) => {
   const version = fs.readJsonSync(getPackageRoot(dirName, 'package.json')).version;
   versionCache[dirName] = {
     commit: getLastCommit(dirName),
     version
   };
   return versionCache;
 }, {});
開發者ID:shlomiassaf,項目名稱:ng2-chess,代碼行數:8,代碼來源:release_mgmt.ts

示例7: getAppScriptsPackageJson

export function getAppScriptsPackageJson() {
  if (!cachedAppScriptsPackageJson) {
    try {
      cachedAppScriptsPackageJson = readJsonSync(join(__dirname, '..', '..', 'package.json'));
    } catch (e) {}
  }
  return cachedAppScriptsPackageJson;
}
開發者ID:Kode-Kitchen,項目名稱:ionic-app-scripts,代碼行數:8,代碼來源:helpers.ts

示例8: getJSON

 getJSON(): any {
   const configPath = path.resolve(process.env.PWD, 'ng2-cli.json');
   if (helper.existsSync(configPath)) {
     return fse.readJsonSync(configPath);
   } else {
     throw new Error('Config file not found.');
   }
 }
開發者ID:jkuri,項目名稱:ng2-cli,代碼行數:8,代碼來源:config.ts

示例9: Error

 files.forEach(file => {
   const def = fs.readJsonSync(file);
   def.file = file;
   const title = getTitle(def);
   if (defs[title]) {
     throw new Error('Duplicate entry ' + title);
   }
   defs[title] = def;
 });
開發者ID:eclipsesource,項目名稱:tabris-js,代碼行數:9,代碼來源:common.ts

示例10: processFile

async function processFile ({ filePath, tempPath, entryBaseName }) {
  const indexJsStr = `
  import {AppRegistry} from 'react-native';
  import App from '../${entryBaseName}';
  // import {name as appName} from '../app.json';

  AppRegistry.registerComponent('${moduleName}', () => App);`

  if (!fs.existsSync(filePath)) {
    return
  }
  const dirname = path.dirname(filePath)
  const destDirname = dirname.replace(tempPath, jdreactPath)
  const destFilePath = path.format({dir: destDirname, base: path.basename(filePath)})
  const indexFilePath = path.join(tempPath, 'index.js')
  const tempPkgPath = path.join(tempPath, 'package.json')

  // generate jsbundles/moduleName.js
  if (filePath === indexFilePath) {
    const indexDistDirPath = path.join(jdreactPath, 'jsbundles')
    const indexDistFilePath = path.join(indexDistDirPath, `${moduleName}.js`)
    fs.ensureDirSync(indexDistDirPath)
    fs.writeFileSync(indexDistFilePath, indexJsStr)
    Util.printLog(processTypeEnum.GENERATE, `${moduleName}.js`, indexDistFilePath)
    return
  }

  // genetate package.json
  if (filePath === tempPkgPath) {
    const destPkgPath = path.join(jdreactPath, 'package.json')
    const templatePkgPath = path.join(jdreactTmpDirname, 'pkg')
    const tempPkgObject = fs.readJsonSync(tempPkgPath)
    const templatePkgObject = fs.readJsonSync(templatePkgPath)
    templatePkgObject.name = `jdreact-jsbundle-${moduleName}`
    templatePkgObject.dependencies = Object.assign({}, tempPkgObject.dependencies, templatePkgObject.dependencies)
    fs.writeJsonSync(destPkgPath, templatePkgObject, {spaces: 2})
    Util.printLog(processTypeEnum.GENERATE, 'package.json', destPkgPath)
    return
  }

  fs.ensureDirSync(destDirname)
  fs.copySync(filePath, destFilePath)
  Util.printLog(processTypeEnum.COPY, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:44,代碼來源:convert_to_jdreact.ts


注:本文中的fs-extra.readJsonSync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。