Ejemplo n.º 1
0
async function processFile(filePath) {
  if (!fs.existsSync(filePath)) {
    return
  }
  const dirname = path.dirname(filePath)
  const distDirname = dirname.replace(sourceDir, tempDir)
  let distPath = path.format({dir: distDirname, base: path.basename(filePath)})
  const code = fs.readFileSync(filePath, 'utf-8')
  if (REG_STYLE.test(filePath)) {
    // do something
  } else if (REG_SCRIPTS.test(filePath)) {
    if (REG_TYPESCRIPT.test(filePath)) {
      distPath = distPath.replace(/\.(tsx|ts)(\?.*)?$/, '.js')
    }
    Util.printLog(processTypeEnum.COMPILE, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
    // transformJSCode
    const transformResult = transformJSCode({code, filePath, isEntryFile: isEntryFile(filePath), projectConfig})
    const jsCode = transformResult.code
    fs.ensureDirSync(distDirname)
    fs.writeFileSync(distPath, Buffer.from(jsCode))
    // compileDepStyles
    const styleFiles = transformResult.styleFiles
    depTree[filePath] = styleFiles
    await compileDepStyles(filePath, styleFiles)
  } else {
    fs.ensureDirSync(distDirname)
    fs.copySync(filePath, distPath)
    Util.printLog(processTypeEnum.COPY, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
  }
}
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 });
        });
    }
});
Ejemplo n.º 3
0
export function copyFileSync (from: string, to: string, options?: ICopyArgOptions) {
  const filename = path.basename(from)
  if (fs.statSync(from).isFile() && !path.extname(to)) {
    fs.ensureDirSync(to)
    if (from === path.join(to, filename)) {
      return
    }
    return fs.copySync(from, path.join(to, filename), options)
  }
  if (from === to) {
    return
  }
  fs.ensureDirSync(path.dirname(to))
  return fs.copySync(from, to, options)
}
Ejemplo n.º 4
0
 zipfile.on('entry', entry => {
   if (/\/$/.test(entry.fileName)) {
     const fileNameArr = entry.fileName.replace(/\\/g, '/').split('/')
     fileNameArr.shift()
     const fileName = fileNameArr.join('/')
     fs.ensureDirSync(path.join(path.dirname(zipPath), fileName))
     zipfile.readEntry()
   } else {
     zipfile.openReadStream(entry, (err, readStream) => {
       if (err) throw err
       const filter = new Transform()
       filter._transform = function (chunk, encoding, cb) {
         cb(undefined, chunk)
       }
       filter._flush = function (cb) {
         cb()
         zipfile.readEntry()
       }
       const fileNameArr = entry.fileName.replace(/\\/g, '/').split('/')
       fileNameArr.shift()
       const fileName = fileNameArr.join('/')
       const writeStream = fs.createWriteStream(path.join(path.dirname(zipPath), fileName))
       writeStream.on('close', () => {})
       readStream
         .pipe(filter)
         .pipe(writeStream)
     })
   }
 })
