-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure create app to make it easier to upgrade deps #477
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/create-app.template-packager/bin/create-app.template-packager.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
// @ts-check | ||
|
||
import { cli } from "../build/esm/index.js"; | ||
cli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "@osdk/create-app.template-packager", | ||
"version": "0.0.0", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/palantir/osdk-ts.git" | ||
}, | ||
"exports": { | ||
".": { | ||
"browser": "./build/browser/index.js", | ||
"import": "./build/esm/index.js" | ||
}, | ||
"./*": { | ||
"browser": "./build/browser/public/*.js", | ||
"import": "./build/esm/public/*.js" | ||
} | ||
}, | ||
"scripts": { | ||
"check-attw": "../../scripts/build_common/check-attw.sh esm", | ||
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo", | ||
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)", | ||
"lint": "eslint . && dprint check --config $(find-up dprint.json)", | ||
"transpile": "find . \\( -path build/cjs -or -path build/esm -or -path build/browser \\) -type f \\( -name '*.js' -or -name '*.js.map' -or -name '*.cjs' -or -name '*.cjs.map' \\) -delete && tsup", | ||
"typecheck": "find . \\( -path build/cjs -or -path build/esm -or -path build/browser \\) -type f \\( -name '*.ts' -or -name '*.ts.map' -or -name '*.cts' -or -name '*.cts.map' \\) -delete && ../../scripts/build_common/typecheck.sh esm" | ||
}, | ||
"dependencies": { | ||
"consola": "^3.2.3", | ||
"find-up": "^7.0.0", | ||
"serialize-javascript": "^6.0.2" | ||
}, | ||
"devDependencies": { | ||
"@osdk/monorepo.api-extractor": "workspace:~", | ||
"@osdk/monorepo.tsconfig": "workspace:~", | ||
"@osdk/monorepo.tsup": "workspace:~", | ||
"@types/node": "^18.0.0", | ||
"@types/serialize-javascript": "^5.0.4", | ||
"@types/tmp": "^0.2.6", | ||
"@types/yargs": "^17.0.29", | ||
"tmp": "^0.2.3", | ||
"typescript": "^5.5.2" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"bin": { | ||
"create-app.template-packager": "bin/create-app.template-packager.mjs" | ||
}, | ||
"files": [ | ||
"build/cjs", | ||
"build/esm", | ||
"build/browser", | ||
"CHANGELOG.md", | ||
"package.json", | ||
"templates", | ||
"*.d.ts" | ||
], | ||
"main": "./build/cjs/index.cjs", | ||
"module": "./build/esm/index.js", | ||
"types": "./build/esm/index.d.ts", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { findUp } from "find-up"; | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
import serialize from "serialize-javascript"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code gen for each |
||
export async function cli() { | ||
const extsToString = new Set([".html", ".cjs", ".hbs", ".gitignore", ".tsx"]); | ||
|
||
const templatesDir = await findUp("templates", { type: "directory" }); | ||
if (!templatesDir) throw new Error("template dir is missing"); | ||
|
||
const sourcePackageJsonPath = await findUp("package.json"); | ||
if (!sourcePackageJsonPath) throw new Error("package.json is missing"); | ||
|
||
const sourcePackageJson = JSON.parse( | ||
await fs.readFile(sourcePackageJsonPath, "utf-8"), | ||
); | ||
|
||
let result = | ||
"export const files = new Map<string, {type: 'base64', body: string} | {type: 'raw', body: string}>([\n"; | ||
|
||
const processFiles = async function(dir: string, baseDir: string) { | ||
for (const filename of await fs.readdir(dir)) { | ||
const file = dir + "/" + filename; | ||
|
||
const stat = await fs.stat(file); | ||
if (stat.isDirectory()) { | ||
await processFiles(file, baseDir); | ||
continue; | ||
} | ||
|
||
let destPath = path.relative(baseDir, file); | ||
|
||
if (path.basename(destPath) === "_gitignore") { | ||
destPath = path.join(path.dirname(destPath), ".gitignore"); | ||
} | ||
|
||
const body = await fs.readFile(file); | ||
let output: string; | ||
|
||
if (destPath === "package.json.hbs") { | ||
const packageJson = JSON.parse(body.toString("utf-8")); | ||
|
||
for ( | ||
const d of ["dependencies", "devDependencies", "peerDependencies"] | ||
) { | ||
if (sourcePackageJson[d]) { | ||
if (!packageJson[d]) { | ||
packageJson[d] = {}; | ||
} | ||
Object.assign(packageJson[d], sourcePackageJson[d]); | ||
delete packageJson[d]["@osdk/create-app.template-packager"]; | ||
for (const key of Object.keys(packageJson[d])) { | ||
if (key.startsWith("@osdk/monorepo.")) { | ||
delete packageJson[d][key]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
output = safeRaw(JSON.stringify(packageJson, undefined, 2)); | ||
} else if ( | ||
extsToString.has(path.extname(destPath)) | ||
|| path.basename(destPath) === ".gitignore" | ||
) { | ||
output = safeRaw(body.toString("utf-8")); | ||
} else { | ||
output = serialize({ | ||
type: "base64", | ||
body: body.toString("base64"), | ||
}, { space: 2 }); | ||
} | ||
|
||
result += `["${destPath}", ${output}],\n`; | ||
} | ||
}; | ||
await processFiles(templatesDir, templatesDir); | ||
result += `]);`; | ||
|
||
await fs.mkdir("src/generatedNoCheck", { recursive: true }); | ||
|
||
await fs.writeFile("src/generatedNoCheck/index.ts", result, { | ||
encoding: "utf-8", | ||
}); | ||
} | ||
|
||
function safeRaw(q: string): string { | ||
return `{ type: "raw", body: \`${ | ||
q | ||
.replace(/\\/g, "\\\\") | ||
.replace(/`/g, "\\`") | ||
.replace(/\$/g, "\\$") | ||
}\`}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"moduleResolution": "Node", | ||
"target": "ES6", | ||
"rootDir": "src", | ||
"outDir": "build/cjs" | ||
}, | ||
"include": [ | ||
"./src/**/*" | ||
], | ||
"references": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@osdk/monorepo.tsconfig/base.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "build/esm" | ||
}, | ||
"include": [ | ||
"./src/**/*" | ||
], | ||
"references": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig(async (options) => | ||
(await import("@osdk/monorepo.tsup")).default(options, { | ||
esmOnly: true, | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# @osdk/create-app.template.next-static-export | ||
|
||
This package contains templates for `@osdk/create-app`. | ||
|
||
The dependencies will come from this package's `package.json` (excluding `@osdk/create-app.template-packager`) and the rest of template is filled out from the `templates` directory. | ||
|
||
NOTE: DO NOT EDIT THIS README BY HAND. It is generated by monorepolint. |
60 changes: 60 additions & 0 deletions
60
packages/create-app.template.next-static-export/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "@osdk/create-app.template.next-static-export", | ||
"version": "0.17.0-beta.2", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/palantir/osdk-ts.git" | ||
}, | ||
"exports": { | ||
".": { | ||
"browser": "./build/browser/index.js", | ||
"import": "./build/esm/index.js" | ||
}, | ||
"./*": { | ||
"browser": "./build/browser/public/*.js", | ||
"import": "./build/esm/public/*.js" | ||
} | ||
}, | ||
"scripts": { | ||
"check-attw": "../../scripts/build_common/check-attw.sh esm", | ||
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo", | ||
"codegen": "create-app.template-packager", | ||
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)", | ||
"lint": "eslint . && dprint check --config $(find-up dprint.json)", | ||
"transpile": "find . \\( -path build/cjs -or -path build/esm -or -path build/browser \\) -type f \\( -name '*.js' -or -name '*.js.map' -or -name '*.cjs' -or -name '*.cjs.map' \\) -delete && tsup", | ||
"typecheck": "find . \\( -path build/cjs -or -path build/esm -or -path build/browser \\) -type f \\( -name '*.ts' -or -name '*.ts.map' -or -name '*.cts' -or -name '*.cts.map' \\) -delete && ../../scripts/build_common/typecheck.sh esm" | ||
}, | ||
"dependencies": { | ||
"next": "14.2.3", | ||
"react": "^18", | ||
"react-dom": "^18" | ||
}, | ||
"devDependencies": { | ||
"@osdk/create-app.template-packager": "workspace:~", | ||
"@osdk/monorepo.api-extractor": "workspace:~", | ||
"@osdk/monorepo.tsconfig": "workspace:~", | ||
"@osdk/monorepo.tsup": "workspace:~", | ||
"@types/node": "^20", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"eslint": "^8.57.0", | ||
"eslint-config-next": "^14.2.3", | ||
"typescript": "^5" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"build/cjs", | ||
"build/esm", | ||
"build/browser", | ||
"CHANGELOG.md", | ||
"package.json", | ||
"templates", | ||
"*.d.ts" | ||
], | ||
"module": "./build/esm/index.js", | ||
"types": "./build/esm/index.d.ts", | ||
"type": "module" | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/create-app.template.next-static-export/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export { files } from "./generatedNoCheck/index.js"; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unified README's.