@nizza/devkit 0.2.3-beta.0 → 0.2.3
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
3
4
|
var fs = require('fs');
|
|
4
5
|
var path = require('path');
|
|
5
|
-
var devkit = require('@nx/devkit');
|
|
6
6
|
|
|
7
|
-
const { mkdir, writeFile, access } = fs.promises;
|
|
7
|
+
const { mkdir, writeFile, access, copyFile } = fs.promises;
|
|
8
8
|
/**
|
|
9
9
|
* Creates the content for an environment file based on the core environment path.
|
|
10
10
|
*
|
|
@@ -22,6 +22,29 @@ export const environment: Environment<typeof config> = config;
|
|
|
22
22
|
export default environment;
|
|
23
23
|
`;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Copies environment.ts to environment.local.ts for the core library.
|
|
27
|
+
* This is a special case since the core library cannot import from itself.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} environmentsDir - The environments directory path.
|
|
30
|
+
*/ async function copyEnvironmentForCore(environmentsDir) {
|
|
31
|
+
const sourceFile = path.join(environmentsDir, 'environment.ts');
|
|
32
|
+
const targetFile = path.join(environmentsDir, 'environment.local.ts');
|
|
33
|
+
try {
|
|
34
|
+
await access(targetFile);
|
|
35
|
+
devkit.logger.info(`✅ The file "environment.local.ts" already exists.`);
|
|
36
|
+
} catch {
|
|
37
|
+
try {
|
|
38
|
+
await access(sourceFile);
|
|
39
|
+
devkit.logger.warn(`📝 The file "environment.local.ts" does not exist. Copying from environment.ts...`);
|
|
40
|
+
await copyFile(sourceFile, targetFile);
|
|
41
|
+
devkit.logger.info(`🎉 The file "environment.local.ts" has been created by copying environment.ts.`);
|
|
42
|
+
} catch {
|
|
43
|
+
devkit.logger.error(`❌ Source file "environment.ts" does not exist. Cannot create environment.local.ts.`);
|
|
44
|
+
throw new Error('Source environment.ts file not found in core library');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
25
48
|
/**
|
|
26
49
|
* Ensures that the given directory exists, creating it if it does not.
|
|
27
50
|
*
|
|
@@ -57,6 +80,7 @@ export default environment;
|
|
|
57
80
|
}));
|
|
58
81
|
}
|
|
59
82
|
|
|
83
|
+
exports.copyEnvironmentForCore = copyEnvironmentForCore;
|
|
60
84
|
exports.createEnvironmentFileContent = createEnvironmentFileContent;
|
|
61
85
|
exports.ensureDirectoryExists = ensureDirectoryExists;
|
|
62
86
|
exports.writeFilesIfNotExist = writeFilesIfNotExist;
|
|
@@ -29,6 +29,8 @@ const environmentFiles = [
|
|
|
29
29
|
const projectConfig = utils.getProjectConfig(ctx);
|
|
30
30
|
const environmentsDir = path.join(projectConfig.root, ENV_DIR);
|
|
31
31
|
const mainPkgJson = utils$1.getPkgJson(ctx.root);
|
|
32
|
+
// Check if this is the core library
|
|
33
|
+
const isCoreLibrary = projectConfig.root.includes('libs/core');
|
|
32
34
|
const getEnvPath = (fileName)=>{
|
|
33
35
|
const isLocal = fileName.includes('.local');
|
|
34
36
|
const coreEnvFile = (isLocal ? ENV_DEV_FILE : fileName).replace('.ts', '');
|
|
@@ -39,15 +41,21 @@ const environmentFiles = [
|
|
|
39
41
|
};
|
|
40
42
|
};
|
|
41
43
|
await helpers.ensureDirectoryExists(environmentsDir);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
if (isCoreLibrary) {
|
|
45
|
+
// Special handling for core library: copy environment.ts to environment.local.ts
|
|
46
|
+
await helpers.copyEnvironmentForCore(environmentsDir);
|
|
47
|
+
} else {
|
|
48
|
+
// Normal handling for other libraries and apps
|
|
49
|
+
for (const envFileName of environmentFiles){
|
|
50
|
+
const { key, coreEnvFile } = getEnvPath(envFileName);
|
|
51
|
+
const content = await helpers.createEnvironmentFileContent({
|
|
52
|
+
coreEnvFile,
|
|
53
|
+
projectOrg: mainPkgJson.name
|
|
54
|
+
});
|
|
55
|
+
await helpers.writeFilesIfNotExist(environmentsDir, {
|
|
56
|
+
[key]: content
|
|
57
|
+
});
|
|
58
|
+
}
|
|
51
59
|
}
|
|
52
60
|
return utils.ok();
|
|
53
61
|
} catch (error) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { logger } from '@nx/devkit';
|
|
1
2
|
import { promises } from 'fs';
|
|
2
3
|
import { join } from 'path';
|
|
3
|
-
import { logger } from '@nx/devkit';
|
|
4
4
|
|
|
5
|
-
const { mkdir, writeFile, access } = promises;
|
|
5
|
+
const { mkdir, writeFile, access, copyFile } = promises;
|
|
6
6
|
/**
|
|
7
7
|
* Creates the content for an environment file based on the core environment path.
|
|
8
8
|
*
|
|
@@ -20,6 +20,29 @@ export const environment: Environment<typeof config> = config;
|
|
|
20
20
|
export default environment;
|
|
21
21
|
`;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Copies environment.ts to environment.local.ts for the core library.
|
|
25
|
+
* This is a special case since the core library cannot import from itself.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} environmentsDir - The environments directory path.
|
|
28
|
+
*/ async function copyEnvironmentForCore(environmentsDir) {
|
|
29
|
+
const sourceFile = join(environmentsDir, 'environment.ts');
|
|
30
|
+
const targetFile = join(environmentsDir, 'environment.local.ts');
|
|
31
|
+
try {
|
|
32
|
+
await access(targetFile);
|
|
33
|
+
logger.info(`✅ The file "environment.local.ts" already exists.`);
|
|
34
|
+
} catch {
|
|
35
|
+
try {
|
|
36
|
+
await access(sourceFile);
|
|
37
|
+
logger.warn(`📝 The file "environment.local.ts" does not exist. Copying from environment.ts...`);
|
|
38
|
+
await copyFile(sourceFile, targetFile);
|
|
39
|
+
logger.info(`🎉 The file "environment.local.ts" has been created by copying environment.ts.`);
|
|
40
|
+
} catch {
|
|
41
|
+
logger.error(`❌ Source file "environment.ts" does not exist. Cannot create environment.local.ts.`);
|
|
42
|
+
throw new Error('Source environment.ts file not found in core library');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
23
46
|
/**
|
|
24
47
|
* Ensures that the given directory exists, creating it if it does not.
|
|
25
48
|
*
|
|
@@ -55,4 +78,4 @@ export default environment;
|
|
|
55
78
|
}));
|
|
56
79
|
}
|
|
57
80
|
|
|
58
|
-
export { createEnvironmentFileContent, ensureDirectoryExists, writeFilesIfNotExist };
|
|
81
|
+
export { copyEnvironmentForCore, createEnvironmentFileContent, ensureDirectoryExists, writeFilesIfNotExist };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { getProjectConfig, ok, err } from '../shared/utils.mjs';
|
|
3
|
-
import { ensureDirectoryExists, createEnvironmentFileContent, writeFilesIfNotExist } from './helpers.mjs';
|
|
3
|
+
import { ensureDirectoryExists, copyEnvironmentForCore, createEnvironmentFileContent, writeFilesIfNotExist } from './helpers.mjs';
|
|
4
4
|
import '../../shared/logger.mjs';
|
|
5
5
|
import { getPkgJson } from '../../shared/utils.mjs';
|
|
6
6
|
|
|
@@ -27,6 +27,8 @@ const environmentFiles = [
|
|
|
27
27
|
const projectConfig = getProjectConfig(ctx);
|
|
28
28
|
const environmentsDir = join(projectConfig.root, ENV_DIR);
|
|
29
29
|
const mainPkgJson = getPkgJson(ctx.root);
|
|
30
|
+
// Check if this is the core library
|
|
31
|
+
const isCoreLibrary = projectConfig.root.includes('libs/core');
|
|
30
32
|
const getEnvPath = (fileName)=>{
|
|
31
33
|
const isLocal = fileName.includes('.local');
|
|
32
34
|
const coreEnvFile = (isLocal ? ENV_DEV_FILE : fileName).replace('.ts', '');
|
|
@@ -37,15 +39,21 @@ const environmentFiles = [
|
|
|
37
39
|
};
|
|
38
40
|
};
|
|
39
41
|
await ensureDirectoryExists(environmentsDir);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if (isCoreLibrary) {
|
|
43
|
+
// Special handling for core library: copy environment.ts to environment.local.ts
|
|
44
|
+
await copyEnvironmentForCore(environmentsDir);
|
|
45
|
+
} else {
|
|
46
|
+
// Normal handling for other libraries and apps
|
|
47
|
+
for (const envFileName of environmentFiles){
|
|
48
|
+
const { key, coreEnvFile } = getEnvPath(envFileName);
|
|
49
|
+
const content = await createEnvironmentFileContent({
|
|
50
|
+
coreEnvFile,
|
|
51
|
+
projectOrg: mainPkgJson.name
|
|
52
|
+
});
|
|
53
|
+
await writeFilesIfNotExist(environmentsDir, {
|
|
54
|
+
[key]: content
|
|
55
|
+
});
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
return ok();
|
|
51
59
|
} catch (error) {
|