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