@contember/cli-common 0.12.0-alpha.9 → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/application/Application.d.ts +2 -0
- package/dist/src/application/Application.d.ts.map +1 -1
- package/dist/src/application/Application.js +13 -6
- package/dist/src/application/Application.js.map +1 -1
- package/dist/src/application/UsageFormatter.js +1 -1
- package/dist/src/application/UsageFormatter.js.map +1 -1
- package/dist/src/pathUtils.js +2 -2
- package/dist/src/pathUtils.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/utils/PathMapping.js +7 -6
- package/dist/src/utils/PathMapping.js.map +1 -1
- package/dist/src/utils/Project.d.ts +0 -1
- package/dist/src/utils/Project.d.ts.map +1 -1
- package/dist/src/utils/Project.js +0 -37
- package/dist/src/utils/Project.js.map +1 -1
- package/dist/src/utils/ProjectManager.js +8 -8
- package/dist/src/utils/ProjectManager.js.map +1 -1
- package/dist/src/utils/Workspace.d.ts +7 -7
- package/dist/src/utils/Workspace.d.ts.map +1 -1
- package/dist/src/utils/Workspace.js +21 -60
- package/dist/src/utils/Workspace.js.map +1 -1
- package/dist/src/utils/fs.js +4 -4
- package/dist/src/utils/fs.js.map +1 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +0 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/npm.d.ts +1 -1
- package/dist/src/utils/npm.d.ts.map +1 -1
- package/dist/src/utils/npm.js +8 -9
- package/dist/src/utils/npm.js.map +1 -1
- package/dist/src/utils/template.d.ts.map +1 -1
- package/dist/src/utils/template.js +33 -30
- package/dist/src/utils/template.js.map +1 -1
- package/dist/src/utils/version.js +1 -1
- package/dist/src/utils/version.js.map +1 -1
- package/dist/src/utils/yaml.d.ts +0 -6
- package/dist/src/utils/yaml.d.ts.map +1 -1
- package/dist/src/utils/yaml.js +3 -27
- package/dist/src/utils/yaml.js.map +1 -1
- package/package.json +5 -6
- package/resources/templates/template-project/admin/components/Layout.tsx +12 -0
- package/resources/templates/template-project/admin/components/SideMenu.tsx +10 -0
- package/resources/templates/template-project/admin/index.html +9 -0
- package/resources/templates/template-project/admin/index.tsx +18 -0
- package/resources/templates/template-project/admin/pages/Dashboard.tsx +8 -0
- package/resources/templates/template-project/admin/vite-env.d.ts +7 -0
- package/resources/templates/template-project/api/{acl/index.ts → acl.ts} +0 -0
- package/resources/templates/template-project/api/model/index.ts +3 -2
- package/resources/templates/template-project/contember.template.yaml +3 -4
- package/resources/templates/template-project/tsconfig.json +16 -9
- package/resources/templates/template-workspace/.gitignore.dist +3 -0
- package/resources/templates/{template-workspace-single-instance → template-workspace}/contember.template.yaml +5 -1
- package/resources/templates/template-workspace/contember.yaml +4 -0
- package/resources/templates/template-workspace/docker-compose.yaml +159 -0
- package/resources/templates/template-workspace/package.json +17 -0
- package/resources/templates/{template-workspace-single-instance/api → template-workspace/scripts/minio}/s3-entrypoint.sh +0 -0
- package/resources/templates/{template-workspace-single-instance/api → template-workspace/scripts/minio}/s3-policy.json +0 -0
- package/resources/templates/template-workspace/tsconfig.json +16 -0
- package/src/application/Application.ts +14 -7
- package/src/utils/PathMapping.ts +1 -1
- package/src/utils/Project.ts +0 -40
- package/src/utils/Workspace.ts +21 -42
- package/src/utils/fs.ts +2 -2
- package/src/utils/index.ts +0 -1
- package/src/utils/npm.ts +3 -4
- package/src/utils/template.ts +28 -24
- package/src/utils/yaml.ts +3 -35
- package/dist/src/utils/dockerCompose.d.ts +0 -15
- package/dist/src/utils/dockerCompose.d.ts.map +0 -1
- package/dist/src/utils/dockerCompose.js +0 -22
- package/dist/src/utils/dockerCompose.js.map +0 -1
- package/resources/templates/template-project/api/migrations/2019-12-13-110355-init.json +0 -146
- package/resources/templates/template-project/api/model/Image.ts +0 -5
- package/resources/templates/template-project/api/model/Post.ts +0 -8
- package/resources/templates/template-project/package.json +0 -13
- package/resources/templates/template-workspace-single-instance/.dockerignore +0 -1
- package/resources/templates/template-workspace-single-instance/api/config.yaml +0 -0
- package/resources/templates/template-workspace-single-instance/contember.workspace.yaml +0 -2
- package/resources/templates/template-workspace-single-instance/docker-compose.override.dist.yaml +0 -26
- package/resources/templates/template-workspace-single-instance/docker-compose.yaml +0 -88
- package/resources/templates/template-workspace-single-instance/package.json +0 -12
- package/resources/templates/template-workspace-single-instance/projects/.gitkeep +0 -0
- package/resources/templates/template-workspace-single-instance/tsconfig.json +0 -22
- package/src/utils/dockerCompose.ts +0 -38
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts-template": {
|
|
3
|
+
"contember": "docker-compose run contember-cli",
|
|
4
|
+
"start-admin": "vite admin --port ${VITE_PORT:-4000} --host 0.0.0.0",
|
|
5
|
+
"build-admin": "tsc && vite build admin"
|
|
6
|
+
},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@contember/schema": "{version}",
|
|
9
|
+
"@contember/schema-definition": "{version}",
|
|
10
|
+
"@contember/admin": "0.7.0-beta.1",
|
|
11
|
+
"@contember/admin-i18n": "0.7.0-beta.1",
|
|
12
|
+
"@types/react": "17.0.5",
|
|
13
|
+
"react": "17.0.1",
|
|
14
|
+
"react-dom": "17.0.1",
|
|
15
|
+
"vite": "^2.5.2"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowSyntheticDefaultImports": true,
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"isolatedModules": true,
|
|
6
|
+
"jsx": "react",
|
|
7
|
+
"lib": ["esnext", "dom"],
|
|
8
|
+
"module": "esnext",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"noImplicitOverride": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"target": "esnext"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -6,9 +6,7 @@ export class Application {
|
|
|
6
6
|
constructor(private readonly commandManager: CommandManager, private readonly applicationDescription: string) {}
|
|
7
7
|
|
|
8
8
|
async run(args: string[]): Promise<void> {
|
|
9
|
-
const [
|
|
10
|
-
|
|
11
|
-
const [name, ...rest] = commandArgs
|
|
9
|
+
const [name, ...rest] = args
|
|
12
10
|
if (!name || name === '--help') {
|
|
13
11
|
console.error(this.applicationDescription)
|
|
14
12
|
console.error(`Usage: <command> <command args>`)
|
|
@@ -41,11 +39,20 @@ export class Application {
|
|
|
41
39
|
|
|
42
40
|
return process.exit(0)
|
|
43
41
|
}
|
|
42
|
+
return this.runCommandInternal(name, rest, true)
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
+
public async runCommand(name: string, args: string[]) {
|
|
46
|
+
return this.runCommandInternal(name, args, false)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public async runCommandInternal(name: string, args: string[], showCommandName: boolean) {
|
|
45
50
|
const [fullName, command] = this.commandManager.createCommand(name)
|
|
46
51
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
52
|
+
if (args[0] === '--help' || args[0] === '-h') {
|
|
53
|
+
if (showCommandName) {
|
|
54
|
+
console.error(chalk.greenBright(fullName))
|
|
55
|
+
}
|
|
49
56
|
const configuration = command.getConfiguration()
|
|
50
57
|
const commandDescription = configuration.getDescription()
|
|
51
58
|
if (commandDescription) {
|
|
@@ -60,13 +67,13 @@ export class Application {
|
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
try {
|
|
63
|
-
const result = await command.run(
|
|
70
|
+
const result = await command.run(args)
|
|
64
71
|
return process.exit(result)
|
|
65
72
|
} catch (e) {
|
|
66
73
|
if (e instanceof InvalidInputError) {
|
|
67
74
|
console.error(chalk.bgRedBright.white(e.message))
|
|
68
75
|
const configuration = command.getConfiguration()
|
|
69
|
-
console.error(`${chalk.greenBright(fullName)}
|
|
76
|
+
console.error(`${showCommandName ? chalk.greenBright(fullName) + ' ' : ''}${chalk.green(configuration.getUsage({ format: 'line' }))}`)
|
|
70
77
|
|
|
71
78
|
return process.exit(1)
|
|
72
79
|
} else {
|
package/src/utils/PathMapping.ts
CHANGED
|
@@ -16,7 +16,7 @@ export const resolvePathMappingConfig = async (
|
|
|
16
16
|
return { ['*']: dir }
|
|
17
17
|
} else {
|
|
18
18
|
// single instance/project
|
|
19
|
-
const baseName = basename(baseDir)
|
|
19
|
+
const baseName = process.env.CONTEMBER_PROJECT_NAME ?? basename(baseDir)
|
|
20
20
|
.toLocaleLowerCase()
|
|
21
21
|
.replace(/[^-_a-z0-9]/, '')
|
|
22
22
|
return { [baseName]: baseDir }
|
package/src/utils/Project.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { pathExists } from 'fs-extra'
|
|
2
1
|
import * as path from 'path'
|
|
3
|
-
import { promises as fs } from 'fs'
|
|
4
|
-
import { updateYaml } from './yaml'
|
|
5
|
-
import { updateMainDockerComposeConfig } from './dockerCompose'
|
|
6
2
|
import { Workspace } from './Workspace'
|
|
7
|
-
import { projectNameToEnvName } from '@contember/engine-common'
|
|
8
3
|
|
|
9
4
|
export class Project {
|
|
10
5
|
constructor(
|
|
@@ -24,41 +19,6 @@ export class Project {
|
|
|
24
19
|
get migrationsDir() {
|
|
25
20
|
return path.join(this.apiDir, 'migrations')
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
async register() {
|
|
29
|
-
const adminPath = this.workspace.adminProjectsFile
|
|
30
|
-
if (await pathExists(adminPath)) {
|
|
31
|
-
const relativePath = path.relative(path.dirname(adminPath), this.adminDir)
|
|
32
|
-
const code = `export { default as ${this.name.replace('-', '_')} } from '${relativePath}'\n`
|
|
33
|
-
await fs.appendFile(adminPath, code, { encoding: 'utf8' })
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await updateYaml(this.workspace.apiConfigFile, (config, { merge }) =>
|
|
37
|
-
merge(config, {
|
|
38
|
-
projects: {
|
|
39
|
-
[this.name]: {
|
|
40
|
-
stages: { live: null },
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
)
|
|
45
|
-
await updateMainDockerComposeConfig(this.workspace.directory, config => {
|
|
46
|
-
const serviceName = config.services?.['contember'] ? 'contember' : 'api'
|
|
47
|
-
return {
|
|
48
|
-
...config,
|
|
49
|
-
services: {
|
|
50
|
-
...config.services,
|
|
51
|
-
[serviceName]: {
|
|
52
|
-
...config.services?.[serviceName],
|
|
53
|
-
environment: {
|
|
54
|
-
...config.services?.[serviceName]?.environment,
|
|
55
|
-
[projectNameToEnvName(this.name) + '_DB_NAME']: this.name,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
22
|
}
|
|
63
23
|
|
|
64
24
|
export const validateProjectName = (name: string) => {
|
package/src/utils/Workspace.ts
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import { pathExists } from 'fs-extra'
|
|
2
|
-
import * as path from 'path'
|
|
3
1
|
import { basename, join } from 'path'
|
|
4
|
-
import { readYaml, updateYaml } from './yaml'
|
|
5
2
|
import { ProjectManager } from './ProjectManager'
|
|
6
3
|
import { PathMapping } from './PathMapping'
|
|
7
4
|
import { installTemplate } from './template'
|
|
8
5
|
import { getPackageVersion } from './version'
|
|
9
|
-
import {
|
|
6
|
+
import { pathExists } from 'fs-extra'
|
|
7
|
+
import { readYaml } from './yaml'
|
|
10
8
|
|
|
11
|
-
interface WorkspaceDirectoryArgument {
|
|
9
|
+
export interface WorkspaceDirectoryArgument {
|
|
12
10
|
workspaceDirectory: string
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
template,
|
|
18
|
-
}: {
|
|
13
|
+
type CreateWorkspaceArgs = {
|
|
14
|
+
workspaceName: string
|
|
19
15
|
template?: string
|
|
20
|
-
} & WorkspaceDirectoryArgument
|
|
21
|
-
|
|
16
|
+
} & WorkspaceDirectoryArgument
|
|
17
|
+
|
|
18
|
+
export const createWorkspace = async ({ workspaceDirectory, workspaceName, template }: CreateWorkspaceArgs) => {
|
|
19
|
+
template ??= '@contember/template-workspace'
|
|
22
20
|
await installTemplate(template, workspaceDirectory, 'workspace', {
|
|
23
21
|
version: getPackageVersion(),
|
|
22
|
+
projectName: workspaceName,
|
|
24
23
|
})
|
|
25
24
|
const workspace = await Workspace.get(workspaceDirectory)
|
|
26
|
-
|
|
27
|
-
await project.register()
|
|
25
|
+
await workspace.projects.createProject(workspaceName, {})
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
export interface WorkspaceConfig {
|
|
@@ -61,38 +59,19 @@ export class Workspace {
|
|
|
61
59
|
return this.config?.api?.version || undefined
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
get apiConfigFile(): string {
|
|
65
|
-
return path.resolve(this.directory, this.config.api?.configFile || 'api/config.yaml')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get adminProjectsFile(): string {
|
|
69
|
-
return path.resolve(this.directory, this.config.admin?.projectsFile || 'admin/src/projects.ts')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async updateApiVersion(newVersion: string) {
|
|
73
|
-
const configPath = formatConfigPath(this.directory)
|
|
74
|
-
if (!(await pathExists(configPath))) {
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
await updateYaml(configPath, data => {
|
|
78
|
-
return {
|
|
79
|
-
...data,
|
|
80
|
-
api: {
|
|
81
|
-
...(typeof data.api === 'object' ? data.api : {}),
|
|
82
|
-
version: newVersion,
|
|
83
|
-
},
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
return true
|
|
87
|
-
}
|
|
88
62
|
}
|
|
89
63
|
|
|
90
|
-
const
|
|
64
|
+
export const formatWorkspaceConfigPath = (workspaceDirectory: string) => [
|
|
65
|
+
join(workspaceDirectory, 'contember.yaml'),
|
|
66
|
+
join(workspaceDirectory, 'contember.workspace.yaml'),
|
|
67
|
+
]
|
|
91
68
|
|
|
92
69
|
const readWorkspaceConfig = async ({ workspaceDirectory }: WorkspaceDirectoryArgument): Promise<WorkspaceConfig> => {
|
|
93
|
-
const configPath =
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
const configPath = formatWorkspaceConfigPath(workspaceDirectory)
|
|
71
|
+
for (const file of configPath) {
|
|
72
|
+
if ((await pathExists(file))) {
|
|
73
|
+
return await readYaml(file)
|
|
74
|
+
}
|
|
96
75
|
}
|
|
97
|
-
return
|
|
76
|
+
return {}
|
|
98
77
|
}
|
package/src/utils/fs.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const listDirectories = async (dir: string): Promise<string[]> => {
|
|
|
8
8
|
const stats = await Promise.all(entries.map(async it => tuple(it, await fs.lstat(it))))
|
|
9
9
|
return stats.filter(([, it]) => it.isDirectory()).map(([it]) => it)
|
|
10
10
|
} catch (e) {
|
|
11
|
-
if (e
|
|
11
|
+
if (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {
|
|
12
12
|
return []
|
|
13
13
|
}
|
|
14
14
|
throw e
|
|
@@ -25,7 +25,7 @@ export const tryUnlink = async (path: string): Promise<void> => {
|
|
|
25
25
|
try {
|
|
26
26
|
await fs.unlink(path)
|
|
27
27
|
} catch (e) {
|
|
28
|
-
if (e
|
|
28
|
+
if (e instanceof Error && 'code' in e && (e as any).code === 'ENOENT') {
|
|
29
29
|
return
|
|
30
30
|
}
|
|
31
31
|
throw e
|
package/src/utils/index.ts
CHANGED
package/src/utils/npm.ts
CHANGED
|
@@ -2,11 +2,11 @@ import getRegistryInfo from 'registry-info'
|
|
|
2
2
|
import getPackageJson from 'get-package-json-from-registry'
|
|
3
3
|
import npa from 'npm-package-arg'
|
|
4
4
|
import downloadTarball from 'download-tarball'
|
|
5
|
-
import {
|
|
5
|
+
import { readdir } from 'fs-extra'
|
|
6
6
|
import { join } from 'path'
|
|
7
7
|
import { tmpdir } from 'os'
|
|
8
8
|
|
|
9
|
-
export const downloadPackage = async (pkgName: string
|
|
9
|
+
export const downloadPackage = async (pkgName: string): Promise<string> => {
|
|
10
10
|
const { scope } = npa(pkgName)
|
|
11
11
|
const { authorization } = getRegistryInfo(scope)
|
|
12
12
|
const headers = authorization ? { authorization } : {}
|
|
@@ -22,6 +22,5 @@ export const downloadPackage = async (pkgName: string, dir: string): Promise<voi
|
|
|
22
22
|
if (dirContent.length !== 1 || dirContent[0] !== 'package') {
|
|
23
23
|
throw 'Invalid NPM package'
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
await remove(tmpDir)
|
|
25
|
+
return join(tmpDir, 'package')
|
|
27
26
|
}
|
package/src/utils/template.ts
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { replaceFileContent
|
|
1
|
+
import { isAbsolute, join } from 'path'
|
|
2
|
+
import { replaceFileContent } from './fs'
|
|
3
3
|
import { copy, pathExists, remove, rename } from 'fs-extra'
|
|
4
|
-
import { readYaml } from './yaml'
|
|
5
4
|
import { downloadPackage } from './npm'
|
|
5
|
+
import { resourcesDir } from '../pathUtils'
|
|
6
|
+
import { readYaml } from './yaml'
|
|
6
7
|
|
|
8
|
+
const localTemplates: Record<string, string> = {
|
|
9
|
+
['@contember/template-workspace']: join(resourcesDir, 'templates/template-workspace'),
|
|
10
|
+
['@contember/template-project']: join(resourcesDir, 'templates/template-project'),
|
|
11
|
+
}
|
|
7
12
|
export const installTemplate = async (
|
|
8
13
|
template: string,
|
|
9
14
|
targetDir: string,
|
|
10
15
|
requiredTemplateType: string,
|
|
11
16
|
variables: Record<string, string> = {},
|
|
12
17
|
) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await downloadPackage(template, targetDir)
|
|
18
|
+
let removeTemplate = () => {}
|
|
19
|
+
if (localTemplates[template]) {
|
|
20
|
+
template = localTemplates[template]
|
|
21
|
+
}
|
|
22
|
+
if (!isAbsolute(template)) {
|
|
23
|
+
template = await downloadPackage(template)
|
|
24
|
+
removeTemplate = async () => {
|
|
25
|
+
await remove(template)
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
|
-
const templateConfigFile = join(
|
|
28
|
+
const templateConfigFile = join(template, 'contember.template.yaml')
|
|
25
29
|
if (!(await pathExists(templateConfigFile))) {
|
|
26
|
-
await remove(targetDir)
|
|
27
30
|
throw `${template} is not a Contember template`
|
|
28
31
|
}
|
|
29
32
|
const config = (await readYaml(templateConfigFile)) as {
|
|
@@ -31,17 +34,15 @@ export const installTemplate = async (
|
|
|
31
34
|
remove?: string[]
|
|
32
35
|
patchPackageJson?: boolean
|
|
33
36
|
rename?: Record<string, string>
|
|
37
|
+
copy?: Record<string, string>
|
|
34
38
|
replaceVariables?: string[]
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (const fileToRemove of config.remove || []) {
|
|
43
|
-
await tryUnlink(join(targetDir, fileToRemove))
|
|
44
|
-
}
|
|
40
|
+
const nodeModulesDir = join(template, 'node_modules')
|
|
41
|
+
const skippedFiles = new Set([...(config.remove || []).map(it => join(template, it)), templateConfigFile])
|
|
42
|
+
await copy(template, targetDir, {
|
|
43
|
+
filter: src => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src),
|
|
44
|
+
})
|
|
45
|
+
await removeTemplate()
|
|
45
46
|
|
|
46
47
|
if (config.patchPackageJson) {
|
|
47
48
|
await replaceFileContent(join(targetDir, 'package.json'), content => {
|
|
@@ -59,6 +60,9 @@ export const installTemplate = async (
|
|
|
59
60
|
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
60
61
|
await rename(join(targetDir, source), join(targetDir, target))
|
|
61
62
|
}
|
|
63
|
+
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
64
|
+
await copy(join(targetDir, source), join(targetDir, target))
|
|
65
|
+
}
|
|
62
66
|
|
|
63
67
|
for (const file of config.replaceVariables || []) {
|
|
64
68
|
const path = join(targetDir, file)
|
package/src/utils/yaml.ts
CHANGED
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
import { JSONObject, JSONPrimitive } from './json'
|
|
2
|
-
import { pathExists } from 'fs-extra'
|
|
3
|
-
import { promises as fs } from 'fs'
|
|
4
|
-
import YAWN from 'yawn-yaml/cjs'
|
|
5
|
-
import { Merger } from '@contember/config-loader'
|
|
6
1
|
import jsyaml from 'js-yaml'
|
|
2
|
+
import { JSONObject } from './json'
|
|
3
|
+
import { readFile } from 'fs/promises'
|
|
7
4
|
|
|
8
|
-
export type JsonUpdateCallback<Value = JSONObject> = (
|
|
9
|
-
data: Partial<Value>,
|
|
10
|
-
utils: { merge: (a: JSONObject, b: JSONObject) => JSONObject },
|
|
11
|
-
) => Value
|
|
12
|
-
|
|
13
|
-
export const updateYaml = async <Value = JSONObject>(
|
|
14
|
-
path: string,
|
|
15
|
-
updater: JsonUpdateCallback<Value>,
|
|
16
|
-
options: { createMissing?: boolean } = {},
|
|
17
|
-
) => {
|
|
18
|
-
let config = ''
|
|
19
|
-
if (await pathExists(path)) {
|
|
20
|
-
config = await fs.readFile(path, { encoding: 'utf8' })
|
|
21
|
-
} else if (options.createMissing !== true) {
|
|
22
|
-
throw new Error(`File ${path} does not exist.`)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let newConfig = ''
|
|
26
|
-
const mergeUtils = { merge: (a: JSONObject, b: JSONObject) => Merger.merge<JSONPrimitive>(a, b) }
|
|
27
|
-
if (config) {
|
|
28
|
-
const yawn = new YAWN(config)
|
|
29
|
-
yawn.json = updater(yawn.json, mergeUtils)
|
|
30
|
-
newConfig = yawn.yaml
|
|
31
|
-
} else {
|
|
32
|
-
newConfig = jsyaml.dump(updater({}, mergeUtils))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await fs.writeFile(path, newConfig, { encoding: 'utf8' })
|
|
36
|
-
}
|
|
37
5
|
|
|
38
6
|
export const readYaml = async <T = JSONObject>(path: string): Promise<T> => {
|
|
39
|
-
const content = await
|
|
7
|
+
const content = await readFile(path, { encoding: 'utf8' })
|
|
40
8
|
return jsyaml.load(content) as unknown as T
|
|
41
9
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { JsonUpdateCallback } from './yaml';
|
|
2
|
-
export interface DockerComposeServiceConfig {
|
|
3
|
-
image?: string;
|
|
4
|
-
command?: string;
|
|
5
|
-
user?: string;
|
|
6
|
-
environment?: Record<string, string>;
|
|
7
|
-
ports?: (string | {})[];
|
|
8
|
-
}
|
|
9
|
-
export interface DockerComposeConfig {
|
|
10
|
-
[key: string]: unknown;
|
|
11
|
-
version?: string;
|
|
12
|
-
services?: Record<string, DockerComposeServiceConfig>;
|
|
13
|
-
}
|
|
14
|
-
export declare const updateMainDockerComposeConfig: (dir: string, updater: JsonUpdateCallback<DockerComposeConfig>) => Promise<void>;
|
|
15
|
-
//# sourceMappingURL=dockerCompose.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dockerCompose.d.ts","sourceRoot":"","sources":["../../../src/utils/dockerCompose.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAc,MAAM,QAAQ,CAAA;AAIvD,MAAM,WAAW,0BAA0B;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,mBAAmB;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IAEtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAA;CACrD;AAYD,eAAO,MAAM,6BAA6B,QACpC,MAAM,WACF,mBAAmB,mBAAmB,CAAC,KAC9C,QAAQ,IAAI,CAGd,CAAA"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateMainDockerComposeConfig = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const fs_extra_1 = require("fs-extra");
|
|
6
|
-
const yaml_1 = require("./yaml");
|
|
7
|
-
const MAIN_CONFIGS = ['docker-compose.yaml', 'docker-compose.yml'];
|
|
8
|
-
const resolvePath = async (dir, possibleFileNames, fallbackFileName) => {
|
|
9
|
-
for (const file of possibleFileNames) {
|
|
10
|
-
const path = path_1.join(dir, file);
|
|
11
|
-
if (await fs_extra_1.pathExists(path)) {
|
|
12
|
-
return path;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return path_1.join(dir, fallbackFileName);
|
|
16
|
-
};
|
|
17
|
-
const updateMainDockerComposeConfig = async (dir, updater) => {
|
|
18
|
-
const path = process.env.COMPOSE_FILE || (await resolvePath(dir, MAIN_CONFIGS, MAIN_CONFIGS[0]));
|
|
19
|
-
return yaml_1.updateYaml(path, updater, { createMissing: true });
|
|
20
|
-
};
|
|
21
|
-
exports.updateMainDockerComposeConfig = updateMainDockerComposeConfig;
|
|
22
|
-
//# sourceMappingURL=dockerCompose.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dockerCompose.js","sourceRoot":"","sources":["../../../src/utils/dockerCompose.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,uCAAqC;AACrC,iCAAuD;AAEvD,MAAM,YAAY,GAAG,CAAC,qBAAqB,EAAE,oBAAoB,CAAC,CAAA;AAiBlE,MAAM,WAAW,GAAG,KAAK,EAAE,GAAW,EAAE,iBAA2B,EAAE,gBAAwB,EAAmB,EAAE;IACjH,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE;QACrC,MAAM,IAAI,GAAG,WAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QAC5B,IAAI,MAAM,qBAAU,CAAC,IAAI,CAAC,EAAE;YAC3B,OAAO,IAAI,CAAA;SACX;KACD;IACD,OAAO,WAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;AACnC,CAAC,CAAA;AAEM,MAAM,6BAA6B,GAAG,KAAK,EACjD,GAAW,EACX,OAAgD,EAChC,EAAE;IAClB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,MAAM,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAChG,OAAO,iBAAU,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAC1D,CAAC,CAAA;AANY,QAAA,6BAA6B,iCAMzC"}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"modifications": [
|
|
3
|
-
{
|
|
4
|
-
"modification": "createEntity",
|
|
5
|
-
"entity": {
|
|
6
|
-
"name": "Image",
|
|
7
|
-
"primary": "id",
|
|
8
|
-
"primaryColumn": "id",
|
|
9
|
-
"tableName": "image",
|
|
10
|
-
"fields": {
|
|
11
|
-
"id": {
|
|
12
|
-
"name": "id",
|
|
13
|
-
"columnName": "id",
|
|
14
|
-
"nullable": false,
|
|
15
|
-
"type": "Uuid",
|
|
16
|
-
"columnType": "uuid"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"unique": {}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"modification": "createEntity",
|
|
24
|
-
"entity": {
|
|
25
|
-
"name": "Post",
|
|
26
|
-
"primary": "id",
|
|
27
|
-
"primaryColumn": "id",
|
|
28
|
-
"tableName": "post",
|
|
29
|
-
"fields": {
|
|
30
|
-
"id": {
|
|
31
|
-
"name": "id",
|
|
32
|
-
"columnName": "id",
|
|
33
|
-
"nullable": false,
|
|
34
|
-
"type": "Uuid",
|
|
35
|
-
"columnType": "uuid"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"unique": {}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"modification": "createColumn",
|
|
43
|
-
"entityName": "Image",
|
|
44
|
-
"field": {
|
|
45
|
-
"name": "url",
|
|
46
|
-
"columnName": "url",
|
|
47
|
-
"nullable": true,
|
|
48
|
-
"type": "String",
|
|
49
|
-
"columnType": "text"
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"modification": "createColumn",
|
|
54
|
-
"entityName": "Post",
|
|
55
|
-
"field": {
|
|
56
|
-
"name": "title",
|
|
57
|
-
"columnName": "title",
|
|
58
|
-
"nullable": false,
|
|
59
|
-
"type": "String",
|
|
60
|
-
"columnType": "text"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"modification": "createColumn",
|
|
65
|
-
"entityName": "Post",
|
|
66
|
-
"field": {
|
|
67
|
-
"name": "content",
|
|
68
|
-
"columnName": "content",
|
|
69
|
-
"nullable": false,
|
|
70
|
-
"type": "String",
|
|
71
|
-
"columnType": "text"
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"modification": "createRelation",
|
|
76
|
-
"entityName": "Post",
|
|
77
|
-
"owningSide": {
|
|
78
|
-
"name": "image",
|
|
79
|
-
"nullable": true,
|
|
80
|
-
"type": "ManyHasOne",
|
|
81
|
-
"target": "Image",
|
|
82
|
-
"joiningColumn": {
|
|
83
|
-
"columnName": "image_id",
|
|
84
|
-
"onDelete": "restrict"
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"modification": "patchAclSchema",
|
|
90
|
-
"patch": [
|
|
91
|
-
{
|
|
92
|
-
"op": "add",
|
|
93
|
-
"path": "/roles/admin",
|
|
94
|
-
"value": {
|
|
95
|
-
"variables": {},
|
|
96
|
-
"stages": "*",
|
|
97
|
-
"entities": {
|
|
98
|
-
"Image": {
|
|
99
|
-
"predicates": {},
|
|
100
|
-
"operations": {
|
|
101
|
-
"create": {
|
|
102
|
-
"id": true,
|
|
103
|
-
"url": true
|
|
104
|
-
},
|
|
105
|
-
"read": {
|
|
106
|
-
"id": true,
|
|
107
|
-
"url": true
|
|
108
|
-
},
|
|
109
|
-
"update": {
|
|
110
|
-
"id": true,
|
|
111
|
-
"url": true
|
|
112
|
-
},
|
|
113
|
-
"delete": true
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
"Post": {
|
|
117
|
-
"predicates": {},
|
|
118
|
-
"operations": {
|
|
119
|
-
"create": {
|
|
120
|
-
"id": true,
|
|
121
|
-
"title": true,
|
|
122
|
-
"content": true,
|
|
123
|
-
"image": true
|
|
124
|
-
},
|
|
125
|
-
"read": {
|
|
126
|
-
"id": true,
|
|
127
|
-
"title": true,
|
|
128
|
-
"content": true,
|
|
129
|
-
"image": true
|
|
130
|
-
},
|
|
131
|
-
"update": {
|
|
132
|
-
"id": true,
|
|
133
|
-
"title": true,
|
|
134
|
-
"content": true,
|
|
135
|
-
"image": true
|
|
136
|
-
},
|
|
137
|
-
"delete": true
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
]
|
|
146
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@contember/template-project",
|
|
3
|
-
"version": "0.12.0-alpha.9",
|
|
4
|
-
"license": "Apache-2.0",
|
|
5
|
-
"devDependencies": {},
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"@contember/schema": "^0.12.0-alpha.9",
|
|
8
|
-
"@contember/schema-definition": "^0.12.0-alpha.9"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "echo 'No tests'"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/node_modules
|
|
File without changes
|