@mouryaamit/nx-polystack 1.1.0 → 1.2.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.
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askValid = exports.scriptedPrompter = exports.terminalPrompter = exports.isInteractive = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const readline = tslib_1.__importStar(require("readline"));
6
+ const types_1 = require("./types");
7
+ /** Questions are asked only when both ends are a terminal. */
8
+ function isInteractive() {
9
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY);
10
+ }
11
+ exports.isInteractive = isInteractive;
12
+ /** A prompter on stdin/stdout (Node readline; no extra dependency). */
13
+ function terminalPrompter() {
14
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
15
+ return {
16
+ ask: (question, defaultValue) => new Promise((resolve) => {
17
+ const hint = defaultValue !== undefined && defaultValue !== '' ? ` [${defaultValue}]` : '';
18
+ rl.question(`${question}${hint}: `, (answer) => {
19
+ const a = answer.trim();
20
+ resolve(a === '' ? defaultValue ?? '' : a);
21
+ });
22
+ }),
23
+ close: () => rl.close(),
24
+ };
25
+ }
26
+ exports.terminalPrompter = terminalPrompter;
27
+ /** A prompter answering from a list (tests); throws when it runs out. */
28
+ function scriptedPrompter(answers, asked = []) {
29
+ const queue = [...answers];
30
+ return {
31
+ ask: async (question, defaultValue) => {
32
+ asked.push(question);
33
+ if (queue.length === 0)
34
+ throw new Error(`no scripted answer for "${question}"`);
35
+ const a = (queue.shift() ?? '').trim();
36
+ return a === '' ? defaultValue ?? '' : a;
37
+ },
38
+ close: () => undefined,
39
+ };
40
+ }
41
+ exports.scriptedPrompter = scriptedPrompter;
42
+ const MAX_TRIES = 3;
43
+ /**
44
+ * Asks until `check` accepts the answer (it returns the problem, or undefined); gives up after
45
+ * three tries.
46
+ */
47
+ async function askValid(p, question, defaultValue, check, say = (l) => console.log(l)) {
48
+ for (let i = 0; i < MAX_TRIES; i++) {
49
+ const answer = await p.ask(question, defaultValue);
50
+ const problem = check(answer);
51
+ if (!problem)
52
+ return answer;
53
+ say(` ${problem}`);
54
+ }
55
+ throw new types_1.CliError(`no valid answer to "${question}"; nothing was changed.`);
56
+ }
57
+ exports.askValid = askValid;
58
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/cli/prompt.ts"],"names":[],"mappings":";;;;AAAA,2DAAqC;AAErC,mCAAmC;AASnC,8DAA8D;AAC9D,SAAgB,aAAa;IAC3B,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAFD,sCAEC;AAED,uEAAuE;AACvE,SAAgB,gBAAgB;IAC9B,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtF,OAAO;QACL,GAAG,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,CAC9B,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACtB,MAAM,IAAI,GAAG,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3F,EAAE,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;gBAC7C,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;gBACxB,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;QACL,CAAC,CA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AAC,KAAK,OAAO,EAAE,CAAC,CAAC;KACrB;IACD,MAAM,IAAI,gBAAQ,CAAC,uBAAuB,QAAQ,yBAAyB,CAAC,CAAC;AAC/E,CAAC;AAdD,4BAcC"}
@@ -0,0 +1,86 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { SkipRules } from '../migrate/copy';
3
+ export type AppType = 'angular' | 'ionic' | 'flutter';
4
+ /** What `pstack app --from` needs to know about the base app (also for its questions). */
5
+ export interface BaseApp {
6
+ name: string;
7
+ type: AppType;
8
+ /** Project folder, e.g. apps/web or apps/legacy/web. */
9
+ root: string;
10
+ /** The folder under apps/ that holds it (the --dir default), when it sits under apps/. */
11
+ dir?: string;
12
+ /** Its environments (release configurations / Flutter env files), dev first. */
13
+ envs: string[];
14
+ /** The environment that builds DEV (always kept). */
15
+ devEnv: string;
16
+ /** A release configuration sets a base href. */
17
+ baseHref: boolean;
18
+ tags: string[];
19
+ /** Ionic: the Capacitor appId. */
20
+ appId?: string;
21
+ /** Angular/Ionic: the folder under environments/ with its env files. */
22
+ envProject?: string;
23
+ /** Angular/Ionic: env → its env file name(s) in environments/<envProject>/. */
24
+ envFiles?: Record<string, string[]>;
25
+ }
26
+ export interface AppFromOptions {
27
+ from: string;
28
+ name: string;
29
+ dir?: string;
30
+ port?: number;
31
+ /** undefined: `/<name>/` when the base app has one; null: none. */
32
+ baseHref?: string | null;
33
+ appId?: string;
34
+ /** Environments to keep (default all; the dev one is always kept). */
35
+ envs?: string[];
36
+ csp?: 'keep' | 'clear';
37
+ tags?: string[];
38
+ }
39
+ export interface Leftover {
40
+ file: string;
41
+ line: number;
42
+ text: string;
43
+ }
44
+ export interface AppFromResult {
45
+ base: BaseApp;
46
+ name: string;
47
+ root: string;
48
+ port: number;
49
+ baseHref?: string;
50
+ appId?: string;
51
+ envs: string[];
52
+ leftOut: string[];
53
+ /** Files copied into the new app (relative to the workspace). */
54
+ copied: string[];
55
+ /** Env files written with emptied values. */
56
+ envFiles: string[];
57
+ /** `file: key` of values that were not literals (now ''). */
58
+ expressions: string[];
59
+ /** Spread/shorthand entries left as written (`file: entry`). */
60
+ unkeyed: string[];
61
+ /** Env files whose `environment` is not an object literal: copied as they are. */
62
+ notEmptied: string[];
63
+ /** Paths not copied (build output, caches, ignored files); folders end with "/". */
64
+ skipped: string[];
65
+ /** Possible secrets not copied. */
66
+ secrets: string[];
67
+ leftovers: Leftover[];
68
+ /** Root npm scripts added for the new app. */
69
+ scripts: string[];
70
+ }
71
+ /** Not copied from the base app (on top of what git ignores). */
72
+ export declare const APP_FROM_SKIP: SkipRules;
73
+ /** com.example.<name, alphanumerics only>; prefixed with "app" when it would start with a digit. */
74
+ export declare function defaultAppId(name: string): string;
75
+ export declare const APP_ID_RE: RegExp;
76
+ /** The app named `from`, if pstack builds it (Angular/Ionic release target, Flutter flutter-build). */
77
+ export declare function describeBaseApp(tree: Tree, from: string): BaseApp;
78
+ /** kebab, snake, camel, Pascal and Title forms of a kebab-case name (unique, longest first). */
79
+ export declare function nameForms(name: string): string[];
80
+ /**
81
+ * Creates the new app from the base app: copies its files and configuration under the new name,
82
+ * empties its environment values and sets what must differ (port, base href, appId, env set).
83
+ */
84
+ export declare function appFrom(tree: Tree, o: AppFromOptions): AppFromResult;
85
+ /** The report printed after (or, with --dry-run, instead of) creating the app. */
86
+ export declare function appFromReport(r: AppFromResult): string;