Ejemplo n.º 5
0
async function buildH5Lib () {
  try {
    const { appPath, outputDirName, tempPath } = buildData
    const outputDir = path.join(appPath, outputDirName, h5OutputName)
    const tempEntryFilePath = resolveScriptPath(path.join(tempPath, 'index'))
    const outputEntryFilePath = path.join(outputDir, path.basename(tempEntryFilePath))
    const code = fs.readFileSync(tempEntryFilePath).toString()
    const transformResult = wxTransformer({
      code,
      sourcePath: tempEntryFilePath,
      outputPath: outputEntryFilePath,
      isNormal: true,
      isTyped: REG_TYPESCRIPT.test(tempEntryFilePath)
    })
    const { styleFiles, components, code: generateCode } = parseEntryAst(transformResult.ast, tempEntryFilePath)
    const relativePath = path.relative(appPath, tempEntryFilePath)
    printLog(processTypeEnum.COPY, '发现文件', relativePath)
    fs.ensureDirSync(path.dirname(outputEntryFilePath))
    fs.writeFileSync(outputEntryFilePath, generateCode)
    if (components.length) {
      components.forEach(item => {
        copyFileToDist(item.path as string, tempPath, outputDir)
      })
      analyzeFiles(components.map(item => item.path as string), tempPath, outputDir)
    }
    if (styleFiles.length) {
      styleFiles.forEach(item => {
        copyFileToDist(item, tempPath, path.join(appPath, outputDirName))
      })
      analyzeStyleFilesImport(styleFiles, tempPath, path.join(appPath, outputDirName))
    }
  } catch (err) {
    console.log(err)
  }
}
Ejemplo n.º 6
0
export function getTaroPath (): string {
  const taroPath = path.join(homedir(), '.taro')
  if (!fs.existsSync(taroPath)) {
    fs.ensureDirSync(taroPath)
  }
  return taroPath
}
Ejemplo n.º 7
0
	exportSolution(project: Project, from: string, to: string, platform: string) {
		if (project.getDebugDir() !== '') fs.copySync(path.resolve(from, project.getDebugDir()), path.resolve(to, 'data'), { clobber: true });

		let dotcproject = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', '.cproject'), 'utf8');
		dotcproject = dotcproject.replace(/{ProjectName}/g, project.getName());
		let includes = '';
		for (let include of project.getIncludeDirs()) {
			includes += '<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/CopiedSources/' + include + '}&quot;"/>';
		}
		dotcproject = dotcproject.replace(/{includes}/g, includes);
		let defines = '';
		for (let define of project.getDefines()) {
			defines += '<listOptionValue builtIn="false" value="' + define + '"/>';
		}
		dotcproject = dotcproject.replace(/{defines}/g, defines);
		fs.writeFileSync(path.resolve(to, '.cproject'), dotcproject);

		let dotproject = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', '.project'), 'utf8');
		dotproject = dotproject.replace(/{ProjectName}/g, project.getName());
		fs.writeFileSync(path.resolve(to, '.project'), dotproject);

		let manifest = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', 'manifest.xml'), 'utf8');
		manifest = manifest.replace(/{ProjectName}/g, project.getName());
		fs.writeFileSync(path.resolve(to, 'manifest.xml'), manifest);

		for (let file of project.getFiles()) {
			let target = path.resolve(to, 'CopiedSources', file);
			fs.ensureDirSync(path.join(target.substr(0, target.lastIndexOf('/'))));
			fs.copySync(path.resolve(from, file), target, { clobber: true });
		}
	}
Ejemplo n.º 8
0
 await Promise.all(names.map(async from => {
   if (fs.existsSync(from) && fs.statSync(from).isFile()) {
     const to = from.replace(outputDir, appPath)
     fs.ensureDirSync(path.dirname(to))
     await fs.copyFile(from, to)
   }
 }))
Ejemplo n.º 9
0
export async function copyDir(src: string, dest: string, filter: CopyFilter = defaultFilter) {
  if (!path.isAbsolute(dest)) {
    dest = path.resolve(process.PROJECT_LOCATION, dest)
  }

  ensureDirSync(dest)

  let files = glob.sync('**/*', { cwd: src, nodir: true, dot: true })

  if (filter) {
    files = files.filter(filter)
  }

  return Promise.mapSeries(files, f =>
    Promise.fromCallback(async cb => {
      const fileDest = path.join(dest, f)
      const fileDir = path.dirname(fileDest)

      if (fileDir.length) {
        ensureDirSync(fileDir)
      }

      const buffer = await Promise.fromCallback(cb => {
        fs.readFile(path.join(src, f), cb)
      })

      fs.writeFile(fileDest, buffer, cb)
    })
  )
}
Ejemplo n.º 10
0
 it('creates working directory', () => {
     log.silence();
     fse.ensureDirSync('mocha-tests');
     process.chdir('mocha-tests');
     objdir = path.join('.jerk', 'objects');
     fs = FS.fs();
 });