fs#copyFileSync JavaScript Examples

The following examples show how to use fs#copyFileSync. 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: Generator.js    From fes.js with MIT License 6 votes vote down vote up
copyDirectory(opts) {
      const files = glob.sync('**/*', {
          cwd: opts.path,
          dot: true,
          ignore: ['**/node_modules/**']
      });
      files.forEach((file) => {
          const absFile = join(opts.path, file);
          if (statSync(absFile).isDirectory()) return;
          if (file.endsWith('.tpl')) {
              this.copyTpl({
                  templatePath: absFile,
                  target: join(opts.target, file.replace(/\.tpl$/, '')),
                  context: opts.context
              });
          } else {
              console.log(`${chalk.green('Copy: ')} ${file}`);
              const absTarget = join(opts.target, file);
              mkdirp.sync(dirname(absTarget));
              copyFileSync(absFile, absTarget);
          }
      });
  }
Example #2
Source File: main.js    From k-domains with MIT License 5 votes vote down vote up
export default function(options) {
  const routerFile = path.join(this.options.srcDir, "router.js");
  if( !existsSync(routerFile) ){
    logger.info(new Error("router.js file not found"));
    logger.info(`creating new router configuration in ${this.options.srcDir}`)
    copyFileSync(path.join(__dirname, "router.js"), routerFile);
  }
 }
Example #3
Source File: registerMethods.js    From fes.js with MIT License 4 votes vote down vote up
export default function (api) {
    [
        'onExit',
        'onGenerateFiles',
        'addPluginExports',
        'addCoreExports',
        'addRuntimePluginKey',
        'addRuntimePlugin',
        'addEntryImportsAhead',
        'addEntryImports',
        'addEntryCodeAhead',
        'addEntryCode',
        'addBeforeMiddlewares',
        'addHTMLHeadScripts',
        'addMiddlewares',
        'modifyRoutes',
        'modifyBundleConfigOpts',
        'modifyBundleConfig',
        'modifyBabelOpts',
        'modifyBabelPresetOpts',
        'chainWebpack',
        'addTmpGenerateWatcherPaths',
        'modifyPublicPathStr'
    ].forEach((name) => {
        api.registerMethod({ name });
    });

    api.registerMethod({
        name: 'writeTmpFile',
        fn({
            path,
            content
        }) {
            assert(
                api.stage >= api.ServiceStage.pluginReady,
                'api.writeTmpFile() should not execute in register stage.'
            );
            const absPath = join(api.paths.absTmpPath, path);
            api.utils.mkdirp.sync(dirname(absPath));
            if (!existsSync(absPath) || readFileSync(absPath, 'utf-8') !== content) {
                writeFileSync(absPath, content, 'utf-8');
            }
        }
    });

    api.registerMethod({
        name: 'copyTmpFiles',
        fn({
            namespace, path, ignore
        }) {
            assert(
                api.stage >= api.ServiceStage.pluginReady,
                'api.copyTmpFiles() should not execute in register stage.'
            );
            assert(
                path,
                'api.copyTmpFiles() should has param path'
            );
            assert(
                namespace,
                'api.copyTmpFiles() should has param namespace'
            );
            const files = api.utils.glob.sync('**/*', {
                cwd: path
            });
            const base = join(api.paths.absTmpPath, namespace);
            files.forEach((file) => {
                const source = join(path, file);
                const target = join(base, file);
                if (!existsSync(dirname(target))) {
                    api.utils.mkdirp.sync(dirname(target));
                }
                if (statSync(source).isDirectory()) {
                    api.utils.mkdirp.sync(target);
                } else if (Array.isArray(ignore)) {
                    if (!ignore.some(pattern => new RegExp(pattern).test(file))) {
                        copyFileSync(source, target);
                    }
                } else {
                    copyFileSync(source, target);
                }
            });
        }
    });
}