@amagaki/amagaki 1.12.1 → 2.1.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.
Files changed (69) hide show
  1. package/dist/src/builder.d.ts +15 -17
  2. package/dist/src/builder.js +117 -20
  3. package/dist/src/cache.js +0 -1
  4. package/dist/src/cli.d.ts +1 -1
  5. package/dist/src/cli.js +16 -3
  6. package/dist/src/collection.d.ts +1 -1
  7. package/dist/src/collection.js +0 -1
  8. package/dist/src/commands/build.js +3 -27
  9. package/dist/src/commands/export.d.ts +8 -0
  10. package/dist/src/commands/export.js +21 -0
  11. package/dist/src/commands/global.d.ts +2 -0
  12. package/dist/src/commands/global.js +14 -1
  13. package/dist/src/commands/serve.js +2 -26
  14. package/dist/src/document.d.ts +1 -1
  15. package/dist/src/document.js +0 -1
  16. package/dist/src/environment.js +0 -1
  17. package/dist/src/gitData.d.ts +15 -0
  18. package/dist/src/gitData.js +67 -0
  19. package/dist/src/index.js +0 -1
  20. package/dist/src/locale.js +0 -1
  21. package/dist/src/plugins/builder.js +0 -1
  22. package/dist/src/plugins/index.js +0 -1
  23. package/dist/src/plugins/nunjucks.js +4 -2
  24. package/dist/src/plugins/router.js +0 -1
  25. package/dist/src/plugins/server.js +0 -1
  26. package/dist/src/plugins/yaml.js +0 -1
  27. package/dist/src/plugins.js +0 -1
  28. package/dist/src/pod.d.ts +2 -2
  29. package/dist/src/pod.js +0 -1
  30. package/dist/src/profile.js +0 -1
  31. package/dist/src/router.d.ts +26 -5
  32. package/dist/src/router.js +44 -3
  33. package/dist/src/server.js +0 -1
  34. package/dist/src/staticFile.js +0 -1
  35. package/dist/src/string.js +0 -1
  36. package/dist/src/templateEngine.js +0 -1
  37. package/dist/src/url.d.ts +3 -3
  38. package/dist/src/url.js +0 -1
  39. package/dist/src/utils.d.ts +4 -4
  40. package/dist/src/utils.js +0 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +5 -4
  43. package/dist/src/builder.js.map +0 -1
  44. package/dist/src/cache.js.map +0 -1
  45. package/dist/src/cli.js.map +0 -1
  46. package/dist/src/collection.js.map +0 -1
  47. package/dist/src/commands/build.js.map +0 -1
  48. package/dist/src/commands/global.js.map +0 -1
  49. package/dist/src/commands/serve.js.map +0 -1
  50. package/dist/src/document.js.map +0 -1
  51. package/dist/src/environment.js.map +0 -1
  52. package/dist/src/index.js.map +0 -1
  53. package/dist/src/locale.js.map +0 -1
  54. package/dist/src/plugins/builder.js.map +0 -1
  55. package/dist/src/plugins/index.js.map +0 -1
  56. package/dist/src/plugins/nunjucks.js.map +0 -1
  57. package/dist/src/plugins/router.js.map +0 -1
  58. package/dist/src/plugins/server.js.map +0 -1
  59. package/dist/src/plugins/yaml.js.map +0 -1
  60. package/dist/src/plugins.js.map +0 -1
  61. package/dist/src/pod.js.map +0 -1
  62. package/dist/src/profile.js.map +0 -1
  63. package/dist/src/router.js.map +0 -1
  64. package/dist/src/server.js.map +0 -1
  65. package/dist/src/staticFile.js.map +0 -1
  66. package/dist/src/string.js.map +0 -1
  67. package/dist/src/templateEngine.js.map +0 -1
  68. package/dist/src/url.js.map +0 -1
  69. package/dist/src/utils.js.map +0 -1
@@ -1,23 +1,15 @@
1
1
  import * as cliProgress from 'cli-progress';
