@sanity/pkg-utils 7.2.8-canary.1 → 7.2.8
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/_chunks-cjs/build.cjs +4 -4
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +14 -14
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +84 -83
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/init.cjs +11 -11
- package/dist/_chunks-cjs/init.cjs.map +1 -1
- package/dist/_chunks-cjs/{logger.cjs → isRecord.cjs} +4 -4
- package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
- package/dist/_chunks-cjs/watch.cjs +8 -8
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +126 -126
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/build.ts +2 -1
- package/src/node/check.ts +2 -1
- package/src/node/core/config/index.ts +3 -3
- package/src/node/init.ts +1 -1
- package/src/node/resolveBuildContext.ts +1 -1
- package/src/node/tasks/index.ts +0 -4
- package/src/node/tasks/types.ts +1 -1
- package/src/node/watch.ts +2 -1
- package/dist/_chunks-cjs/logger.cjs.map +0 -1
- package/src/node/core/index.ts +0 -7
- package/src/node/tasks/dts/index.ts +0 -4
- package/src/node/tasks/rollup/index.ts +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var path = require("node:path"), rxjs = require("rxjs"), consoleSpy = require("./consoleSpy.cjs"),
|
|
2
|
+
var path = require("node:path"), rxjs = require("rxjs"), consoleSpy = require("./consoleSpy.cjs"), isRecord = require("./isRecord.cjs"), index = require("./index.cjs"), operators = require("rxjs/operators"), globby = require("globby"), chokidar = require("chokidar");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -107,7 +107,7 @@ function watchFiles(patterns) {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
async function watchConfigFiles(options) {
|
|
110
|
-
const { cwd, logger
|
|
110
|
+
const { cwd, logger } = options, initialFiles = await globFiles([
|
|
111
111
|
path__default.default.resolve(cwd, "package.json"),
|
|
112
112
|
path__default.default.resolve(cwd, "package.config.cjs"),
|
|
113
113
|
path__default.default.resolve(cwd, "package.config.js"),
|
|
@@ -119,21 +119,21 @@ async function watchConfigFiles(options) {
|
|
|
119
119
|
path__default.default.resolve(cwd, "package.config.js"),
|
|
120
120
|
path__default.default.resolve(cwd, "package.config.ts")
|
|
121
121
|
]).pipe(
|
|
122
|
-
operators.scan((files, fileEvent) => fileEvent.type === "add" ? files.concat(fileEvent.file) : fileEvent.type === "unlink" ? files.filter((f) => f !== fileEvent.file) : fileEvent.type === "change" ? (
|
|
122
|
+
operators.scan((files, fileEvent) => fileEvent.type === "add" ? files.concat(fileEvent.file) : fileEvent.type === "unlink" ? files.filter((f) => f !== fileEvent.file) : fileEvent.type === "change" ? (logger.log(
|
|
123
123
|
"--------------------------------------------------------------------------------"
|
|
124
|
-
),
|
|
124
|
+
), logger.info(path__default.default.relative(cwd, fileEvent.file), "changed"), logger.log(""), files.slice(0)) : files, initialFiles),
|
|
125
125
|
operators.startWith(initialFiles),
|
|
126
126
|
operators.distinctUntilChanged()
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
async function watch(options) {
|
|
130
|
-
const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger
|
|
131
|
-
(await watchConfigFiles({ cwd, logger
|
|
130
|
+
const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger = isRecord.createLogger();
|
|
131
|
+
(await watchConfigFiles({ cwd, logger })).pipe(
|
|
132
132
|
rxjs.switchMap(async (configFiles) => {
|
|
133
133
|
if (!configFiles.map((f) => path__default.default.relative(cwd, f)).find((f) => f === "package.json"))
|
|
134
134
|
throw new Error("missing package.json");
|
|
135
|
-
const config = await consoleSpy.loadConfig({ cwd }), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger
|
|
136
|
-
return consoleSpy.resolveBuildContext({ config, cwd, logger
|
|
135
|
+
const config = await consoleSpy.loadConfig({ cwd }), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger, strict }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json";
|
|
136
|
+
return consoleSpy.resolveBuildContext({ config, cwd, logger, pkg, strict, tsconfig });
|
|
137
137
|
})
|
|
138
138
|
).subscribe(async (ctx) => {
|
|
139
139
|
const watchTasks = resolveWatchTasks(ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.cjs","sources":["../../src/node/resolveWatchTasks.ts","../../src/node/globFiles.ts","../../src/node/watchFiles.ts","../../src/node/watchConfigFiles.ts","../../src/node/watch.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types'\nimport type {BuildContext} from './core/contexts/buildContext'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths'\nimport type {DtsWatchTask} from './tasks/dts/types'\nimport type {RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks/types'\n\n/** @internal */\nexport function resolveWatchTasks(ctx: BuildContext): WatchTask[] {\n const {pkg, target} = ctx\n const tasks: WatchTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsWatchTask = {\n type: 'watch:dts',\n entries: [],\n }\n\n const rollupTasks: Record<string, RollupWatchTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'watch:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n","import path from 'node:path'\nimport globby from 'globby'\n\nexport function globFiles(patterns: string[]): Promise<string[]> {\n return globby(patterns.map((pattern) => pattern.split(path.sep).join(path.posix.sep)))\n}\n","import * as chokidar from 'chokidar'\nimport type {EventName} from 'chokidar/handler.js'\nimport {Observable} from 'rxjs'\n\nexport interface FileEvent {\n type: EventName\n file: string\n}\n\nexport function watchFiles(patterns: string[]): Observable<FileEvent> {\n return new Observable((observer) => {\n const watcher = chokidar.watch(patterns, {\n ignoreInitial: true,\n })\n\n function handleFileEvent(type: EventName, file: string | Error) {\n if (type === 'error' || file instanceof Error) {\n observer.error(file)\n } else {\n observer.next({type, file})\n }\n }\n\n watcher.on('all', handleFileEvent)\n\n return () => {\n watcher.off('all', handleFileEvent)\n watcher.close()\n }\n })\n}\n","import path from 'node:path'\nimport type {Observable} from 'rxjs'\nimport {distinctUntilChanged, scan, startWith} from 'rxjs/operators'\nimport {globFiles} from './globFiles'\nimport type {Logger} from './logger'\nimport {watchFiles} from './watchFiles'\n\nexport async function watchConfigFiles(options: {\n cwd: string\n logger: Logger\n}): Promise<Observable<string[]>> {\n const {cwd, logger} = options\n\n const initialFiles = await globFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n const fileEvent$ = watchFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n return fileEvent$.pipe(\n scan((files, fileEvent) => {\n if (fileEvent.type === 'add') {\n return files.concat(fileEvent.file)\n }\n\n if (fileEvent.type === 'unlink') {\n return files.filter((f) => f !== fileEvent.file)\n }\n\n if (fileEvent.type === 'change') {\n logger.log(\n '--------------------------------------------------------------------------------',\n )\n logger.info(path.relative(cwd, fileEvent.file), 'changed')\n logger.log('')\n\n return files.slice(0) // trigger update\n }\n\n return files\n }, initialFiles),\n startWith(initialFiles),\n distinctUntilChanged(),\n )\n}\n","import path from 'node:path'\nimport {switchMap} from 'rxjs'\nimport {loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveWatchTasks} from './resolveWatchTasks'\nimport {watchTaskHandlers} from './tasks'\nimport {type TaskHandler, type WatchTask} from './tasks/types'\nimport {watchConfigFiles} from './watchConfigFiles'\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n\n const logger = createLogger()\n\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n const ctx$ = configFiles$.pipe(\n switchMap(async (configFiles) => {\n const files = configFiles.map((f) => path.relative(cwd, f))\n\n const packageJsonPath = files.find((f) => f === 'package.json')\n\n if (!packageJsonPath) {\n throw new Error('missing package.json')\n }\n\n const config = await loadConfig({cwd})\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n }),\n )\n\n ctx$.subscribe(async (ctx) => {\n const watchTasks = resolveWatchTasks(ctx)\n\n for (const task of watchTasks) {\n const handler = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>\n const result$ = handler.exec(ctx, task)\n\n result$.subscribe({\n error: (err) => {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n },\n next: (result) => {\n handler.complete(ctx, task, result)\n },\n complete: () => {\n ctx.logger.success(handler.name(ctx, task))\n ctx.logger.log()\n },\n })\n }\n })\n}\n"],"names":["exports","path","getTargetPaths","globby","Observable","chokidar","logger","scan","startWith","distinctUntilChanged","createLogger","switchMap","loadConfig","loadPkgWithReporting","resolveBuildContext","watchTaskHandlers"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQO,SAAS,kBAAkB,KAAgC;AAChE,QAAM,EAAC,KAAK,OAAM,IAAI,KAChB,QAAqB,CAErB,GAAAA,WAAU,OAAO,QAAQ,IAA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AO,GAE/B;AAAA,IACxBK,KAAA,UAAU,OAAO,gBAAgB;AAK/B,UAAI,CAJU,YAAY,IAAI,CAAC,MAAMV,cAAK,QAAA,SAAS,KAAK,CAAC,CAAC,EAE5B,KAAK,CAAC,MAAM,MAAM,cAAc;AAGtD,cAAA,IAAI,MAAM,sBAAsB;AAGxC,YAAM,SAAS,MAAMW,sBAAW,EAAC,IAAG,CAAC,GAC/B,MAAM,MAAMC,gCAAqB,EAAC,KAAKP,QAAAA,UAAQ,QAAO,GACtD,WAAW,kBAAkB,QAAQ,YAAY;AAEhD,aAAAQ,WAAA,oBAAoB,EAAC,QAAQ,KAAA,QAAKR,UAAQ,KAAK,QAAQ,UAAS;AAAA,IACxE,CAAA;AAAA,EAAA,EAGE,UAAU,OAAO,QAAQ;AACtB,UAAA,aAAa,kBAAkB,GAAG;AAExC,eAAW,QAAQ,YAAY;AACvB,YAAA,UAAUS,MAAAA,kBAAkB,KAAK,IAAI;AAC3B,cAAQ,KAAK,KAAK,IAAI,EAE9B,UAAU;AAAA,QAChB,OAAO,CAAC,QAAQ;AACV,cAAA,OAAO,MAAM,GAAG,GACpB,IAAI,OAAO,IAAI,GAEf,QAAQ,KAAK,CAAC;AAAA,QAChB;AAAA,QACA,MAAM,CAAC,WAAW;AACR,kBAAA,SAAS,KAAK,MAAM,MAAM;AAAA,QACpC;AAAA,QACA,UAAU,MAAM;AACV,cAAA,OAAO,QAAQ,QAAQ,KAAK,KAAK,IAAI,CAAC,GAC1C,IAAI,OAAO,IAAI;AAAA,QAAA;AAAA,MACjB,CACD;AAAA,IAAA;AAAA,EACH,CACD;AACH;;"}
|
|
1
|
+
{"version":3,"file":"watch.cjs","sources":["../../src/node/resolveWatchTasks.ts","../../src/node/globFiles.ts","../../src/node/watchFiles.ts","../../src/node/watchConfigFiles.ts","../../src/node/watch.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types'\nimport type {BuildContext} from './core/contexts/buildContext'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths'\nimport type {DtsWatchTask} from './tasks/dts/types'\nimport type {RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks/types'\n\n/** @internal */\nexport function resolveWatchTasks(ctx: BuildContext): WatchTask[] {\n const {pkg, target} = ctx\n const tasks: WatchTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsWatchTask = {\n type: 'watch:dts',\n entries: [],\n }\n\n const rollupTasks: Record<string, RollupWatchTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'watch:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n","import path from 'node:path'\nimport globby from 'globby'\n\nexport function globFiles(patterns: string[]): Promise<string[]> {\n return globby(patterns.map((pattern) => pattern.split(path.sep).join(path.posix.sep)))\n}\n","import * as chokidar from 'chokidar'\nimport type {EventName} from 'chokidar/handler.js'\nimport {Observable} from 'rxjs'\n\nexport interface FileEvent {\n type: EventName\n file: string\n}\n\nexport function watchFiles(patterns: string[]): Observable<FileEvent> {\n return new Observable((observer) => {\n const watcher = chokidar.watch(patterns, {\n ignoreInitial: true,\n })\n\n function handleFileEvent(type: EventName, file: string | Error) {\n if (type === 'error' || file instanceof Error) {\n observer.error(file)\n } else {\n observer.next({type, file})\n }\n }\n\n watcher.on('all', handleFileEvent)\n\n return () => {\n watcher.off('all', handleFileEvent)\n watcher.close()\n }\n })\n}\n","import path from 'node:path'\nimport type {Observable} from 'rxjs'\nimport {distinctUntilChanged, scan, startWith} from 'rxjs/operators'\nimport {globFiles} from './globFiles'\nimport type {Logger} from './logger'\nimport {watchFiles} from './watchFiles'\n\nexport async function watchConfigFiles(options: {\n cwd: string\n logger: Logger\n}): Promise<Observable<string[]>> {\n const {cwd, logger} = options\n\n const initialFiles = await globFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n const fileEvent$ = watchFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n return fileEvent$.pipe(\n scan((files, fileEvent) => {\n if (fileEvent.type === 'add') {\n return files.concat(fileEvent.file)\n }\n\n if (fileEvent.type === 'unlink') {\n return files.filter((f) => f !== fileEvent.file)\n }\n\n if (fileEvent.type === 'change') {\n logger.log(\n '--------------------------------------------------------------------------------',\n )\n logger.info(path.relative(cwd, fileEvent.file), 'changed')\n logger.log('')\n\n return files.slice(0) // trigger update\n }\n\n return files\n }, initialFiles),\n startWith(initialFiles),\n distinctUntilChanged(),\n )\n}\n","import path from 'node:path'\nimport {switchMap} from 'rxjs'\nimport {loadConfig} from './core/config/loadConfig'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveWatchTasks} from './resolveWatchTasks'\nimport {watchTaskHandlers} from './tasks'\nimport {type TaskHandler, type WatchTask} from './tasks/types'\nimport {watchConfigFiles} from './watchConfigFiles'\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n\n const logger = createLogger()\n\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n const ctx$ = configFiles$.pipe(\n switchMap(async (configFiles) => {\n const files = configFiles.map((f) => path.relative(cwd, f))\n\n const packageJsonPath = files.find((f) => f === 'package.json')\n\n if (!packageJsonPath) {\n throw new Error('missing package.json')\n }\n\n const config = await loadConfig({cwd})\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n }),\n )\n\n ctx$.subscribe(async (ctx) => {\n const watchTasks = resolveWatchTasks(ctx)\n\n for (const task of watchTasks) {\n const handler = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>\n const result$ = handler.exec(ctx, task)\n\n result$.subscribe({\n error: (err) => {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n },\n next: (result) => {\n handler.complete(ctx, task, result)\n },\n complete: () => {\n ctx.logger.success(handler.name(ctx, task))\n ctx.logger.log()\n },\n })\n }\n })\n}\n"],"names":["exports","path","getTargetPaths","globby","Observable","chokidar","scan","startWith","distinctUntilChanged","createLogger","switchMap","loadConfig","loadPkgWithReporting","resolveBuildContext","watchTaskHandlers"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQO,SAAS,kBAAkB,KAAgC;AAChE,QAAM,EAAC,KAAK,OAAM,IAAI,KAChB,QAAqB,CAErB,GAAAA,WAAU,OAAO,QAAQ,IAAI,WAAW,CAAA,CAAE,EAAE;AAAA,IAChD,CAAC,CAAC,OAAO,GAAG,OAAO,EAAC,OAAO,GAAG,IAAG;AAAA,KAG7B,UAAwB;AAAA,IAC5B,MAAM;AAAA,IACN,SAAS,CAAA;AAAA,EACX,GAEM,cAA+C,CAAC;AAE7C,WAAA,mBAAmB,QAAmB,SAAqB,OAAwB;AAC1F,UAAM,UAAU,GAAG,MAAM,IAAI,OAAO;AAEhC,gBAAY,OAAO,IACrB,YAAY,OAAO,EAAE,QAAQ,KAAK,KAAK,IAEvC,YAAY,OAAO,IAAI;AAAA,MACrB,MAAM;AAAA,MACN;AAAA,MACA,SAAS,CAAC,KAAK;AAAA,MACf;AAAA,MACA;AAAA,MACA,QAAQ,OAAO,OAAO;AAAA,IACxB;AAAA,EAAA;AAKJ,aAAW,OAAOA,UAAS;AACzB,UAAM,WAAWC,cAAAA,QAAK,KAAK,IAAI,MAAM,IAAI,KAAK;AAE1C,QAAI,QAAQ,SAAS,KAAK,KAC5B,QAAQ,QAAQ,KAAK;AAAA,MACnB;AAAA,MACA,YAAY,IAAI;AAAA,MAChB,YAA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AAQ,KAAK,CAAC;AAAA,QAChB;AAAA,QACA,MAAM,CAAC,WAAW;AACR,kBAAA,SAAS,KAAK,MAAM,MAAM;AAAA,QACpC;AAAA,QACA,UAAU,MAAM;AACV,cAAA,OAAO,QAAQ,QAAQ,KAAK,KAAK,IAAI,CAAC,GAC1C,IAAI,OAAO,IAAI;AAAA,QAAA;AAAA,MACjB,CACD;AAAA,IAAA;AAAA,EACH,CACD;AACH;;"}
|
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var cac = require("cac"), version = "7.2.8
|
|
2
|
+
var cac = require("cac"), version = "7.2.8";
|
|
3
3
|
const cli = cac.cac();
|
|
4
4
|
cli.command("", "Check").alias("check").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async (options) => {
|
|
5
5
|
const { checkAction } = await Promise.resolve().then(function() {
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var build = require("./_chunks-cjs/build.cjs"), check = require("./_chunks-cjs/check.cjs"), consoleSpy = require("./_chunks-cjs/consoleSpy.cjs"),
|
|
3
|
+
var build = require("./_chunks-cjs/build.cjs"), check = require("./_chunks-cjs/check.cjs"), consoleSpy = require("./_chunks-cjs/consoleSpy.cjs"), isRecord = require("./_chunks-cjs/isRecord.cjs"), init = require("./_chunks-cjs/init.cjs"), index = require("./_chunks-cjs/index.cjs"), watch = require("./_chunks-cjs/watch.cjs");
|
|
4
4
|
function defineConfig(configOptions) {
|
|
5
5
|
return configOptions;
|
|
6
6
|
}
|
|
@@ -18,8 +18,8 @@ exports.pkgExtMap = consoleSpy.pkgExtMap;
|
|
|
18
18
|
exports.resolveConfigProperty = consoleSpy.resolveConfigProperty;
|
|
19
19
|
exports.strictOptions = consoleSpy.strictOptions;
|
|
20
20
|
exports.toggle = consoleSpy.toggle;
|
|
21
|
-
exports.createLogger =
|
|
22
|
-
exports.isRecord =
|
|
21
|
+
exports.createLogger = isRecord.createLogger;
|
|
22
|
+
exports.isRecord = isRecord.isRecord;
|
|
23
23
|
exports.createFromTemplate = init.createFromTemplate;
|
|
24
24
|
exports.defineTemplateOption = init.defineTemplateOption;
|
|
25
25
|
exports.init = init.init;
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { register } from "esbuild-register/dist/node";
|
|
|
5
5
|
import pkgUp from "pkg-up";
|
|
6
6
|
import findConfig from "find-config";
|
|
7
7
|
import { statSync, existsSync } from "node:fs";
|
|
8
|
-
import { z, ZodError } from "zod";
|
|
9
8
|
import chalk from "chalk";
|
|
10
|
-
import
|
|
9
|
+
import { z, ZodError } from "zod";
|
|
10
|
+
import fs, { readFile, writeFile, readdir, lstat } from "node:fs/promises";
|
|
11
11
|
import browserslist from "browserslist";
|
|
12
12
|
import config$1 from "@sanity/browserslist-config";
|
|
13
13
|
import ts from "typescript";
|
|
@@ -42,9 +42,6 @@ import { outdent } from "outdent";
|
|
|
42
42
|
import { scan, startWith, distinctUntilChanged } from "rxjs/operators";
|
|
43
43
|
import globby from "globby";
|
|
44
44
|
import * as chokidar from "chokidar";
|
|
45
|
-
function defineConfig(configOptions) {
|
|
46
|
-
return configOptions;
|
|
47
|
-
}
|
|
48
45
|
function fileExists(filePath) {
|
|
49
46
|
try {
|
|
50
47
|
return statSync(filePath), !0;
|
|
@@ -78,12 +75,13 @@ async function loadConfig(options) {
|
|
|
78
75
|
} } : register(esbuildOptions), mod = require(configFile);
|
|
79
76
|
return unregister(), mod?.default || mod || void 0;
|
|
80
77
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
78
|
+
function assertLast(a, arr) {
|
|
79
|
+
const aIdx = arr.indexOf(a);
|
|
80
|
+
return aIdx === -1 ? !0 : aIdx === arr.length - 1;
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
82
|
+
function assertOrder(a, b, arr) {
|
|
83
|
+
const aIdx = arr.indexOf(a), bIdx = arr.indexOf(b);
|
|
84
|
+
return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
|
|
87
85
|
}
|
|
88
86
|
const pkgSchema = z.object({
|
|
89
87
|
type: z.optional(z.enum(["commonjs", "module"])),
|
|
@@ -158,14 +156,6 @@ async function loadPkg(options) {
|
|
|
158
156
|
const buf = await fs.readFile(pkgPath), raw = JSON.parse(buf.toString());
|
|
159
157
|
return validatePkg(raw), raw;
|
|
160
158
|
}
|
|
161
|
-
function assertLast(a, arr) {
|
|
162
|
-
const aIdx = arr.indexOf(a);
|
|
163
|
-
return aIdx === -1 ? !0 : aIdx === arr.length - 1;
|
|
164
|
-
}
|
|
165
|
-
function assertOrder(a, b, arr) {
|
|
166
|
-
const aIdx = arr.indexOf(a), bIdx = arr.indexOf(b);
|
|
167
|
-
return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
|
|
168
|
-
}
|
|
169
159
|
async function loadPkgWithReporting(options) {
|
|
170
160
|
const { cwd, logger, strict } = options;
|
|
171
161
|
try {
|
|
@@ -224,6 +214,74 @@ async function loadPkgWithReporting(options) {
|
|
|
224
214
|
function formatPath(segments) {
|
|
225
215
|
return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
|
|
226
216
|
}
|
|
217
|
+
function createLogger() {
|
|
218
|
+
return {
|
|
219
|
+
log: (...args) => {
|
|
220
|
+
console.log(...args);
|
|
221
|
+
},
|
|
222
|
+
info: (...args) => {
|
|
223
|
+
console.log(chalk.blue("[info]"), ...args);
|
|
224
|
+
},
|
|
225
|
+
warn: (...args) => {
|
|
226
|
+
console.log(chalk.yellow("[warning]"), ...args);
|
|
227
|
+
},
|
|
228
|
+
error: (...args) => {
|
|
229
|
+
console.log(chalk.red("[error]"), ...args);
|
|
230
|
+
},
|
|
231
|
+
success: (...args) => {
|
|
232
|
+
console.log(chalk.green("[success]"), ...args);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function browserslistToEsbuild(browserslistConfig, options = {}) {
|
|
237
|
+
if (!browserslistConfig) {
|
|
238
|
+
const path2 = process.cwd();
|
|
239
|
+
browserslistConfig = browserslist.loadConfig({ path: path2, ...options });
|
|
240
|
+
}
|
|
241
|
+
const SUPPORTED_ESBUILD_TARGETS = [
|
|
242
|
+
"es",
|
|
243
|
+
"chrome",
|
|
244
|
+
"edge",
|
|
245
|
+
"firefox",
|
|
246
|
+
"ios",
|
|
247
|
+
"node",
|
|
248
|
+
"safari",
|
|
249
|
+
"opera",
|
|
250
|
+
"ie"
|
|
251
|
+
], UNSUPPORTED = ["android 4"], replaces = {
|
|
252
|
+
ios_saf: "ios",
|
|
253
|
+
android: "chrome"
|
|
254
|
+
}, separator = " ";
|
|
255
|
+
return browserslist(browserslistConfig, options).filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u))).map((b) => b === "safari TP" ? browserslist("last 1 safari version")[0] : b).map((b) => b.split(separator)).map((b) => (replaces[b[0]] && (b[0] = replaces[b[0]]), b)).map((b) => (b[1].includes("-") && (b[1] = b[1].slice(0, b[1].indexOf("-"))), b)).map((b) => (b[1].endsWith(".0") && (b[1] = b[1].slice(0, -2)), b)).filter((b) => /^\d+(\.\d+)*$/.test(b[1])).filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0])).reduce((acc, b) => {
|
|
256
|
+
const existingIndex = acc.findIndex((br) => br[0] === b[0]);
|
|
257
|
+
return existingIndex !== -1 ? acc[existingIndex][1] = b[1] : acc.push(b), acc;
|
|
258
|
+
}, []).map((b) => b.join(""));
|
|
259
|
+
}
|
|
260
|
+
function resolveConfigProperty(prop, initialValue) {
|
|
261
|
+
return prop ? typeof prop == "function" ? prop(initialValue) : prop : initialValue;
|
|
262
|
+
}
|
|
263
|
+
const DEFAULT_BROWSERSLIST_QUERY = config$1;
|
|
264
|
+
function pathContains(containerPath, itemPath) {
|
|
265
|
+
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
266
|
+
}
|
|
267
|
+
function findCommonDirPath(filePaths) {
|
|
268
|
+
let ret;
|
|
269
|
+
for (const filePath of filePaths) {
|
|
270
|
+
let dirPath = path.dirname(filePath);
|
|
271
|
+
if (!ret) {
|
|
272
|
+
ret = dirPath;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
for (; dirPath !== ret && (dirPath = path.dirname(dirPath), dirPath !== ret); ) {
|
|
276
|
+
if (pathContains(dirPath, ret)) {
|
|
277
|
+
ret = dirPath;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
if (dirPath === ".") return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return ret;
|
|
284
|
+
}
|
|
227
285
|
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", defaultEnding = ".js", mjsEnding = ".mjs", cjsEnding = ".cjs", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
228
286
|
function getTargetPaths(_type, expOrBundle) {
|
|
229
287
|
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
@@ -243,6 +301,9 @@ function getTargetPaths(_type, expOrBundle) {
|
|
|
243
301
|
function isPkgExport$1(exp) {
|
|
244
302
|
return exp?.browser || exp?.node || exp?.default;
|
|
245
303
|
}
|
|
304
|
+
function isRecord(value) {
|
|
305
|
+
return !!value && !Array.isArray(value) && typeof value == "object";
|
|
306
|
+
}
|
|
246
307
|
const pkgExtMap = {
|
|
247
308
|
// pkg.type: "commonjs"
|
|
248
309
|
commonjs: {
|
|
@@ -371,50 +432,6 @@ function parseExports(options) {
|
|
|
371
432
|
function isPkgExport(value) {
|
|
372
433
|
return isRecord(value) && "source" in value && typeof value.source == "string";
|
|
373
434
|
}
|
|
374
|
-
const promptsTypes = {
|
|
375
|
-
string: "text"
|
|
376
|
-
};
|
|
377
|
-
async function createFromTemplate(options) {
|
|
378
|
-
const { cwd, logger, packagePath, template: templateOrResolver } = options, template = typeof templateOrResolver == "function" ? await templateOrResolver({ cwd, logger, packagePath }) : templateOrResolver;
|
|
379
|
-
logger.log("create new package at", relative(cwd, packagePath));
|
|
380
|
-
const templateOptions = {};
|
|
381
|
-
for (const templateOption of template.options) {
|
|
382
|
-
const templateValidate = templateOption.validate, res = await prompts(
|
|
383
|
-
{
|
|
384
|
-
type: promptsTypes[templateOption.type],
|
|
385
|
-
name: templateOption.name,
|
|
386
|
-
message: templateOption.description,
|
|
387
|
-
validate: templateValidate ? (prev) => templateValidate(prev) : void 0,
|
|
388
|
-
initial: typeof templateOption.initial == "function" ? templateOption.initial(templateOptions) : templateOption.initial
|
|
389
|
-
},
|
|
390
|
-
{ onCancel: () => process.exit(0) }
|
|
391
|
-
);
|
|
392
|
-
templateOptions[templateOption.name] = templateOption.parse ? templateOption.parse(res[templateOption.name]) : res[templateOption.name];
|
|
393
|
-
}
|
|
394
|
-
const features = {};
|
|
395
|
-
for (const templateFeature of template.features) {
|
|
396
|
-
const res = templateFeature.optional ? await prompts(
|
|
397
|
-
{
|
|
398
|
-
type: "confirm",
|
|
399
|
-
name: "confirm",
|
|
400
|
-
message: `use ${templateFeature.name}?`,
|
|
401
|
-
initial: templateFeature.initial
|
|
402
|
-
},
|
|
403
|
-
{ onCancel: () => process.exit(0) }
|
|
404
|
-
) : void 0;
|
|
405
|
-
features[templateFeature.name] = res?.confirm || !templateFeature.optional;
|
|
406
|
-
}
|
|
407
|
-
const files = await template.getFiles(templateOptions, features);
|
|
408
|
-
files.sort((a, b) => a.name.localeCompare(b.name));
|
|
409
|
-
for (const file of files) {
|
|
410
|
-
const filePath = resolve(packagePath, file.name);
|
|
411
|
-
await mkdirp(dirname(filePath)), await writeFile(filePath, file.contents.trim() + `
|
|
412
|
-
`), logger.success(`wrote ${relative(cwd, filePath)}`);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
function defineTemplateOption(option) {
|
|
416
|
-
return option;
|
|
417
|
-
}
|
|
418
435
|
async function loadTSConfig(options) {
|
|
419
436
|
const { cwd, tsconfigPath } = options, configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
420
437
|
if (!configPath)
|
|
@@ -422,70 +439,6 @@ async function loadTSConfig(options) {
|
|
|
422
439
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
423
440
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
424
441
|
}
|
|
425
|
-
function createLogger() {
|
|
426
|
-
return {
|
|
427
|
-
log: (...args) => {
|
|
428
|
-
console.log(...args);
|
|
429
|
-
},
|
|
430
|
-
info: (...args) => {
|
|
431
|
-
console.log(chalk.blue("[info]"), ...args);
|
|
432
|
-
},
|
|
433
|
-
warn: (...args) => {
|
|
434
|
-
console.log(chalk.yellow("[warning]"), ...args);
|
|
435
|
-
},
|
|
436
|
-
error: (...args) => {
|
|
437
|
-
console.log(chalk.red("[error]"), ...args);
|
|
438
|
-
},
|
|
439
|
-
success: (...args) => {
|
|
440
|
-
console.log(chalk.green("[success]"), ...args);
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
function browserslistToEsbuild(browserslistConfig, options = {}) {
|
|
445
|
-
if (!browserslistConfig) {
|
|
446
|
-
const path2 = process.cwd();
|
|
447
|
-
browserslistConfig = browserslist.loadConfig({ path: path2, ...options });
|
|
448
|
-
}
|
|
449
|
-
const SUPPORTED_ESBUILD_TARGETS = [
|
|
450
|
-
"es",
|
|
451
|
-
"chrome",
|
|
452
|
-
"edge",
|
|
453
|
-
"firefox",
|
|
454
|
-
"ios",
|
|
455
|
-
"node",
|
|
456
|
-
"safari",
|
|
457
|
-
"opera",
|
|
458
|
-
"ie"
|
|
459
|
-
], UNSUPPORTED = ["android 4"], replaces = {
|
|
460
|
-
ios_saf: "ios",
|
|
461
|
-
android: "chrome"
|
|
462
|
-
}, separator = " ";
|
|
463
|
-
return browserslist(browserslistConfig, options).filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u))).map((b) => b === "safari TP" ? browserslist("last 1 safari version")[0] : b).map((b) => b.split(separator)).map((b) => (replaces[b[0]] && (b[0] = replaces[b[0]]), b)).map((b) => (b[1].includes("-") && (b[1] = b[1].slice(0, b[1].indexOf("-"))), b)).map((b) => (b[1].endsWith(".0") && (b[1] = b[1].slice(0, -2)), b)).filter((b) => /^\d+(\.\d+)*$/.test(b[1])).filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0])).reduce((acc, b) => {
|
|
464
|
-
const existingIndex = acc.findIndex((br) => br[0] === b[0]);
|
|
465
|
-
return existingIndex !== -1 ? acc[existingIndex][1] = b[1] : acc.push(b), acc;
|
|
466
|
-
}, []).map((b) => b.join(""));
|
|
467
|
-
}
|
|
468
|
-
function pathContains(containerPath, itemPath) {
|
|
469
|
-
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
470
|
-
}
|
|
471
|
-
function findCommonDirPath(filePaths) {
|
|
472
|
-
let ret;
|
|
473
|
-
for (const filePath of filePaths) {
|
|
474
|
-
let dirPath = path.dirname(filePath);
|
|
475
|
-
if (!ret) {
|
|
476
|
-
ret = dirPath;
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
|
-
for (; dirPath !== ret && (dirPath = path.dirname(dirPath), dirPath !== ret); ) {
|
|
480
|
-
if (pathContains(dirPath, ret)) {
|
|
481
|
-
ret = dirPath;
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
if (dirPath === ".") return;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return ret;
|
|
488
|
-
}
|
|
489
442
|
function resolveBrowserTarget(versions) {
|
|
490
443
|
const target = versions.filter(
|
|
491
444
|
(version) => version.startsWith("chrome") || version.startsWith("edge") || version.startsWith("firefox") || version.startsWith("ios") || version.startsWith("safari") || version.startsWith("opera")
|
|
@@ -1592,6 +1545,53 @@ function isEsbuildFailure(err) {
|
|
|
1592
1545
|
function isEsbuildMessage(msg) {
|
|
1593
1546
|
return typeof msg == "object" && msg !== null && "text" in msg && typeof msg.text == "string" && "location" in msg && (msg.location === null || typeof msg.location == "object");
|
|
1594
1547
|
}
|
|
1548
|
+
function defineConfig(configOptions) {
|
|
1549
|
+
return configOptions;
|
|
1550
|
+
}
|
|
1551
|
+
const promptsTypes = {
|
|
1552
|
+
string: "text"
|
|
1553
|
+
};
|
|
1554
|
+
async function createFromTemplate(options) {
|
|
1555
|
+
const { cwd, logger, packagePath, template: templateOrResolver } = options, template = typeof templateOrResolver == "function" ? await templateOrResolver({ cwd, logger, packagePath }) : templateOrResolver;
|
|
1556
|
+
logger.log("create new package at", relative(cwd, packagePath));
|
|
1557
|
+
const templateOptions = {};
|
|
1558
|
+
for (const templateOption of template.options) {
|
|
1559
|
+
const templateValidate = templateOption.validate, res = await prompts(
|
|
1560
|
+
{
|
|
1561
|
+
type: promptsTypes[templateOption.type],
|
|
1562
|
+
name: templateOption.name,
|
|
1563
|
+
message: templateOption.description,
|
|
1564
|
+
validate: templateValidate ? (prev) => templateValidate(prev) : void 0,
|
|
1565
|
+
initial: typeof templateOption.initial == "function" ? templateOption.initial(templateOptions) : templateOption.initial
|
|
1566
|
+
},
|
|
1567
|
+
{ onCancel: () => process.exit(0) }
|
|
1568
|
+
);
|
|
1569
|
+
templateOptions[templateOption.name] = templateOption.parse ? templateOption.parse(res[templateOption.name]) : res[templateOption.name];
|
|
1570
|
+
}
|
|
1571
|
+
const features = {};
|
|
1572
|
+
for (const templateFeature of template.features) {
|
|
1573
|
+
const res = templateFeature.optional ? await prompts(
|
|
1574
|
+
{
|
|
1575
|
+
type: "confirm",
|
|
1576
|
+
name: "confirm",
|
|
1577
|
+
message: `use ${templateFeature.name}?`,
|
|
1578
|
+
initial: templateFeature.initial
|
|
1579
|
+
},
|
|
1580
|
+
{ onCancel: () => process.exit(0) }
|
|
1581
|
+
) : void 0;
|
|
1582
|
+
features[templateFeature.name] = res?.confirm || !templateFeature.optional;
|
|
1583
|
+
}
|
|
1584
|
+
const files = await template.getFiles(templateOptions, features);
|
|
1585
|
+
files.sort((a, b) => a.name.localeCompare(b.name));
|
|
1586
|
+
for (const file of files) {
|
|
1587
|
+
const filePath = resolve(packagePath, file.name);
|
|
1588
|
+
await mkdirp(dirname(filePath)), await writeFile(filePath, file.contents.trim() + `
|
|
1589
|
+
`), logger.success(`wrote ${relative(cwd, filePath)}`);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
function defineTemplateOption(option) {
|
|
1593
|
+
return option;
|
|
1594
|
+
}
|
|
1595
1595
|
async function isEmptyDirectory(dirPath) {
|
|
1596
1596
|
return (await readdir(dirPath)).length === 0;
|
|
1597
1597
|
}
|