Пример #1
0
 public ProjectGenerator(string baseDir, string projDir)
 {
     this.baseDir     = baseDir;
     this.projDir     = projDir;
     this.projectFile = null;
     this.projectFile = OneProjectFile.fromJson(OneJson.parse(OneFile.readText($"{projDir}/one.json")).asObject());
     this.srcDir      = $"{this.projDir}/{this.projectFile.sourceDir}";
     this.outDir      = $"{this.projDir}/{this.projectFile.outputDir}";
 }
Пример #2
0
 public void generate(string dstDir, ObjectValue model)
 {
     foreach (var fn in this.srcFiles)
     {
         var srcFn = $"{this.templateDir}/src/{fn}";
         var dstFn = $"{dstDir}/{fn}";
         if (this.meta.templateFiles.includes(fn))
         {
             var tmpl    = new TemplateParser(OneFile.readText(srcFn)).parse();
             var dstFile = tmpl.format(new VMContext(model));
             OneFile.writeText(dstFn, dstFile);
         }
         else
         {
             OneFile.copy(srcFn, dstFn);
         }
     }
 }
Пример #3
0
        public static async Task <Compiler> initProject(string projectName, string sourceDir, string lang = "ts", string packagesDir = null)
        {
            if (lang != "ts")
            {
                throw new Error("Only typescript is supported.");
            }

            var compiler = new Compiler();
            await compiler.init(packagesDir ?? $"{CompilerHelper.baseDir}packages/");

            compiler.setupNativeResolver(OneFile.readText($"{CompilerHelper.baseDir}langs/NativeResolvers/typescript.ts"));
            compiler.newWorkspace(projectName);

            foreach (var file in OneFile.listFiles(sourceDir, true).filter(x => x.endsWith(".ts")))
            {
                compiler.addProjectFile(file, OneFile.readText($"{sourceDir}/{file}"));
            }

            return(compiler);
        }
Пример #4
0
        public async Task <PackageBundle> getAllCached()
        {
            var packages = new Dictionary <string, PackageContent> {
            };
            var allFiles = OneFile.listFiles(this.packagesDir, true);

            foreach (var fn in allFiles)
            {
                var pathParts = fn.split(new RegExp("/")).ToList();
                // [0]=implementations/interfaces, [1]=package-name, [2:]=path
                if (pathParts.length() < 3)
                {
                    continue;
                }
                var type   = pathParts.shift();
                var pkgDir = pathParts.shift();
                if (type != "implementations" && type != "interfaces")
                {
                    continue;
                }
                // skip e.g. bundle.json
                var pkgIdStr = $"{type}/{pkgDir}";
                var pkg      = packages.get(pkgIdStr);
                if (pkg == null)
                {
                    var pkgDirParts = pkgDir.split(new RegExp("-")).ToList();
                    var version     = pkgDirParts.pop().replace(new RegExp("^v"), "");
                    var pkgType     = type == "implementations" ? PackageType.Implementation : PackageType.Interface;
                    var pkgId       = new PackageId(pkgType, pkgDirParts.join("-"), version);
                    pkg = new PackageContent(pkgId, new Dictionary <string, string> {
                    }, true);
                    packages.set(pkgIdStr, pkg);
                }
                pkg.files.set(pathParts.join("/"), OneFile.readText($"{this.packagesDir}/{fn}"));
            }
            return(new PackageBundle(Object.values(packages)));
        }
Пример #5
0
 public ProjectTemplate(string templateDir)
 {
     this.templateDir = templateDir;
     this.meta        = ProjectTemplateMeta.fromYaml(OneYaml.load(OneFile.readText($"{templateDir}/index.yaml")));
     this.srcFiles    = OneFile.listFiles($"{templateDir}/src", true);
 }