Skip to content
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

NEXT-33446 - add new env variable #30

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
ADMIN_TOKENS_FILE_KEY: ${{ secrets.TOKENS__ADMIN_TOKENS_FILE_KEY }}
PRIMITIVE_TOKENS_FILE_KEY: ${{ secrets.TOKENS__PRIMITIVE_TOKENS_FILE_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion packages/tokens/.env

This file was deleted.

40 changes: 18 additions & 22 deletions packages/tokens/src/GenerateArtifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { env } from './env.js';
import { HttpClientUsingFetch } from './common/infrastructure/http-client/HttpClientUsingFetch.js';
import { server } from '../tests/mocks/node.js';
import { HttpResponse, http } from 'msw';
import {
ADMIN_TOKENS_FILE_KEY,
PRIMITIVE_TOKENS_FILE_KEY,
} from './constants.js';

fact(
'creates a Dictionary in form of a JSON file for the primitive Design Tokens',
async () => {
// GIVEN
server.use(
http.get(
`https://api.figma.com/v1/files/${PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -80,7 +76,7 @@ fact(
},
),
http.get(
`https://api.figma.com/v1/files/${ADMIN_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.ADMIN_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -132,7 +128,7 @@ fact(

const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand Down Expand Up @@ -172,7 +168,7 @@ fact(
// GIVEN
server.use(
http.get(
`https://api.figma.com/v1/files/${PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -235,7 +231,7 @@ fact(
},
),
http.get(
`https://api.figma.com/v1/files/${ADMIN_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.ADMIN_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -287,7 +283,7 @@ fact(

const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand Down Expand Up @@ -327,7 +323,7 @@ fact(
// GIVEN
server.use(
http.get(
`https://api.figma.com/v1/files/${PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -390,7 +386,7 @@ fact(
},
),
http.get(
`https://api.figma.com/v1/files/${ADMIN_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.ADMIN_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -442,7 +438,7 @@ fact(

const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand Down Expand Up @@ -480,7 +476,7 @@ fact('creates a CSS file for the primitive Design Tokens', async () => {
// GIVEN
server.use(
http.get(
`https://api.figma.com/v1/files/${PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -543,7 +539,7 @@ fact('creates a CSS file for the primitive Design Tokens', async () => {
},
),
http.get(
`https://api.figma.com/v1/files/${ADMIN_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.ADMIN_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -595,7 +591,7 @@ fact('creates a CSS file for the primitive Design Tokens', async () => {

const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand All @@ -622,7 +618,7 @@ fact('creates a CSS file for the admin light mode tokens', async () => {
// GIVEN
server.use(
http.get(
`https://api.figma.com/v1/files/${PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -685,7 +681,7 @@ fact('creates a CSS file for the admin light mode tokens', async () => {
},
),
http.get(
`https://api.figma.com/v1/files/${ADMIN_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.ADMIN_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -737,7 +733,7 @@ fact('creates a CSS file for the admin light mode tokens', async () => {

const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand All @@ -763,7 +759,7 @@ fact('creates a CSS file for the admin dark mode tokens', async () => {
// GIVEN
server.use(
http.get(
`https://api.figma.com/v1/files/${PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.PRIMITIVE_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -826,7 +822,7 @@ fact('creates a CSS file for the admin dark mode tokens', async () => {
},
),
http.get(
`https://api.figma.com/v1/files/${ADMIN_TOKENS_FILE_KEY}/variables/local`,
`https://api.figma.com/v1/files/${env.ADMIN_TOKENS_FILE_KEY}/variables/local`,
() => {
return HttpResponse.json({
status: 200,
Expand Down Expand Up @@ -878,7 +874,7 @@ fact('creates a CSS file for the admin dark mode tokens', async () => {

const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand Down
9 changes: 3 additions & 6 deletions packages/tokens/src/GenerateArtifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import type { FileSystem } from './common/domain/file-system/FileSystem.js';
import { Dictionary } from './dictionary/domain/Dictionary.js';
import { CSSDeliverable } from './deliverable/domain/CSSDeliverable.js';
import { FigmaApi } from './figma/infrastructure/FigmaApi.js';
import {
ADMIN_TOKENS_FILE_KEY,
PRIMITIVE_TOKENS_FILE_KEY,
} from './constants.js';
import { env } from './env.js';

export class GenerateArtifacts {
public constructor(
Expand All @@ -15,8 +12,8 @@ export class GenerateArtifacts {

public async execute() {
const [primitiveTokenResponse, adminTokenResponse] = await Promise.all(
[PRIMITIVE_TOKENS_FILE_KEY, ADMIN_TOKENS_FILE_KEY].map((fileKey) =>
this.figmaApi.getLocalVariablesOfFile(fileKey),
[env.PRIMITIVE_TOKENS_FILE_KEY, env.ADMIN_TOKENS_FILE_KEY].map(
(fileKey) => this.figmaApi.getLocalVariablesOfFile(fileKey),
),
);

Expand Down
2 changes: 0 additions & 2 deletions packages/tokens/src/constants.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/tokens/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import dotenv from 'dotenv';
dotenv.config();

const schema = z.object({
API_KEY: z.string().min(1),
FIGMA_TOKEN: z.string().min(1),
ADMIN_TOKENS_FILE_KEY: z.string().min(1),
PRIMITIVE_TOKENS_FILE_KEY: z.string().min(1),
});

export const env = schema.parse(process.env);
2 changes: 1 addition & 1 deletion packages/tokens/src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ora from 'ora';
const fileSystem = new HardDiskFileSystem();
const figmaApi = new FigmaApi(
{
apiKey: env.API_KEY,
apiKey: env.FIGMA_TOKEN,
},
new HttpClientUsingFetch(),
);
Expand Down
Loading