First commit
This commit is contained in:
160
framework/npmScripts/convertClass.js
Normal file
160
framework/npmScripts/convertClass.js
Normal file
@@ -0,0 +1,160 @@
|
||||
|
||||
|
||||
import filemanager from "../server/filemanager.js";
|
||||
|
||||
import simplePath from "../unify/simplePath.js";
|
||||
|
||||
import fs from "fs-extra";
|
||||
|
||||
import path from "path";
|
||||
|
||||
|
||||
class converter{
|
||||
|
||||
replacements = new Array();
|
||||
|
||||
createPlatformCachePath( applicationPath ) {
|
||||
|
||||
var cachePath = new simplePath();
|
||||
|
||||
cachePath.beginWithSlash = false;
|
||||
|
||||
cachePath.add( "../../" );
|
||||
|
||||
cachePath.add( "application" );
|
||||
|
||||
cachePath.add( applicationPath );
|
||||
|
||||
|
||||
return cachePath.resolve();
|
||||
|
||||
}
|
||||
|
||||
addReplacement( from, to ) {
|
||||
|
||||
var replacement = new Object();
|
||||
|
||||
replacement.from = from;
|
||||
|
||||
replacement.to = to;
|
||||
|
||||
this.replacements.push( replacement );
|
||||
|
||||
}
|
||||
|
||||
constructor() {
|
||||
|
||||
this.addReplacement( "list", "userList" );
|
||||
|
||||
this.addReplacement( "news", "user" );
|
||||
|
||||
|
||||
}
|
||||
|
||||
async loadFiles() {
|
||||
|
||||
var path = this.createPlatformCachePath( "demo/userList/cache" )
|
||||
|
||||
var files = new filemanager( path );
|
||||
|
||||
await files.findApplicationFiles( "./application/demo/userList");
|
||||
|
||||
this.saveFiles( files );
|
||||
|
||||
}
|
||||
|
||||
replaceFileName( filePath, from, to ) {
|
||||
|
||||
var parts = filePath.split("/");
|
||||
|
||||
var filename = parts.pop().replaceAll( from, to );
|
||||
|
||||
|
||||
return parts.join("/") + "/" + filename;
|
||||
|
||||
}
|
||||
|
||||
saveFiles( files ) {
|
||||
|
||||
var files = files.files;
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
|
||||
var file = files[i];
|
||||
|
||||
var filePath = file.filePath;
|
||||
|
||||
var fileType = file.type;
|
||||
|
||||
var convertPath = path.resolve( "./converted/" + filePath );
|
||||
|
||||
for (var j = 0; j < this.replacements.length; j++) {
|
||||
|
||||
var replacement = this.replacements[j];
|
||||
|
||||
convertPath = this.replaceFileName( convertPath, replacement.from, replacement.to );
|
||||
|
||||
}
|
||||
|
||||
if( fileType == "directory" ) {
|
||||
|
||||
fs.ensureDirSync( convertPath )
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
|
||||
var file = files[i];
|
||||
|
||||
var name = file.name;
|
||||
|
||||
var filePath = file.filePath;
|
||||
|
||||
var fileType = file.type;
|
||||
|
||||
var source = file.source;
|
||||
|
||||
var convertPath = path.resolve( "./converted/" + filePath );
|
||||
|
||||
for (var j = 0; j < this.replacements.length; j++) {
|
||||
|
||||
var replacement = this.replacements[j];
|
||||
|
||||
convertPath = this.replaceFileName( convertPath, replacement.from, replacement.to );
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( file.type == "file" ) {
|
||||
|
||||
var replacedSource = source;
|
||||
|
||||
for (var j = 0; j < this.replacements.length; j++) {
|
||||
|
||||
var replacement = this.replacements[j];
|
||||
|
||||
replacedSource = replacedSource.replaceAll( replacement.from, replacement.to );
|
||||
|
||||
}
|
||||
|
||||
console.log( "Save file: ", convertPath );
|
||||
|
||||
fs.writeFileSync( convertPath, replacedSource )
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var convert = new converter();
|
||||
|
||||
convert.loadFiles();
|
||||
//files.
|
||||
|
||||
//console.log( files );
|
||||
Reference in New Issue
Block a user