예제 #1
0
파일: bundle.go 프로젝트: jasonweng/train
func hasRequireDirectives(filePath string) bool {
	b_content, _ := ioutil.ReadFile(filePath)
	content := string(b_content)
	fileExt := path.Ext(filePath)
	header := train.FindDirectivesHeader(&content, fileExt)
	return len(header) != 0
}
예제 #2
0
파일: cmd.go 프로젝트: clinthowarth/train
func bundleAssets() {
	fmt.Println("-> bundle assets with require directive")
	train.Config.BundleAssets = true
	publicAssetPath := "public" + train.Config.AssetsUrl
	filepath.Walk(publicAssetPath, func(filePath string, info os.FileInfo, err error) error {
		if info.IsDir() {
			return nil
		}
		fileExt := path.Ext(filePath)
		if fileExt != ".js" && fileExt != ".css" {
			return nil
		}

		assetUrl := strings.Replace(filePath, publicAssetPath, train.Config.AssetsUrl, 1)
		b_content, err := ioutil.ReadFile(filePath)
		content := string(b_content)
		header := train.FindDirectivesHeader(&content, fileExt)
		if len(header) != 0 {
			content, err := train.ReadAsset(assetUrl)
			if err != nil {
				removeAssets()
				panic(err)
			}
			ioutil.WriteFile(filePath, []byte(content), os.ModeDevice)
		}
		return nil
	})
}