2
+ import { GitCommit } from './gitData';
2
3
  import { Pod } from './pod';
3
4
  import { TranslationString } from './string';
4
5
  interface PodPathSha {
5
6
  path: string;
6
7
  sha: string;
7
8
  }
8
- interface CommitAuthor {
9
- name: string;
10
- email: string;
11
- }
12
- interface Commit {
13
- sha: string;
14
- author: CommitAuthor;
15
- message: string;
16
- }
17
9
  export interface BuildManifest {
18
10
  branch: string | null;
19
11
  built: string;
20
- commit: Commit | null;
12
+ commit: GitCommit | null;
21
13
  files: Array<PodPathSha>;
22
14
  }
23
15
  export interface BuildDiffPaths {
@@ -42,14 +34,19 @@ export interface BuildResult {
42
34
  manifest: BuildManifest;
43
35
  diff: BuildDiffPaths;
44
36
  }
45
- export interface ExportOptions {
37
+ export interface BuildOptions {
46
38
  patterns?: string[];
47
39
  writeLocales?: Boolean;
48
40
  }
41
+ export interface ExportOptions {
42
+ buildDir?: string;
43
+ exportDir: string;
44
+ exportControlDir?: string;
45
+ }
49
46
  export declare class Builder {
50
47
  benchmarkPodPath: string;
51
48
  pod: Pod;
52
- manifestPodPath: string;
49
+ manifestPath: string;
53
50
  metricsPodPath: string;
54
51
  missingTranslationsPodPath: string;
55
52
  outputDirectoryPodPath: string;
@@ -69,12 +66,13 @@ export declare class Builder {
69
66
  moveFileAsync(beforePath: string, afterPath: string): Promise<void>;
70
67
  writeFileAsync(outputPath: string, content: string): Promise<void>;
71
68
  deleteDirectoryRecursive(path: string): void;
72
- deleteOutputFiles(paths: Array<string>): void;
73
- getExistingManifest(): BuildManifest | null;
74
- cleanOutputUsingManifests(existingManifest: BuildManifest | null, newManifest: BuildManifest, options?: ExportOptions): BuildDiffPaths;
69
+ deleteOutputFiles(paths: Array<string>, outputRootDir: string): void;
70
+ getManifest(filePath: string): BuildManifest | null;
71
+ cleanOutputUsingManifests(existingManifest: BuildManifest | null, newManifest: BuildManifest, options?: BuildOptions): BuildDiffPaths;
75
72
  static createProgressBar(label: string): cliProgress.SingleBar;
76
- export(options?: ExportOptions): Promise<BuildResult>;
77
- logResult(buildDiff: BuildDiffPaths, buildMetrics: BuildMetrics, options?: ExportOptions): void;
73
+ export(options: ExportOptions): Promise<BuildDiffPaths>;
74
+ build(options?: BuildOptions): Promise<BuildResult>;
75
+ logResult(buildDiff: BuildDiffPaths, buildMetrics: BuildMetrics, options?: BuildOptions): void;
78
76
  writeLocales(localesToMissingTranslations: LocalesToMissingTranslations): Promise<void>;
79
77
  exportBenchmark(): Promise<void>;
80
78
  }
@@ -31,17 +31,15 @@ const fsPath = __importStar(require("path"));
31
31
  const stream = __importStar(require("stream"));
32
32
  const util = __importStar(require("util"));
33
33
  const utils = __importStar(require("./utils"));
34
+ const gitData_1 = require("./gitData");
34
35
  const chalk_1 = __importDefault(require("chalk"));
35
36
  const minimatch_1 = __importDefault(require("minimatch"));
36
37
  class Builder {
37
38
  constructor(pod) {
38
39
  this.pod = pod;
39
- // TODO: Right now, this is limited to a sub-directory within the pod. We
40
- // want that to be the default, but we should also permit building to
41
- // directories external to the pod.
42
40
  this.outputDirectoryPodPath = Builder.DefaultOutputDirectory;
43
41
  this.controlDirectoryAbsolutePath = this.pod.getAbsoluteFilePath(fsPath.join(this.outputDirectoryPodPath, '.amagaki'));
44
- this.manifestPodPath = fsPath.join(this.outputDirectoryPodPath, '.amagaki', 'manifest.json');
42
+ this.manifestPath = this.pod.getAbsoluteFilePath(fsPath.join(this.outputDirectoryPodPath, '.amagaki', 'manifest.json'));
45
43
  this.metricsPodPath = fsPath.join(this.outputDirectoryPodPath, '.amagaki', 'metrics.json');
46
44
  this.benchmarkPodPath = fsPath.join(this.outputDirectoryPodPath, '.amagaki', 'benchmark.txt');
47
45
  this.missingTranslationsPodPath = fsPath.join(this.outputDirectoryPodPath, '.amagaki', 'locales');
@@ -85,7 +83,9 @@ class Builder {
85
83
  }
86
84
  moveFileAsync(beforePath, afterPath) {
87
85
  Builder.ensureDirectoryExists(afterPath);
88
- return fs.promises.rename(beforePath, afterPath).catch((err) => {
86
+ return fs.promises
87
+ .rename(beforePath, afterPath)
88
+ .catch((err) => {
89
89
  // Handle scenario where temporary directory is on a different device than
90
90
  // the destination directory. In this situation, Node cannot move files,
91
91
  // but copying files is OK. The temporary directory is cleaned up later by
@@ -117,10 +117,10 @@ class Builder {
117
117
  fs.rmdirSync(path);
118
118
  }
119
119
  }
120
- deleteOutputFiles(paths) {
120
+ deleteOutputFiles(paths, outputRootDir) {
121
121
  paths.forEach(outputPath => {
122
122
  // Delete the file.
123
- const absOutputPath = this.pod.getAbsoluteFilePath(fsPath.join(this.outputDirectoryPodPath, outputPath));
123
+ const absOutputPath = fsPath.join(outputRootDir, outputPath.replace(/^\//, ''));
124
124
  try {
125
125
  fs.unlinkSync(absOutputPath);
126
126
  }
@@ -143,12 +143,10 @@ class Builder {
143
143
  }
144
144
  });
145
145
  }
146
- getExistingManifest() {
147
- const path = this.manifestPodPath;
148
- if (this.pod.fileExists(path)) {
149
- return JSON.parse(this.pod.readFile(this.manifestPodPath));
150
- }
151
- return null;
146
+ getManifest(filePath) {
147
+ return fs.existsSync(filePath)
148
+ ? JSON.parse(fs.readFileSync(filePath, 'utf-8'))
149
+ : null;
152
150
  }
153
151
  cleanOutputUsingManifests(existingManifest, newManifest, options) {
154
152
  const buildDiffPaths = {
@@ -208,11 +206,109 @@ class Builder {
208
206
  return new cliProgress.SingleBar(options, cliProgress.Presets.shades_classic);
209
207
  }
210
208
  async export(options) {
209
+ const buildDir = options.buildDir ?? this.pod.getAbsoluteFilePath(this.outputDirectoryPodPath);
210
+ const buildManifestPath = fsPath.join(buildDir, '.amagaki', 'manifest.json');
211
+ const exportManifestPath = options.exportControlDir
212
+ ? fsPath.join(options.exportControlDir, 'manifest.json')
213
+ : fsPath.join(options.exportDir, '.amagaki', 'manifest.json');
214
+ const buildManifest = this.getManifest(buildManifestPath);
215
+ const exportManifest = this.getManifest(exportManifestPath);
216
+ if (!buildManifest) {
217
+ throw new Error(`Could not find build manifest at ${buildManifestPath}.`);
218
+ }
219
+ const filesToExport = buildManifest.files;
220
+ const existingFiles = exportManifest?.files;
221
+ // Collect adds, edits, and deletes.
222
+ const result = {
223
+ adds: [],
224
+ edits: [],
225
+ noChanges: [],
226
+ deletes: [],
227
+ };
228
+ if (!existingFiles) {
229
+ result.adds = buildManifest.files.map(pathSha => pathSha.path);
230
+ }
231
+ else {
232
+ const existingPathsToShas = {};
233
+ for (const pathSha of existingFiles) {
234
+ existingPathsToShas[pathSha.path] = pathSha.sha;
235
+ }
236
+ const buildPathsToShas = {};
237
+ for (const pathSha of filesToExport) {
238
+ buildPathsToShas[pathSha.path] = pathSha.sha;
239
+ }
240
+ for (const pathSha of buildManifest.files) {
241
+ if (pathSha.path in existingPathsToShas) {
242
+ if (pathSha.sha !== existingPathsToShas[pathSha.path]) {
243
+ result.edits.push(pathSha.path);
244
+ }
245
+ else {
246
+ result.noChanges.push(pathSha.path);
247
+ }
248
+ }
249
+ else {
250
+ result.adds.push(pathSha.path);
251
+ }
252
+ }
253
+ for (const pathSha of existingFiles) {
254
+ if (!(pathSha.path in buildPathsToShas)) {
255
+ result.deletes.push(pathSha.path);
256
+ }
257
+ }
258
+ }
259
+ if (exportManifest?.commit) {
260
+ console.log(chalk_1.default.yellow(`Previous export:`), `${exportManifest.built} by ${exportManifest.commit.author.email} (${exportManifest.commit.sha.slice(0, 6)})`);
261
+ }
262
+ if (buildManifest?.commit) {
263
+ console.log(chalk_1.default.yellow(` Current build:`), `${buildManifest.built} by ${buildManifest.commit.author.email} (${buildManifest.commit.sha.slice(0, 6)})`);
264
+ }
265
+ const numOperations = result.adds.length + result.edits.length + result.deletes.length;
266
+ if (numOperations === 0) {
267
+ console.log(chalk_1.default.blue('No changes since last export: ') +
268
+ this.pod.getAbsoluteFilePath(options.exportDir));
269
+ return result;
270
+ }
271
+ const moveBar = Builder.createProgressBar('Exporting');
272
+ const showMoveProgressBar = numOperations >= Builder.ShowMoveProgressBarThreshold;
273
+ const moveStartTime = new Date().getTime();
274
+ if (showMoveProgressBar) {
275
+ moveBar.start(numOperations, 0, {
276
+ customDuration: Builder.formatProgressBarTime(0),
277
+ });
278
+ }
279
+ // Copy adds and edits.
280
+ const moveFiles = [...result.adds, ...result.edits];
281
+ await async.mapLimit(moveFiles, Builder.NumConcurrentCopies, async (filePath) => {
282
+ const relativePath = filePath.replace(/^\//, '');
283
+ const source = fsPath.join(buildDir, relativePath);
284
+ const destination = fsPath.join(options.exportDir, relativePath);
285
+ ;
286
+ Builder.ensureDirectoryExists(destination);
287
+ moveBar.increment();
288
+ return fs.promises.copyFile(source, destination);
289
+ });
290
+ // Delete deleted files.
291
+ this.deleteOutputFiles(result.deletes, options.exportDir);
292
+ moveBar.stop();
293
+ // Write the manifest.
294
+ await Promise.all([
295
+ this.writeFileAsync(exportManifestPath, JSON.stringify(buildManifest, null, 2)),
296
+ ]);
297
+ console.log(chalk_1.default.blue('Changes: ') +
298
+ chalk_1.default.green(`${result.adds.length} adds, `) +
299
+ chalk_1.default.yellow(`${result.edits.length} edits, `) +
300
+ chalk_1.default.red(`${result.deletes.length} deletes`));
301
+ console.log(chalk_1.default.blue('Export complete: ') +
302
+ this.pod.getAbsoluteFilePath(options.exportDir));
303
+ return result;
304
+ }
305
+ async build(options) {
211
306
  await this.pod.plugins.trigger('beforeBuild', this);
212
- const existingManifest = this.getExistingManifest();
307
+ const existingManifest = this.getManifest(this.manifestPath);
308
+ const gitData = await (0, gitData_1.getGitData)(this.pod.root);
213
309
  const buildManifest = {
214
- branch: null,
215
- commit: null,
310
+ branch: gitData.branch,
311
+ commit: gitData.commit,
216
312
  built: new Date().toString(),
217
313
  files: [],
218
314
  };
@@ -372,17 +468,19 @@ class Builder {
372
468
  localesToMissingTranslations[locale.id].push(string);
373
469
  }
374
470
  }
375
- buildMetrics.localesToNumMissingTranslations = localesToNumMissingTranslations;
471
+ buildMetrics.localesToNumMissingTranslations =
472
+ localesToNumMissingTranslations;
376
473
  // Write the manifest and metrics.
377
474
  await Promise.all([
378
- this.writeFileAsync(this.pod.getAbsoluteFilePath(this.manifestPodPath), JSON.stringify(buildManifest, null, 2)),
475
+ this.writeFileAsync(this.manifestPath, JSON.stringify(buildManifest, null, 2)),
379
476
  this.writeFileAsync(this.pod.getAbsoluteFilePath(this.metricsPodPath), JSON.stringify(buildMetrics, null, 2)),
380
477
  ]);
381
478
  const buildDiff = this.cleanOutputUsingManifests(existingManifest, buildManifest, options);
382
479
  // After diff has been computed, actually delete files. Incremental builds
383
480
  // don't support deletes, so avoid deleting files if building incrementally.
384
481
  if (!options?.patterns) {
385
- this.deleteOutputFiles(buildDiff.deletes);
482
+ const outputRootDir = this.pod.getAbsoluteFilePath(fsPath.join(this.outputDirectoryPodPath));
483
+ this.deleteOutputFiles(buildDiff.deletes, outputRootDir);
386
484
  }
387
485
  const result = {
388
486
  diff: buildDiff,
@@ -447,4 +545,3 @@ Builder.DefaultOutputDirectory = 'build';
447
545
  Builder.NumConcurrentBuilds = 40;
448
546
  Builder.NumConcurrentCopies = 2000;
449
547
  Builder.ShowMoveProgressBarThreshold = 1000;
450
- //# sourceMappingURL=builder.js.map
package/dist/src/cache.js CHANGED
@@ -28,4 +28,3 @@ class Cache {
28
28
  }
29
29
  }
30
30
  exports.Cache = Cache;
31
- //# sourceMappingURL=cache.js.map
package/dist/src/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  export declare const VERSION: any;
3
- export declare const MIN_NODE_VERSION = 10;
3
+ export declare const MIN_NODE_VERSION = 14;
4
4
  export declare function isNodeVersionSupported(): boolean;
package/dist/src/cli.js CHANGED
@@ -25,10 +25,11 @@ exports.isNodeVersionSupported = exports.MIN_NODE_VERSION = exports.VERSION = vo
25
25
  // @ts-ignore: File is located two directories down when packed.
26
26
  const packageData = __importStar(require("../../package.json"));
27
27
  const build_1 = require("./commands/build");
28
+ const export_1 = require("./commands/export");
28
29
  const serve_1 = require("./commands/serve");
29
30
  const commander_1 = require("commander");
30
31
  exports.VERSION = packageData.version;
31
- exports.MIN_NODE_VERSION = 10;
32
+ exports.MIN_NODE_VERSION = 14;
32
33
  // Make sure that unhandled promises causes the command to fail.
33
34
  process.on('unhandledRejection', up => {
34
35
  throw up;
@@ -49,6 +50,19 @@ program
49
50
  const cmd = new build_1.BuildCommand(program.opts(), options);
50
51
  cmd.run(path);
51
52
  });
53
+ program
54
+ .command('export [root]')
55
+ .description('export a build to another directory')
56
+ .requiredOption('-o, --exportDir <path>', 'export directory')
57
+ .option('-b, --buildDir <path>', 'build directory', 'build')
58
+ .option('-c, --exportControlDir <path>', 'export control directory')
59
+ .action((path, options) => {
60
+ if (!isNodeVersionSupported()) {
61
+ return;
62
+ }
63
+ const cmd = new export_1.ExportCommand(program.opts(), options);
64
+ cmd.run(path);
65
+ });
52
66
  program
53
67
  .command('serve [root]')
54
68
  .description('start the development server')
@@ -64,10 +78,9 @@ program.parse(process.argv);
64
78
  function isNodeVersionSupported() {
65
79
  const version = Number(process.version.slice(1).split('.')[0]);
66
80
  if (version < exports.MIN_NODE_VERSION) {
67
- console.error(`Amagaki requires Node.js 10.x or higher. You are currently running ${process.version}, which is not supported.`);
81
+ console.error(`Amagaki requires Node.js 14.x or higher. You are currently running ${process.version}, which is not supported.`);
68
82
  return false;
69
83
  }
70
84
  return true;
71
85
  }
72
86
  exports.isNodeVersionSupported = isNodeVersionSupported;
73
- //# sourceMappingURL=cli.js.map
@@ -95,7 +95,7 @@ export declare class Collection {
95
95
  * the document whose basename is `index`. If two documents with different
96
96
  * extensions are located, the first one found is returned.
97
97
  */
98
- get index(): Document | undefined;
98
+ get index(): Document;
99
99
  /**
100
100
  * Returns a list of the parent collections, up to the top-most collection.
101
101
  *
@@ -266,4 +266,3 @@ class Collection {
266
266
  }
267
267
  exports.Collection = Collection;
268
268
  Collection.ConfigFile = '_collection.yaml';
269
- //# sourceMappingURL=collection.js.map
@@ -1,27 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  exports.BuildCommand = void 0;
23
- const fs = __importStar(require("fs"));
24
- const pod_1 = require("../pod");
4
+ const global_1 = require("./global");
25
5
  const profile_1 = require("../profile");
26
6
  class BuildCommand {
27
7
  constructor(globalOptions, options) {
@@ -29,13 +9,10 @@ class BuildCommand {
29
9
  this.options = options;
30
10
  }
31
11
  async run(path = './') {
32
- const pod = new pod_1.Pod(fs.realpathSync(path), this.globalOptions.env ? { name: this.globalOptions.env } : undefined);
33
- if (this.globalOptions.env) {
34
- pod.setEnvironment(this.globalOptions.env);
35
- }
12
+ const pod = (0, global_1.getPodWithEnvironment)(path, this.globalOptions);
36
13
  const timer = pod.profiler.timer('command.build', 'Build command');
37
14
  try {
38
- await pod.builder.export({
15
+ await pod.builder.build({
39
16
  patterns: this.options.pattern,
40
17
  writeLocales: this.options.writeLocales,
41
18
  });
@@ -49,4 +26,3 @@ class BuildCommand {
49
26
  }
50
27
  }
51
28
  exports.BuildCommand = BuildCommand;
52
- //# sourceMappingURL=build.js.map
@@ -0,0 +1,8 @@
1
+ import { GlobalOptions } from './global';
2
+ import { ExportOptions } from '../builder';
3
+ export declare class ExportCommand {
4
+ private readonly globalOptions;
5
+ private readonly options;
6
+ constructor(globalOptions: GlobalOptions, options: ExportOptions);
7
+ run(path?: string): Promise<void>;
8
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportCommand = void 0;
4
+ const global_1 = require("./global");
5
+ class ExportCommand {
6
+ constructor(globalOptions, options) {
7
+ this.globalOptions = globalOptions;
8
+ this.options = options;
9
+ }
10
+ async run(path = './') {
11
+ const pod = (0, global_1.getPodWithEnvironment)(path, this.globalOptions);
12
+ const timer = pod.profiler.timer('command.export', 'Export command');
13
+ try {
14
+ await pod.builder.export(this.options);
15
+ }
16
+ finally {
17
+ timer.stop();
18
+ }
19
+ }
20
+ }
21
+ exports.ExportCommand = ExportCommand;
@@ -1,4 +1,6 @@
1
+ import { EnvironmentOptions, Pod } from '..';
1
2
  export interface GlobalOptions {
2
3
  profile?: boolean;
3
4
  env?: string;
4
5
  }
6
+ export declare function getPodWithEnvironment(path: string, globalOptions: GlobalOptions, env?: EnvironmentOptions): Pod;
@@ -1,3 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=global.js.map
6
+ exports.getPodWithEnvironment = void 0;
7
+ const __1 = require("..");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ function getPodWithEnvironment(path, globalOptions, env) {
10
+ const pod = new __1.Pod(fs_1.default.realpathSync(path), env ?? (globalOptions.env ? { name: globalOptions.env } : undefined));
11
+ if (env !== undefined && globalOptions.env) {
12
+ pod.setEnvironment(globalOptions.env);
13
+ }
14
+ return pod;
15
+ }
16
+ exports.getPodWithEnvironment = getPodWithEnvironment;
@@ -1,31 +1,11 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
4
  };
24
5
  Object.defineProperty(exports, "__esModule", { value: true });
25
6
  exports.ServeCommand = void 0;
26
- const fs = __importStar(require("fs"));
7
+ const global_1 = require("./global");
27
8
  const server_1 = require("../server");
28
- const pod_1 = require("../pod");
29
9
  const chalk_1 = __importDefault(require("chalk"));
30
10
  class ServeCommand {
31
11
  constructor(globalOptions, options) {
@@ -34,16 +14,13 @@ class ServeCommand {
34
14
  }
35
15
  async run(path = './') {
36
16
  const port = this.options.port || process.env.PORT || 8080;
37
- const pod = new pod_1.Pod(fs.realpathSync(path), {
17
+ const pod = (0, global_1.getPodWithEnvironment)(path, this.globalOptions, {
38
18
  dev: true,
39
19
  host: 'localhost',
40
20
  name: this.globalOptions.env || 'default',
41
21
  port: `${port}`,
42
22
  scheme: 'http',
43
23
  });
44
- if (this.globalOptions.env) {
45
- pod.setEnvironment(this.globalOptions.env);
46
- }
47
24
  const server = new server_1.Server(pod, {
48
25
  port: port,
49
26
  });
@@ -59,4 +36,3 @@ class ServeCommand {
59
36
  }
60
37
  }
61
38
  exports.ServeCommand = ServeCommand;
62
- //# sourceMappingURL=serve.js.map
@@ -159,7 +159,7 @@ export declare class Document {
159
159
  get locales(): Set<Locale>;
160
160
  get fields(): any;
161
161
  get content(): string | null;
162
- get body(): string | null | undefined;
162
+ get body(): string;
163
163
  private initPartsFromFrontMatter;
164
164
  /**
165
165
  * Returns whether a document is servable, given a pod path.
@@ -376,4 +376,3 @@ Document.SupportedExtensions = new Set([
376
376
  '.yaml',
377
377
  ]);
378
378
  Document.FrontMatterOnlyExtensions = new Set(['.yaml']);
379
- //# sourceMappingURL=document.js.map
@@ -30,4 +30,3 @@ class Environment {
30
30
  }
31
31
  }
32
32
  exports.Environment = Environment;
33
- //# sourceMappingURL=environment.js.map
@@ -0,0 +1,15 @@
1
+ export interface GitAuthor {
2
+ email: string;
3
+ name: string;
4
+ timestamp: number;
5
+ }
6
+ export interface GitCommit {
7
+ message: string;
8
+ author: GitAuthor;
9
+ sha: string;
10
+ }
11
+ export interface GitData {
12
+ branch: string;
13
+ commit: GitCommit;
14
+ }
15
+ export declare function getGitData(path: string): Promise<GitData>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.getGitData = void 0;
26
+ const fsPath = __importStar(require("path"));
27
+ const git = __importStar(require("isomorphic-git"));
28
+ const fs_1 = __importDefault(require("fs"));
29
+ async function getGitData(path) {
30
+ path = fsPath.resolve(path);
31
+ const root = await git.findRoot({
32
+ fs: fs_1.default,
33
+ filepath: path,
34
+ });
35
+ const log = await git.log({
36
+ fs: fs_1.default,
37
+ dir: root,
38
+ depth: 1,
39
+ ref: 'HEAD',
40
+ });
41
+ const branch = process.env.BRANCH_NAME ||
42
+ process.env.CIRCLE_BRANCH ||
43
+ (await git.currentBranch({
44
+ fs: fs_1.default,
45
+ dir: root,
46
+ fullname: false,
47
+ })) ||
48
+ '';
49
+ if (!log || !log[0]) {
50
+ throw new Error(`Failed to retrieve Git data from path: ${path}`);
51
+ }
52
+ const commit = log[0].commit;
53
+ const cleanMessage = commit.message.slice(0, 128);
54
+ return {
55
+ branch: branch,
56
+ commit: {
57
+ sha: log[0].oid,
58
+ message: cleanMessage,
59
+ author: {
60
+ timestamp: commit.committer.timestamp,
61
+ name: commit.author.name,
62
+ email: commit.author.email,
63
+ },
64
+ },
65
+ };
66
+ }
67
+ exports.getGitData = getGitData;
package/dist/src/index.js CHANGED
@@ -27,4 +27,3 @@ __exportStar(require("./string"), exports);
27
27
  __exportStar(require("./templateEngine"), exports);
28
28
  __exportStar(require("./url"), exports);
29
29
  __exportStar(require("./utils"), exports);
30
- //# sourceMappingURL=index.js.map
@@ -141,4 +141,3 @@ class LocalizableData {
141
141
  }
142
142
  }
143
143
  exports.LocalizableData = LocalizableData;
144
- //# sourceMappingURL=locale.js.map
@@ -42,4 +42,3 @@ class BuilderPlugin {
42
42
  }
43
43
  }
44
44
  exports.BuilderPlugin = BuilderPlugin;
45
- //# sourceMappingURL=builder.js.map
@@ -15,4 +15,3 @@ __exportStar(require("./nunjucks"), exports);
15
15
  __exportStar(require("./router"), exports);
16
16
  __exportStar(require("./server"), exports);
17
17
  __exportStar(require("./yaml"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -102,7 +102,9 @@ class NunjucksPlugin {
102
102
  addGlobal(globalName, value) {
103
103
  this.shortcutGlobals[globalName] = value;
104
104
  }
105
- createTemplateEngineHook(templateEngine, extension) {
105
+ createTemplateEngineHook(templateEngine,
106
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
107
+ extension) {
106
108
  if (templateEngine.constructor.name === 'NunjucksTemplateEngine') {
107
109
  // Add in the shortcut filters.
108
110
  for (const key of Object.keys(this.shortcutFilters)) {
@@ -126,6 +128,7 @@ class NunjucksTemplateEngine {
126
128
  this.env = new nunjucks.Environment(loader, {
127
129
  // Use `dev` option to output full errors from within Nunjucks.
128
130
  // See relevant discussion: https://github.com/mozilla/nunjucks/issues/1287#issuecomment-643602156
131
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
129
132
  // @ts-ignore
130
133
  dev: true,
131
134
  autoescape: true,
@@ -196,4 +199,3 @@ class NunjucksPodLoader extends nunjucks.Loader {
196
199
  return res;
197
200
  }
198
201
  }
199
- //# sourceMappingURL=nunjucks.js.map