-
Notifications
You must be signed in to change notification settings - Fork 41
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
Build If-env
#790
Merged
Merged
Build If-env
#790
Changes from 36 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
1adbf1d
feat(util): add function to check if the file exists in the given path
manushak 152cfe3
feat(config): add 'MANIFEST_NOT_FOUND' string
manushak 5fd1e79
feat(types): adds IFEnvArgs interface
manushak 33ef812
feat(util): add if-env releated functions
manushak 6986792
test(util): add args test
manushak 13a1ab2
feat(config): add `IF_ENV` config
manushak 9d0d73c
feat(src): add if-env template manifest file
manushak f9d4de7
feat(src): add if-env functionality
manushak 4139704
feat(package): add `if-env` into bin and scripts
manushak 1f6b3be
Merge branch 'main' into if-env
manushak 10cf52a
fix(src): move template manifest to the top level of the scr folder
manushak caf68b1
feat(config): add log strings
manushak a28f05b
feat(types): add env types
manushak ec3ce36
feat(util): move some env functions into helpers.ts
manushak 1f0700e
fix(src): move env to the src folder
manushak 4583da3
fix(package): fix env file path
manushak 9dec82b
test(mocks): add fs.stat mock function
manushak ec43b2d
test(util): add test for npm manipulation functions in helpers.ts
manushak 91c1bed
test(util): fix commit lint error
manushak 76c6e80
fix(src): update return data of parseIfEnvArgs
manushak 2d2ca0e
test(util): update test of parseIfEnvArgs function
manushak be6412a
fix(src): remove functioanlity that create sepereate folder
manushak 9c4983d
Merge branch 'main' into if-env
manushak ee94393
Merge branch 'main' into if-env
manushak 1e04a0e
fix(src): get all dependencies from the manifest file
manushak c3a1d41
Merge branch 'main' into if-env
manushak 22febb1
chore(src): fetch changes from remote
narekhovhannisyan be0862b
feat(package): init cross env
narekhovhannisyan 4a8a962
fix(src): fix getting command working directory
manushak ea5e643
Merge branch 'if-env' of https://github.com/Green-Software-Foundation…
manushak aebd849
feat(types): add `cmd` property to IFEnvArgs type
manushak d6f4280
feat(config): add `cmd` flag for if-env
manushak c9fc62b
feat(util): update parseIfEnvArgs function to add cmd flag
manushak a2dd022
feat(types): add cmd property into EnvironmentOptions type and add Ma…
manushak ff44391
fix(src): add cmd flag, fix template manifest directory and package.j…
manushak f1b204a
fix(src): rename `cmd` to `cwd`
manushak 6cb5356
Merge branch 'main' into if-env
jmcook1186 6819c5c
fix(lib): fix import for error strings
jmcook1186 c9b6db6
fix(lib): apply linter
jmcook1186 3c09a50
fix(config): move template manifest into config directory
manushak 14b2b38
fix(src): update template manifest path
manushak f6c6ce1
feat(util): move the isFileExists funtion to the relevant file
manushak 9ff31c8
feat(util): move the npm related funtions to the relevant file
manushak 5e38270
fix(util): move some functions to the coresponding files
manushak 5483ad7
fix(util): update isFileExists path
manushak 2a6f242
feat(util): move the npm related funtions to the relevant file
manushak 0b403b2
test(util): fix isFileExists path
manushak ab54440
feat(mocks): add mocks for util/npm functionality
manushak 6a3ab7b
test(util): add test file for util/fs
manushak 83fd072
test(util): add test file for util/npm
manushak 46afe5a
fix(types): move some type to the corresponding file
manushak 07d91a4
test(util): move not related tests
manushak 041098c
feat(src): move some function to the corresponding files
manushak f3cd231
Merge branch 'main' into if-env
manushak cf78e06
fix(util): add boolean argument to check if need to update package de…
manushak 1545fcd
test(util): update the test according to changes
manushak 8e78685
fix(src): update package depenedencies depend on cwd flag
manushak 67e1595
fix(util): add some function into helpers.ts from env.ts
manushak b3e49bb
fix(util): remove unnecessary logs
manushak 3bfa285
test(util): add test for helpers function
manushak 276589f
fix(src): move some funcions into helpers
manushak fc8e42d
fix(src): fix merge conflicts with main
manushak 13a7019
fix(util): change `CliInputError` to `ParseCliParamsError` error
manushak 66a1c4c
test(util): fix npm test
manushak 0e789b1
test(mocks): add mocks for fs.writeFile
manushak accf32f
test(util): add missied tests
manushak d46d71c
fix(util): add `MissingPluginDependenciesError` custom error class
manushak 04e514a
feat(package): update if-core version
manushak ad2f87d
fix(util): fix dependencies append logic
manushak 621a311
fix(util): typo in npm
narekhovhannisyan 136f062
test(util): add cases for initializeAndInstallLibs
narekhovhannisyan 7a466cc
test(util): put back original process exit
narekhovhannisyan ed31d52
fix(src): add newline to package.json
narekhovhannisyan 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
"email": "[email protected]" | ||
}, | ||
"bin": { | ||
"if-diff": "./build/diff.js", | ||
"if-run": "./build/index.js", | ||
"if-diff": "./build/diff.js" | ||
"if-env": "./build/env.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Green-Software-Foundation/if/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+" | ||
|
@@ -37,6 +38,7 @@ | |
"@types/luxon": "^3.4.2", | ||
"@types/node": "^20.8.9", | ||
"axios-mock-adapter": "^1.22.0", | ||
"cross-env": "7.0.3", | ||
"fixpack": "^4.0.0", | ||
"gts": "^5.0.0", | ||
"husky": "^8.0.0", | ||
|
@@ -74,6 +76,7 @@ | |
"fix": "gts fix", | ||
"fix:package": "fixpack", | ||
"if-diff": "npx ts-node src/diff.ts", | ||
"if-env": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/env.ts", | ||
"if-run": "npx ts-node src/index.ts", | ||
"lint": "gts lint", | ||
"pre-commit": "lint-staged", | ||
|
@@ -85,4 +88,4 @@ | |
}, | ||
"stability": "stable", | ||
"types": "src/index.d.ts" | ||
} | ||
} | ||
narekhovhannisyan marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
jest.mock('fs/promises', () => require('../../../__mocks__/fs')); | ||
|
||
const mockInfo = jest.fn(); | ||
const mockWarn = jest.fn(); | ||
const mockError = jest.fn(); | ||
|
||
|
@@ -6,22 +12,30 @@ jest.mock('node:readline/promises', () => | |
); | ||
jest.mock('../../../util/logger', () => ({ | ||
logger: { | ||
info: mockInfo, | ||
warn: mockWarn, | ||
error: mockError, | ||
}, | ||
})); | ||
|
||
import {ERRORS} from '@grnsft/if-core'; | ||
|
||
import { | ||
andHandle, | ||
checkIfEqual, | ||
formatNotMatchingLog, | ||
mergeObjects, | ||
oneIsPrimitive, | ||
parseManifestFromStdin, | ||
isFileExists, | ||
installDependencies, | ||
initPackageJsonIfNotExists, | ||
} from '../../../util/helpers'; | ||
import {Difference} from '../../../types/lib/compare'; | ||
import {STRINGS} from '../../../config/strings'; | ||
|
||
const {WriteFileError} = ERRORS; | ||
const {INITIALIZING_PACKAGE_JSON, INSTALLING_NPM_PACKAGES} = STRINGS; | ||
|
||
describe('util/helpers: ', () => { | ||
describe('andHandle(): ', () => { | ||
|
@@ -47,9 +61,7 @@ describe('util/helpers: ', () => { | |
expect(mockError).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('util/helpers: ', () => { | ||
describe('mergeObjects(): ', () => { | ||
it('does not override input.', () => { | ||
expect.assertions(1); | ||
|
@@ -408,4 +420,92 @@ description: mock-description | |
expect(response).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('isFileExists(): ', () => { | ||
it('returns true if the file exists.', async () => { | ||
const result = await isFileExists('true'); | ||
|
||
expect.assertions(1); | ||
expect(result).toEqual(true); | ||
}); | ||
|
||
it('returns fale if the file does not exist.', async () => { | ||
const result = await isFileExists('false'); | ||
|
||
expect.assertions(1); | ||
expect(result).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('npm manipulation tests.', () => { | ||
const helpers = require('../../../util/helpers'); | ||
const folderPath = path.resolve(__dirname, 'npm-test'); | ||
|
||
beforeAll(() => { | ||
if (!fs.existsSync(folderPath)) { | ||
fs.mkdirSync(folderPath, {recursive: true}); | ||
} | ||
}); | ||
|
||
afterAll(() => { | ||
if (fs.existsSync(folderPath)) { | ||
fs.rmSync(folderPath, {recursive: true, force: true}); | ||
} | ||
}); | ||
|
||
describe('initPackageJsonIfNotExists(): ', () => { | ||
it('initializes package.json if it does not exist.', async () => { | ||
const spyExecPromise = jest.spyOn(helpers, 'execPromise'); | ||
isFileExists('true'); | ||
|
||
await initPackageJsonIfNotExists(folderPath); | ||
|
||
expect.assertions(2); | ||
expect(mockInfo).toHaveBeenCalledWith(INITIALIZING_PACKAGE_JSON); | ||
expect(spyExecPromise).toHaveBeenCalledWith('npm init -y', { | ||
cwd: folderPath, | ||
}); | ||
}); | ||
|
||
it('returns the package.json path if it exists.', async () => { | ||
const packageJsonPath = path.resolve(folderPath, 'package.json'); | ||
isFileExists('false'); | ||
|
||
const result = await initPackageJsonIfNotExists(folderPath); | ||
|
||
expect.assertions(1); | ||
expect(result).toBe(packageJsonPath); | ||
}); | ||
}); | ||
|
||
describe('installDependencies(): ', () => { | ||
const dependencies = { | ||
'@grnsft/if': '^0.3.3-beta.0', | ||
}; | ||
|
||
it('calls execPromise with the correct arguments.', async () => { | ||
const spyExecPromise = jest.spyOn(helpers, 'execPromise'); | ||
const formattedDependencies = ['@grnsft/[email protected]']; | ||
expect.assertions(1); | ||
|
||
await installDependencies(folderPath, dependencies); | ||
|
||
expect(spyExecPromise).toHaveBeenCalledWith( | ||
`npm install ${formattedDependencies.join(' ')}`, | ||
{cwd: folderPath} | ||
); | ||
}, 30000); | ||
|
||
it('logs the installation message.', async () => { | ||
const dependencies = { | ||
'@grnsft/if': '^0.3.3-beta.0', | ||
}; | ||
|
||
await installDependencies(folderPath, dependencies); | ||
|
||
expect.assertions(1); | ||
expect(mockInfo).toHaveBeenCalledWith(INSTALLING_NPM_PACKAGES); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
missing newline
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.
@narekhovhannisyan in cases like this, please just add the newline and commit. It's silly for these changes to involve >1 person.