-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create foundry.config.json in create-app
- Loading branch information
Showing
10 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...ges/create-app/src/__snapshots__/expected-template-next-static-export/foundry.config.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,11 @@ | ||
{ | ||
"foundryUrl": "https://example.palantirfoundry.com", | ||
"site": { | ||
"application": "ri.third-party-applications.main.application.fake", | ||
"directory": "./out", | ||
"autoVersion": { | ||
"type": "git-describe", | ||
"tagPrefix": "tag-prefix" | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/create-app/src/__snapshots__/expected-template-react/foundry.config.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,11 @@ | ||
{ | ||
"foundryUrl": "https://example.palantirfoundry.com", | ||
"site": { | ||
"application": "ri.third-party-applications.main.application.fake", | ||
"directory": "./dist", | ||
"autoVersion": { | ||
"type": "git-describe", | ||
"tagPrefix": "tag-prefix" | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/create-app/src/__snapshots__/expected-template-vue/foundry.config.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,11 @@ | ||
{ | ||
"foundryUrl": "https://example.palantirfoundry.com", | ||
"site": { | ||
"application": "ri.third-party-applications.main.application.fake", | ||
"directory": "./dist", | ||
"autoVersion": { | ||
"type": "git-describe", | ||
"tagPrefix": "tag-prefix" | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
packages/create-app/src/generate/generateFoundryConfigJson.test.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,42 @@ | ||
/* | ||
* 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 { expect, test } from "vitest"; | ||
import { generateFoundryConfigJson } from "./generateFoundryConfigJson.js"; | ||
|
||
const expected = ` | ||
{ | ||
"foundryUrl": "https://example.palantirfoundry.com", | ||
"site": { | ||
"application": "ri.third-party-applications.main.application.fake", | ||
"directory": "./dist", | ||
"autoVersion": { | ||
"type": "git-describe", | ||
"tagPrefix": "tag-prefix" | ||
} | ||
} | ||
} | ||
`.trimStart(); | ||
|
||
test("it generates foundry.config.json", () => { | ||
expect( | ||
generateFoundryConfigJson({ | ||
foundryUrl: "https://example.palantirfoundry.com", | ||
application: "ri.third-party-applications.main.application.fake", | ||
directory: "./dist", | ||
}), | ||
).toEqual(expected); | ||
}); |
41 changes: 41 additions & 0 deletions
41
packages/create-app/src/generate/generateFoundryConfigJson.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,41 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export function generateFoundryConfigJson({ | ||
foundryUrl, | ||
application, | ||
directory, | ||
}: { | ||
foundryUrl: string; | ||
application: string; | ||
directory: string; | ||
}): string { | ||
return JSON.stringify( | ||
{ | ||
foundryUrl, | ||
site: { | ||
application, | ||
directory, | ||
autoVersion: { | ||
type: "git-describe", | ||
tagPrefix: "tag-prefix", | ||
}, | ||
}, | ||
}, | ||
null, | ||
2, | ||
) + "\n"; | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/create-app/src/prompts/promptApplicationRid.test.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,55 @@ | ||
/* | ||
* 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 { afterEach, expect, test, vi } from "vitest"; | ||
import { consola } from "../consola.js"; | ||
import { promptApplicationRid } from "./promptApplicationRid.js"; | ||
|
||
vi.mock("../consola.js"); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
const valid = "ri.third-party-applications.main.application.fake"; | ||
|
||
test("it accepts valid application rid from prompt", async () => { | ||
vi.mocked(consola).prompt.mockResolvedValueOnce(valid); | ||
expect(await promptApplicationRid({})).toEqual(valid); | ||
expect(vi.mocked(consola).prompt).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("it prompts again if answered value is invalid", async () => { | ||
vi.mocked(consola).prompt.mockResolvedValueOnce("ri.something.else.and.fake"); | ||
vi.mocked(consola).prompt.mockResolvedValueOnce(valid); | ||
expect(await promptApplicationRid({})).toEqual(valid); | ||
expect(vi.mocked(consola).prompt).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
test("it accepts valid initial value without prompt", async () => { | ||
expect(await promptApplicationRid({ application: valid })).toEqual(valid); | ||
expect(vi.mocked(consola).prompt).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test("it prompts if initial value is invalid", async () => { | ||
vi.mocked(consola).prompt.mockResolvedValueOnce(valid); | ||
expect( | ||
await promptApplicationRid({ application: "ri.something.else.and.fake" }), | ||
).toEqual( | ||
valid, | ||
); | ||
expect(vi.mocked(consola).prompt).toHaveBeenCalledTimes(1); | ||
}); |
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,44 @@ | ||
/* | ||
* 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 { consola } from "../consola.js"; | ||
import { italic } from "../highlight.js"; | ||
|
||
export async function promptApplicationRid( | ||
{ application }: { application?: string }, | ||
): Promise<string> { | ||
while ( | ||
application == null | ||
|| !/^ri\.third-party-applications\.[^.]+\.application\.[^.]+$/.test( | ||
application, | ||
) | ||
) { | ||
if (application != null) { | ||
consola.fail( | ||
"Please enter a valid application resource identifier (rid)", | ||
); | ||
} | ||
application = await consola.prompt( | ||
`Enter the application resource identifier (rid) for your application from Developer Console:\n${ | ||
italic( | ||
"(Example ri.third-party-applications.main.application.1c66b352-4e00-40d2-995d-061c9d533ace)", | ||
) | ||
}`, | ||
{ type: "text" }, | ||
); | ||
} | ||
return application; | ||
} |
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