Browse Source

docker.gradle, etc.

CrazyDoctor 1 year ago
parent
commit
dca7fa0f0d
12 changed files with 124 additions and 33 deletions
  1. 1 1
      .eslintrc
  2. 1 0
      .git-credentials.tmpl
  3. 7 0
      .gitconfig.tmpl
  4. 1 2
      .gitignore
  5. 57 18
      build.gradle
  6. 29 0
      config.json
  7. 18 2
      docker.gradle
  8. 1 1
      node_scripts/copyStatics.mjs
  9. 4 4
      node_scripts/uglifyStatics.mjs
  10. 2 2
      package-lock.json
  11. 2 2
      package.json
  12. 1 1
      tsconfig.json

+ 1 - 1
.eslintrc

@@ -1,7 +1,7 @@
 {
 {
   "root": true,
   "root": true,
   "parser": "@typescript-eslint/parser",
   "parser": "@typescript-eslint/parser",
-  "ignorePatterns": ["dist", "static", "node_scripts"],
+  "ignorePatterns": ["build", "static", "node_scripts"],
   "parserOptions": {
   "parserOptions": {
     "ecmaVersion": 2020
     "ecmaVersion": 2020
   },
   },

+ 1 - 0
.git-credentials.tmpl

@@ -0,0 +1 @@
+https://${gitUsername}:${gitPassword}@${commentsRepoUrl}

+ 7 - 0
.gitconfig.tmpl

@@ -0,0 +1,7 @@
+[credential]
+	helper = store
+[credential "https://${commentsRepoUrl}"]
+	provider = generic
+[user]
+	email = ${gitEmail}
+	name = ${gitUsername}

+ 1 - 2
.gitignore

@@ -1,8 +1,7 @@
 node_modules
 node_modules
-dist
+build
 .env
 .env
 .vscode
 .vscode
 .idea
 .idea
-config.json
 .gradle
 .gradle
 target
 target

+ 57 - 18
build.gradle

@@ -19,7 +19,6 @@ repositories {
 group = 'pro.doczilla'
 group = 'pro.doczilla'
 version = '1.0'
 version = '1.0'
 
 
-def distDir = "${projectDir}/dist"
 buildDir = "${projectDir}/target"
 buildDir = "${projectDir}/target"
 def srcDir = "src"
 def srcDir = "src"
 ext.srcMainDir = "${srcDir}"
 ext.srcMainDir = "${srcDir}"
@@ -30,35 +29,72 @@ def windows = org.apache.tools.ant.taskdefs.condition.Os.isFamily(org.apache.too
 ext.npmCmd = windows ? 'npm.cmd' : 'npm'
 ext.npmCmd = windows ? 'npm.cmd' : 'npm'
 ext.nodeCmd = windows ? 'node.exe' : 'node'
 ext.nodeCmd = windows ? 'node.exe' : 'node'
 
 
+def gitDefaults = [
+	adminPassword: '',
+	commentsRepoUrl: '',
+	gitUsername: '',
+	gitEmail: '',
+	gitPassword: ''
+].each {
+	if (!project.hasProperty(it.key))
+		ext[it.key] = it.value
+}
+
 apply plugin: 'eclipse'
 apply plugin: 'eclipse'
 apply plugin: 'maven-publish'
 apply plugin: 'maven-publish'
 apply plugin: 'distribution'
 apply plugin: 'distribution'
 apply plugin: 'com.dorongold.task-tree'
 apply plugin: 'com.dorongold.task-tree'
 
 
 task copySources {
 task copySources {
-	copy {
-		from file("${projectDir}/package.json")
-		into file(buildDir)
-	}
-	copy {
-		from file("${distDir}")
-		into file("${buildDir}/build/")
-	}
-}
+		copy {
+			from file("${projectDir}/package.json")
+			into file(buildDir)
+		}
 
 
-task npmInstall(type: Exec) {
-	workingDir projectDir
-	commandLine npmCmd, 'install'
+		copy {
+			from file("${projectDir}/tsconfig.json")
+			into file(buildDir)
+		}
+
+		copy {
+			from file("${projectDir}/config.json")
+			into file(buildDir)
+			expand(adminPassword: adminPassword)
+		}
+
+		copy {
+			from file(projectDir)
+			include "*.tmpl"
+			into file(buildDir)
+			rename { fileName -> fileName.replace('.tmpl', '') }
+			expand(commentsRepoUrl: commentsRepoUrl, gitUsername: gitUsername, gitEmail: gitEmail, gitPassword: gitPassword)
+		}
+
+		copy {
+			from file("${projectDir}/src")
+			into file("${buildDir}/src")
+		}
+
+		copy {
+			from file("${projectDir}/node_scripts")
+			into file("${buildDir}/node_scripts")
+		}
+
+		copy {
+			from file("${projectDir}/static")
+			into file("${buildDir}/static")
+		}
 }
 }
 
 
-task npmInstallProduction(type: Exec) {
+task npmInstall(type: Exec) {
 	dependsOn copySources
 	dependsOn copySources
 	workingDir buildDir
 	workingDir buildDir
-	commandLine npmCmd, 'install', '--production=true'
+	commandLine npmCmd, 'install'
 }
 }
 
 
-task buildJs(type: Exec) {
-	workingDir projectDir
+task buildTs(type: Exec) {
+	dependsOn npmInstall
+	workingDir buildDir
 	executable npmCmd
 	executable npmCmd
 	args = ['run', 'buildProd']
 	args = ['run', 'buildProd']
 }
 }
@@ -77,7 +113,10 @@ distZip {
 	archiveClassifier = today()
 	archiveClassifier = today()
 }
 }
 
 
-project.tasks.distZip.dependsOn project.tasks.npmInstallProduction
+project.tasks.assemble.dependsOn project.tasks.buildTs
+project.tasks.distZip.dependsOn project.tasks.buildTs
+project.tasks.distTar.dependsOn project.tasks.buildTs
+project.tasks.installDist.dependsOn project.tasks.buildTs
 
 
 distributions {
 distributions {
 	main {
 	main {

+ 29 - 0
config.json

@@ -0,0 +1,29 @@
+{
+	"server": {
+		"adminPassword": "${adminPassword}",
+		"commentsRepoUrl": "https://git.doczilla.pro/CrazyDoctor/js-docs-test"
+	},
+	"sources": {
+		"assetsDir": ".doczilla_js_docs",
+		"repos": [
+			{
+				"name": "org.zenframework.z8",
+				"url": "https://git.doczilla.pro/z8/org.zenframework.z8",
+				"sparseCheckout": "org.zenframework.z8.js",
+				"collectFrom": "org.zenframework.z8.js/src/js"
+			},
+			{
+				"name": "ru.morpher.js",
+				"url": "https://git.doczilla.pro/doczilla/ru.morpher.js",
+				"sparseCheckout": "src/js",
+				"collectFrom": "src/js"
+			},
+			{
+				"name": "pro.doczilla.base.js",
+				"url": "https://git.doczilla.pro/doczilla/pro.doczilla.base.js",
+				"sparseCheckout": "src/js",
+				"collectFrom": "src/js"
+			}
+		]
+	}
+}

+ 18 - 2
docker.gradle

@@ -42,6 +42,11 @@ if (!project.hasProperty('dnsContainerId'))
 	ext.dnsContainerId = 'dns'
 	ext.dnsContainerId = 'dns'
 
 
 def dockerBuildDir = "${buildDir}/docker"
 def dockerBuildDir = "${buildDir}/docker"
+def dockerVolumesDir = '/opt/docker/volumes'
+
+def contBinds = [
+	"${dockerVolumesDir}/${dockerContainerId}/.doczilla_js_docs": '/root/.doczilla_js_docs'
+]
 
 
 task clearDockerFiles(type: Delete) {
 task clearDockerFiles(type: Delete) {
 	delete fileTree("${dockerBuildDir}/files").matching {
 	delete fileTree("${dockerBuildDir}/files").matching {
@@ -49,9 +54,16 @@ task clearDockerFiles(type: Delete) {
 	}
 	}
 }
 }
 
 
+task copyGitCredentials(type: Copy) {
+	dependsOn installDist
+	from("${buildDir}")
+	include ".git*"
+	into "${buildDir}/install/${project.name}"
+}
+
 task prepareDockerFiles(type: Copy) {
 task prepareDockerFiles(type: Copy) {
 	dependsOn clearDockerFiles
 	dependsOn clearDockerFiles
-	dependsOn installDist
+	dependsOn copyGitCredentials
 
 
 	from("${buildDir}/install/${project.name}")
 	from("${buildDir}/install/${project.name}")
 	into "${dockerBuildDir}/files"
 	into "${dockerBuildDir}/files"
@@ -60,10 +72,13 @@ task prepareDockerFiles(type: Copy) {
 task createDockerfile(type: Dockerfile) {
 task createDockerfile(type: Dockerfile) {
 	destFile = project.file("${dockerBuildDir}/Dockerfile")
 	destFile = project.file("${dockerBuildDir}/Dockerfile")
 	from dockerBaseImage
 	from dockerBaseImage
+	runCommand "mkdir -p /root/.doczilla_js_docs"
+	copyFile './files/.gitconfig', '/root/'
+	copyFile './files/.git-credentials', '/root/'
 	copyFile "./files", '/opt/pro.doczilla.js-docs/'
 	copyFile "./files", '/opt/pro.doczilla.js-docs/'
 	workingDir '/opt/pro.doczilla.js-docs/'
 	workingDir '/opt/pro.doczilla.js-docs/'
 	
 	
-	defaultCommand 'index.js'
+	defaultCommand 'node', 'index.js'
 	exposePort 3000
 	exposePort 3000
 }
 }
 
 
@@ -113,6 +128,7 @@ task containerCreate(type: DockerCreateContainer) {
 	targetImageId dockerImageId
 	targetImageId dockerImageId
 	containerId = dockerContainerId
 	containerId = dockerContainerId
 	containerName = dockerContainerId
 	containerName = dockerContainerId
+	hostConfig.binds = contBinds
 	hostConfig.network = 'doczilla'
 	hostConfig.network = 'doczilla'
 	hostConfig.autoRemove = false
 	hostConfig.autoRemove = false
 	hostConfig.restartPolicy = 'always'
 	hostConfig.restartPolicy = 'always'

+ 1 - 1
node_scripts/copyStatics.mjs

@@ -7,7 +7,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
 
 
 class CopyStaticsTask {
 class CopyStaticsTask {
   static SourcePath = './static';
   static SourcePath = './static';
-  static DestinationPath = './dist/static'
+  static DestinationPath = './build/static'
   static AppPath = `${CopyStaticsTask.DestinationPath}/App.js`;
   static AppPath = `${CopyStaticsTask.DestinationPath}/App.js`;
 
 
   static start() {
   static start() {

+ 4 - 4
node_scripts/uglifyStatics.mjs

@@ -38,7 +38,7 @@ class Minifier {
 		}
 		}
 		
 		
 		const allJSFiles = this.MinifyList.reduce((accumulator, currentPath) => {
 		const allJSFiles = this.MinifyList.reduce((accumulator, currentPath) => {
-			currentPath = path.join('./dist/static/', currentPath);
+			currentPath = path.join('./build/static/', currentPath);
 			if (fs.statSync(currentPath).isDirectory()) {
 			if (fs.statSync(currentPath).isDirectory()) {
 				return accumulator.concat(getAllJSFiles(currentPath));
 				return accumulator.concat(getAllJSFiles(currentPath));
 			} else if (currentPath.endsWith('.js')) {
 			} else if (currentPath.endsWith('.js')) {
@@ -49,7 +49,7 @@ class Minifier {
 		
 		
 		const mergedContent = mergeFilesWithComments(allJSFiles);
 		const mergedContent = mergeFilesWithComments(allJSFiles);
 
 
-		fs.writeFileSync('./dist/static/merged_statics.js', mergedContent, { encoding: 'utf8' });
+		fs.writeFileSync('./build/static/merged_statics.js', mergedContent, { encoding: 'utf8' });
 	}
 	}
 
 
 	static uglify() {
 	static uglify() {
@@ -114,7 +114,7 @@ class Minifier {
 			},
 			},
 			toplevel: true
 			toplevel: true
 		}
 		}
-		const uglified = minify_sync(fs.readFileSync('./dist/static/merged_statics.js', 'utf8').toString(), { mangle: mangleProperties });
+		const uglified = minify_sync(fs.readFileSync('./build/static/merged_statics.js', 'utf8').toString(), { mangle: mangleProperties });
 		const uglifiedCode = uglified.code.replace(/\/\*\!\s>>>\s(.+)\s\*\/([^\s])/g, '/*! >>> $1 */\n$2');
 		const uglifiedCode = uglified.code.replace(/\/\*\!\s>>>\s(.+)\s\*\/([^\s])/g, '/*! >>> $1 */\n$2');
 		const uglifiedCodeStrings = uglifiedCode.split('\n');
 		const uglifiedCodeStrings = uglifiedCode.split('\n');
 
 
@@ -137,7 +137,7 @@ class Minifier {
 
 
 
 
 	static clean() {
 	static clean() {
-		fs.rmSync('./dist/static/merged_statics.js');
+		fs.rmSync('./build/static/merged_statics.js');
 	}
 	}
 
 
 	static run() {
 	static run() {

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
 {
   "name": "doczilla_js_docs",
   "name": "doczilla_js_docs",
-  "version": "1.0.2",
+  "version": "1.0.3",
   "lockfileVersion": 3,
   "lockfileVersion": 3,
   "requires": true,
   "requires": true,
   "packages": {
   "packages": {
     "": {
     "": {
       "name": "doczilla_js_docs",
       "name": "doczilla_js_docs",
-      "version": "1.0.2",
+      "version": "1.0.3",
       "dependencies": {
       "dependencies": {
         "@types/ws": "^8.5.10",
         "@types/ws": "^8.5.10",
         "cookie-parser": "^1.4.6",
         "cookie-parser": "^1.4.6",

+ 2 - 2
package.json

@@ -24,9 +24,9 @@
   },
   },
   "scripts": {
   "scripts": {
     "lint": "eslint .",
     "lint": "eslint .",
-    "build": "tsc && ncp ./config.json ./dist/config.json && ncp ./src/views/ ./dist/views && node ./node_scripts/copyStatics.mjs",
+    "build": "tsc && ncp ./config.json ./build/config.json && ncp ./src/views/ ./build/views && node ./node_scripts/copyStatics.mjs",
     "buildProd": "npm run build && node ./node_scripts/uglifyStatics.mjs",
     "buildProd": "npm run build && node ./node_scripts/uglifyStatics.mjs",
-    "start": "node ./dist/index.js",
+    "start": "node ./build/index.js",
     "buildAndStart": "npm run build && npm run start",
     "buildAndStart": "npm run build && npm run start",
     "buildAndStartProd": "npm run buildProd && npm run start"
     "buildAndStartProd": "npm run buildProd && npm run start"
   }
   }

+ 1 - 1
tsconfig.json

@@ -2,7 +2,7 @@
   "compilerOptions": {
   "compilerOptions": {
     "target": "es2022",
     "target": "es2022",
     "module": "commonjs",
     "module": "commonjs",
-    "outDir": "dist",
+    "outDir": "build",
     "strict": true,
     "strict": true,
     "esModuleInterop": true
     "esModuleInterop": true
   },
   },