@nizza/devkit 0.2.0-beta.6 → 0.2.1

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.
@@ -9,33 +9,52 @@ var util = require('util');
9
9
  const execAsync = util.promisify(child_process.exec);
10
10
  const changesetDir = path.resolve('.changeset');
11
11
  const preJsonPath = path.resolve(changesetDir, 'pre.json');
12
- let preJson;
13
- async function main() {
12
+ const readPreJson = async ()=>{
14
13
  try {
15
14
  const data = await promises.readFile(preJsonPath, 'utf8');
16
- preJson = JSON.parse(data);
15
+ return JSON.parse(data);
17
16
  } catch {
18
- preJson = {
17
+ return {
19
18
  mode: 'exit'
20
19
  };
21
20
  }
22
- // Execute "version" command using @changeset/cli
21
+ };
22
+ const executeCommand = async (command)=>{
23
23
  try {
24
- const { mode } = preJson;
24
+ const { stdout, stderr } = await execAsync(command);
25
+ devkit.logger.info(stdout);
26
+ if (stderr) devkit.logger.warn(`⚠️ ${stderr}`);
27
+ } catch (error) {
28
+ devkit.logger.error('❌ An error occurred while executing the command!');
29
+ throw error;
30
+ }
31
+ };
32
+ const handlePrereleaseMode = async (mode, exitMode)=>{
33
+ if (exitMode) {
25
34
  if (mode === 'exit') {
26
- const command = `pnpm changeset pre enter beta`;
27
- const { stdout, stderr } = await execAsync(command);
28
- devkit.logger.info(stdout);
29
- devkit.logger.info(stderr);
30
- devkit.logger.info(`🚀 Successfully enter prerelease mode`);
35
+ devkit.logger.info('ℹ️ Prerelease mode has not been entered. No need to exit.');
31
36
  } else {
32
- devkit.logger.info(`🚀 Prerelease mode has been previously entered`);
37
+ await executeCommand('pnpm changeset pre exit');
38
+ devkit.logger.info('✅ Successfully exited prerelease mode');
33
39
  }
40
+ } else {
41
+ if (mode === 'exit') {
42
+ await executeCommand('pnpm changeset pre enter beta');
43
+ devkit.logger.info('🚀 Successfully entered prerelease mode');
44
+ } else {
45
+ devkit.logger.info('🔄 Prerelease mode has been previously entered');
46
+ }
47
+ }
48
+ };
49
+ const main = async ()=>{
50
+ const args = process.argv.slice(2);
51
+ const exitMode = args.includes('--exit');
52
+ try {
53
+ const preJson = await readPreJson();
54
+ await handlePrereleaseMode(preJson.mode, exitMode);
34
55
  } catch (error) {
35
- devkit.logger.error('❌ An error occurred!');
56
+ devkit.logger.error('❌ An unexpected error occurred!');
36
57
  throw error;
37
58
  }
38
- }
59
+ };
39
60
  main();
40
-
41
- exports.main = main;
@@ -1,7 +1,4 @@
1
1
  'use strict';
2
2
 
3
- var changesetPreMode = require('./changeset-pre-mode.cjs');
3
+ require('./changeset-pre-mode.cjs');
4
4
 
5
-
6
-
7
- exports.main = changesetPreMode.main;
@@ -7,33 +7,52 @@ import { promisify } from 'util';
7
7
  const execAsync = promisify(exec);
8
8
  const changesetDir = resolve('.changeset');
9
9
  const preJsonPath = resolve(changesetDir, 'pre.json');
10
- let preJson;
11
- async function main() {
10
+ const readPreJson = async ()=>{
12
11
  try {
13
12
  const data = await readFile(preJsonPath, 'utf8');
14
- preJson = JSON.parse(data);
13
+ return JSON.parse(data);
15
14
  } catch {
16
- preJson = {
15
+ return {
17
16
  mode: 'exit'
18
17
  };
19
18
  }
20
- // Execute "version" command using @changeset/cli
19
+ };
20
+ const executeCommand = async (command)=>{
21
21
  try {
22
- const { mode } = preJson;
22
+ const { stdout, stderr } = await execAsync(command);
23
+ logger.info(stdout);
24
+ if (stderr) logger.warn(`⚠️ ${stderr}`);
25
+ } catch (error) {
26
+ logger.error('❌ An error occurred while executing the command!');
27
+ throw error;
28
+ }
29
+ };
30
+ const handlePrereleaseMode = async (mode, exitMode)=>{
31
+ if (exitMode) {
23
32
  if (mode === 'exit') {
24
- const command = `pnpm changeset pre enter beta`;
25
- const { stdout, stderr } = await execAsync(command);
26
- logger.info(stdout);
27
- logger.info(stderr);
28
- logger.info(`🚀 Successfully enter prerelease mode`);
33
+ logger.info('ℹ️ Prerelease mode has not been entered. No need to exit.');
29
34
  } else {
30
- logger.info(`🚀 Prerelease mode has been previously entered`);
35
+ await executeCommand('pnpm changeset pre exit');
36
+ logger.info('✅ Successfully exited prerelease mode');
31
37
  }
38
+ } else {
39
+ if (mode === 'exit') {
40
+ await executeCommand('pnpm changeset pre enter beta');
41
+ logger.info('🚀 Successfully entered prerelease mode');
42
+ } else {
43
+ logger.info('🔄 Prerelease mode has been previously entered');
44
+ }
45
+ }
46
+ };
47
+ const main = async ()=>{
48
+ const args = process.argv.slice(2);
49
+ const exitMode = args.includes('--exit');
50
+ try {
51
+ const preJson = await readPreJson();
52
+ await handlePrereleaseMode(preJson.mode, exitMode);
32
53
  } catch (error) {
33
- logger.error('❌ An error occurred!');
54
+ logger.error('❌ An unexpected error occurred!');
34
55
  throw error;
35
56
  }
36
- }
57
+ };
37
58
  main();
38
-
39
- export { main };
@@ -1 +1 @@
1
- export { main } from './changeset-pre-mode.mjs';
1
+ import './changeset-pre-mode.mjs';
@@ -0,0 +1,376 @@
1
+ // Generated by dts-bundle-generator v7.2.0
2
+
3
+ import { ExecutorContext } from '@nx/devkit';
4
+ import { PreRenderedChunk } from 'rollup';
5
+ import { ConfigEnv, LibraryOptions, Plugin, PluginOption, UserConfig, ViteDevServer } from 'vite';
6
+
7
+ export type ExecutorResponse = {
8
+ success: boolean;
9
+ };
10
+ export interface ExecutorOptions {
11
+ s3Bucket: string;
12
+ cloudFrontId: string;
13
+ buildTarget: string;
14
+ assetsDir: string;
15
+ rootDir?: string;
16
+ skipBuild?: boolean;
17
+ typings?: boolean;
18
+ dryRun?: boolean;
19
+ ignoreConfigs?: string[];
20
+ }
21
+ export function deployExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
22
+ export interface ExecutorOptions {
23
+ }
24
+ declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
25
+ export interface ExecutorOptions {
26
+ unlink?: boolean;
27
+ }
28
+ declare function runExecutor(opts: ExecutorOptions, context: ExecutorContext): Promise<ExecutorResponse>;
29
+ export interface ExecutorOptions {
30
+ tag: string;
31
+ dryRun?: boolean;
32
+ }
33
+ declare function runExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
34
+ export interface ExecutorOptions {
35
+ }
36
+ declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
37
+ declare function runExecutor(_opts: any, ctx: ExecutorContext): Promise<ExecutorResponse>;
38
+ export interface ExecutorOptions {
39
+ packageOrg: string;
40
+ rollback?: boolean;
41
+ skipLink?: boolean;
42
+ }
43
+ declare function runExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
44
+ declare enum LogLevel {
45
+ ERROR = 0,
46
+ WARN = 1,
47
+ INFO = 2,
48
+ DEBUG = 3
49
+ }
50
+ export declare enum ViteMode {
51
+ PROD = "production",
52
+ DEV = "development"
53
+ }
54
+ /**
55
+ * Project stages, it coincides with the target configurations of the project.json of NX.
56
+ * @readonly
57
+ * @enum {string}
58
+ */
59
+ export declare enum Stage {
60
+ PROD = "prod",
61
+ DEV = "dev",
62
+ LOCAL = "local"
63
+ }
64
+ export declare enum ProjectType {
65
+ APP = "app",
66
+ LIB = "lib",
67
+ SCRIPT = "script"
68
+ }
69
+ export declare enum Flag {
70
+ SOURCEMAP = "source-maps",
71
+ ANALYZE = "analyze",
72
+ VERBOSE = "verbose",
73
+ VERBOSE_ALIAS = "v",
74
+ HTTPS = "https"
75
+ }
76
+ export declare enum Target {
77
+ BUILD = "build",
78
+ PREVIEW = "preview",
79
+ SERVE = "serve"
80
+ }
81
+ /**
82
+ * Vite Environment.
83
+ *
84
+ * @property {ViteMode} mode - Vite mode.
85
+ */
86
+ export type ViteEnv = ConfigEnv & {
87
+ mode: ViteMode;
88
+ };
89
+ /**
90
+ * Externalizing libraries.
91
+ *
92
+ * @property {boolean} default - React externalizes and other common dependencies,
93
+ * this only applies to libraries.
94
+ * @property {boolean} glob - Glob expression or list of glob expressions to exclude
95
+ * dependencies from the package.json.
96
+ */
97
+ export type ExternalizeLibs = {
98
+ default: boolean;
99
+ glob: string | string[];
100
+ };
101
+ export type ResolveEnvs = {
102
+ default: boolean;
103
+ local: boolean;
104
+ };
105
+ /**
106
+ * Project configuration.
107
+ *
108
+ * @property {ProjectType} type - Type of the project.
109
+ * @property {string} path - Path of the project.
110
+ * @property {string} entry - Path of the file entry point.
111
+ * @property {string} name - Name of the project, it is also used to define the name of the library.
112
+ * @property {string} port - Server port.
113
+ * @property {boolean} debug - Print data purification data.
114
+ * @property {boolean} dts - Control if the .d.ts files are generated, by default it is True.
115
+ * @property {Partial<ResolveEnvs>} resolveEnvs - Flag for resolving environment.
116
+ * @property {boolean} shadowDom - If component is render into shadow dom.
117
+ * @property {Partial<ExternalizeLibs>} externalizeLibs - Configuration for externalizing libraries.
118
+ * @property {LibraryOptions['fileName']} fileName - Output file name for library.
119
+ * @property {string} fileName - Prefix for chunk file name.
120
+ * @property {ViteEnv} viteEnv - Vite environment configuration.
121
+ * @property {UserConfig} overrides - Overrides for vite configuration.
122
+ */
123
+ export interface ProjectConfig {
124
+ type: ProjectType;
125
+ path: string;
126
+ entry?: string;
127
+ name?: string;
128
+ port?: number;
129
+ logLevel?: LogLevel;
130
+ dts?: boolean;
131
+ resolveEnvs?: Partial<ResolveEnvs>;
132
+ shadowDom?: boolean;
133
+ externalizeLibs?: Partial<ExternalizeLibs>;
134
+ fileName?: LibraryOptions["fileName"];
135
+ chunkPrefix?: string;
136
+ viteEnv: ViteEnv;
137
+ overrides?: UserConfig;
138
+ }
139
+ export interface ProjectConfigInitialized extends ProjectConfig {
140
+ name: string;
141
+ fileName: string;
142
+ chunkPrefix: string;
143
+ logLevel: LogLevel;
144
+ overrides: UserConfig;
145
+ shadowDom: boolean;
146
+ resolveEnvs: ResolveEnvs;
147
+ externalizeLibs: ExternalizeLibs;
148
+ }
149
+ /**
150
+ * Vite command details.
151
+ * @interface
152
+ * @property {Stage} stage - Stage of the project.
153
+ * @property {string} target - Command name.
154
+ * @property {Record<string, any>} flags - Flags for customize command.
155
+ */
156
+ export interface ViteCommand {
157
+ stage: Stage;
158
+ target: string;
159
+ flags: Record<string, any>;
160
+ }
161
+ /**
162
+ * Common project configuration.
163
+ *
164
+ * @property {string} envPrefix - Prefix in lowercase for environment variables and output files.
165
+ * @property {boolean} externalizeLibGlob - Glob expression or list of glob expressions to exclude
166
+ * dependencies from the package.json.
167
+ */
168
+ export interface CommonProjectConfig {
169
+ envPrefix: string;
170
+ externalizeLibGlob?: string | string[];
171
+ }
172
+ /**
173
+ * Config builder context.
174
+ *
175
+ * @property {CommonProjectConfig} commonConfig - Common configuration for the project.
176
+ * @property {ProjectConfigInitialized} projectConfig - Initialized project configuration.
177
+ * @property {ViteCommandDetail} viteCmd - Vite command details.
178
+ */
179
+ export interface Context {
180
+ commonConfig: CommonProjectConfig;
181
+ projectConfig: ProjectConfigInitialized;
182
+ viteCmd: ViteCommand;
183
+ localPkgJson: Record<string, any>;
184
+ }
185
+ /**
186
+ * Interface for plugin configuration.
187
+ */
188
+ export interface PluginConfig {
189
+ /**
190
+ * Generates plugin(s) based on the provided configuration.
191
+ * @param {Context} ctx - The main configuration object.
192
+ * @returns {any[]} An array of plugins.
193
+ */
194
+ generate: (ctx: Context) => any[];
195
+ /**
196
+ * Condition to determine if the plugin(s) should be included.
197
+ * @param {Context} ctx - The main configuration object.
198
+ * @returns {boolean} True if the plugin(s) should be included; false otherwise.
199
+ */
200
+ condition?: (ctx: Context) => boolean;
201
+ }
202
+ /**
203
+ * Deeply merges two objects, combining their properties.
204
+ *
205
+ * @param {Record<string, any>} v1 - The first object.
206
+ * @param {Record<string, any>} v2 - The second object.
207
+ * @returns {Record<string, any>} - The merged object.
208
+ *
209
+ * @example
210
+ * const obj1 = { a: 1, b: { c: 2 } };
211
+ * const obj2 = { b: { d: 3 } };
212
+ * const merged = deepMerge(obj1, obj2); // Outputs: { a: 1, b: { c: 2, d: 3 } }
213
+ */
214
+ export declare function deepMerge(v1: Record<string, any>, v2: Record<string, any>): Record<string, any>;
215
+ /**
216
+ * Generates a name for js files.
217
+ *
218
+ * @param {string} [prefix] - An optional prefix for the chunk name.
219
+ * @returns - A function that takes an item and generates a chunk name.
220
+ *
221
+ * @example
222
+ * const generateChunkName = chunkName('prefix');
223
+ * const name = generateChunkName({ name: 'example' }); // Outputs: "prefix-example-Aj3_Dk7_2j.js"
224
+ */
225
+ export declare const chunkName: (prefix?: string) => (x: PreRenderedChunk) => string;
226
+ /**
227
+ * Returns the given object if the condition is true, otherwise returns null.
228
+ *
229
+ * @param {any} condition - The condition to evaluate.
230
+ * @param {Record<string, any>} obj - The object to return if the condition is true.
231
+ * @returns {Record<string, any> | null} - The object or null based on the condition.
232
+ *
233
+ * @example
234
+ * const obj = { a: 1 };
235
+ * const result = when(true, obj); // Outputs: { a: 1 }
236
+ * const result2 = when(false, obj); // Outputs: {}
237
+ */
238
+ export declare const when: (condition: any, obj: Record<string, any>) => Record<string, any>;
239
+ /**
240
+ * Filters and generates plugin configurations based on conditions and the provided context.
241
+ *
242
+ * @param {Context} ctx - The main configuration object.
243
+ * @returns {any[]} - An array of generated plugin configurations.
244
+ */
245
+ export declare const getPlugins: (ctx: Context, ...pluginConfigs: PluginConfig[]) => PluginOption[];
246
+ /**
247
+ * Gets the paths to the tsconfig files for all relevant projects.
248
+ *
249
+ * @returns {string[]} - An array containing paths to tsconfig files for both app and lib projects.
250
+ *
251
+ * @example
252
+ * const projects = {
253
+ * 'my-app': {
254
+ * type: 'app',
255
+ * data: { root: 'apps/my-app' }
256
+ * },
257
+ * 'my-lib': {
258
+ * type: 'lib',
259
+ * data: { root: 'libs/my-lib' }
260
+ * }
261
+ * };
262
+ *
263
+ * const tsConfigPaths = getTsConfigPaths(projects);
264
+ * console.log(tsConfigPaths);
265
+ * // Output:
266
+ * // ['apps/my-app/tsconfig.app.json', 'libs/my-lib/tsconfig.lib.json']
267
+ */
268
+ export declare const getNxTsConfigPaths: () => string[];
269
+ /**
270
+ * Initializes the project configuration with default values.
271
+ *
272
+ * @example
273
+ * const config = { type: ProjectType.APP, path: '/path/to/project', viteEnv: { mode: ViteMode.DEV } };
274
+ * const initializedConfig = initializeConfig(config);
275
+ */
276
+ export declare const initializeConfig: (ccfg: CommonProjectConfig, pcfg: ProjectConfig, localPkgJson: Record<string, any>) => {
277
+ viteCmd: ViteCommand;
278
+ cfg: ProjectConfigInitialized;
279
+ };
280
+ /**
281
+ * Handles merging configurations and logs any errors.
282
+ *
283
+ * @param {UserConfig} defaultConfig - The default configuration.
284
+ * @param {UserConfig} overrides - The overrides configuration.
285
+ * @returns {UserConfig} - The merged configuration.
286
+ */
287
+ export declare const mergeConfigs: (defaultConfig: UserConfig, overrides: UserConfig) => UserConfig;
288
+ /**
289
+ * Resolves glob patterns to actual package names found in package.json dependencies.
290
+ * This function is used to determine which packages should be treated as external
291
+ * in a Rollup or Vite build configuration.
292
+ *
293
+ * @param {string} path - The base path where package.json is located.
294
+ * @param {string | string[]} globs - A glob pattern or an array of glob patterns to match dependencies against.
295
+ * @returns {string[]} An array of package names that match the given glob patterns.
296
+ *
297
+ * @example
298
+ * // Example of using `getExternalDependencies` to find all dependencies starting with "my-lib" and "lodash"
299
+ * const projectPath = '/path/to/project';
300
+ * const globs = ['my-lib*', 'lodash'];
301
+ * const externalDependencies = getExternalDependencies(projectPath, globs);
302
+ * console.log(externalDependencies);
303
+ * // Output might be: ['my-lib/utils', 'my-lib/core', 'lodash']
304
+ */
305
+ export declare const getExternalDependencies: (path: string, globs?: string | string[]) => string[];
306
+ /**
307
+ * Generates a string of initials based on the input string,
308
+ * following certain rules:
309
+ * 1. A word is considered as a sequence of characters
310
+ * separated by hyphens.
311
+ * 2. If the string contains '@', any characters before
312
+ * and including the next '/' are ignored.
313
+ * 3. The first character of each word is taken to form
314
+ * the initials.
315
+ *
316
+ * @param {string} input - The input string from which to generate the initials.
317
+ * @returns {string} The initials formed by taking the first character
318
+ * of each word, after applying the specified rules.
319
+ *
320
+ * @example
321
+ * getInitials("player-script"); // returns "ps"
322
+ * getInitials("ssv-admin"); // returns "sa"
323
+ * getInitials("@nizza/customize-live"); // returns "cl"
324
+ */
325
+ export declare function getInitials(input: string): string;
326
+ /**
327
+ * Retrieves the Vite command details.
328
+ *
329
+ * @param {ViteMode} mode - The Vite mode.
330
+ * @returns {ViteCommand} - The command details.
331
+ *
332
+ * @example
333
+ * const command = getViteCommand(ViteMode.PROD);
334
+ * // Outputs: { stage: Stage.PROD, target: 'build', flags: {} }
335
+ */
336
+ export declare function getViteCommand(mode: ViteMode): ViteCommand;
337
+ /**
338
+ * Parses the command string to extract flags.
339
+ *
340
+ * @param {string | undefined} commandString - The command string.
341
+ * @returns {Record<string, string>} - The flags extracted from the command string.
342
+ *
343
+ * @example
344
+ * const flags = getViteCmdFlags('nx run core:build --source-maps');
345
+ * // Outputs: { 'source-maps: 'true' }
346
+ */
347
+ export declare function getViteCmdFlags(commandString: string | undefined): Record<string, string>;
348
+ /**
349
+ * Builds the configuration based on common and project-specific configurations.
350
+ *
351
+ * @param {CommonProjectConfig} commonConfig - The common configuration.
352
+ * @returns - Returns a function that accepts a project configuration and returns the Vite configuration.
353
+ */
354
+ export declare const createConfigBuilder: (commonConfig: CommonProjectConfig) => (projectConfig: ProjectConfig) => UserConfig;
355
+ export interface Execute {
356
+ function: (data?: string) => void;
357
+ listen: string;
358
+ observer: string;
359
+ }
360
+ export interface ThirdPartyCssInjectPlugin {
361
+ topExecutionPriority?: boolean;
362
+ execute?: Execute[];
363
+ }
364
+ /**
365
+ * Inject the CSS compiled with JS.
366
+ *
367
+ * @return {Plugin}
368
+ */
369
+ export declare function thirdPartyCssInjectPlugin({ topExecutionPriority, execute }?: ThirdPartyCssInjectPlugin | undefined): Plugin;
370
+ export declare function injectCssIntoShadowDom(): {
371
+ name: string;
372
+ configureServer(_server: ViteDevServer): void;
373
+ transform(src: string, id: string): void;
374
+ };
375
+
376
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nizza/devkit",
3
- "version": "0.2.0-beta.6",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",