Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jun 14, 2024
1 parent 94568d7 commit fd97ba3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
project adheres to [Semantic Versioning](https://semver.org/).

## [0.2.4] - 2024-06-14
### Fixed
- Upgrade Lume in an external import map file.

## [0.2.3] - 2024-06-04
### Fixed
- Lume dev version specifier.
Expand Down Expand Up @@ -93,6 +97,7 @@ First version
[#1]: https://github.com/lumeland/init/issues/1
[#3]: https://github.com/lumeland/init/issues/3

[0.2.4]: https://github.com/lumeland/init/compare/v0.2.3...v0.2.4
[0.2.3]: https://github.com/lumeland/init/compare/v0.2.2...v0.2.3
[0.2.2]: https://github.com/lumeland/init/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/lumeland/init/compare/v0.2.0...v0.2.1
Expand Down
1 change: 1 addition & 0 deletions init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Content of deno.json file */
export interface DenoConfig {
importMap?: string;
imports?: Record<string, string>;
tasks?: Record<string, string>;
compilerOptions?: CompilerOptions;
Expand Down
40 changes: 35 additions & 5 deletions steps/update.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { colors, join } from "../deps.ts";
import type { Init } from "../init.ts";
import type { DenoConfig, Init } from "../init.ts";

export default function () {
return async ({ path, deno, lume }: Init) => {
// Save Deno configuration file
const content = JSON.stringify(deno, null, 2) + "\n";
const denoFile = join(path, "deno.json");
const existingContent = await Deno.readTextFile(denoFile);
const changed = await saveDenoConfig(deno, denoFile);

if (existingContent !== content) {
await Deno.writeTextFile(denoFile, content);
if (changed) {
console.log("Update successful!");
console.log(
"Your Lume version is:",
Expand All @@ -20,3 +18,35 @@ export default function () {
}
};
}

async function saveDenoConfig(
deno: DenoConfig,
file: string,
): Promise<boolean> {
let changed = false;

if (deno.importMap) {
const importMap = { imports: deno.imports, scopes: deno.scopes };
const existingContent = await Deno.readTextFile(deno.importMap);
const newContent = JSON.stringify(importMap, null, 2) + "\n";

if (existingContent.trim() !== newContent.trim()) {
changed = true;
}

await Deno.writeTextFile(deno.importMap, newContent);
delete deno.imports;
delete deno.scopes;
}

const newContent = JSON.stringify(deno, null, 2) + "\n";
const existingContent = await Deno.readTextFile(file);

if (existingContent.trim() !== newContent.trim()) {
changed = true;
}

await Deno.writeTextFile(file, newContent);

return changed;
}

0 comments on commit fd97ba3

Please sign in to comment.