-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrapped globSync and extracted blueprintRoot (#24)
* refactor: Created a function that wraps globSync * refactor: Removed unused argument * refactor: Renamed variable * refactor: Extracted function (unionize) * refactor: Extracted constant (blueprintRoot) * chore: Added tests * refactor: Extracted function (validatePackageJson) * chore: Added warning --------- Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
Showing
16 changed files
with
196 additions
and
122 deletions.
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
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
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,2 +1,3 @@ | ||
export * from './blueprints/blueprint-root.js'; | ||
export * from './blueprints/decide-version.js'; | ||
export * from './blueprints/process-template.js'; |
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,13 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
function getBlueprintRoot() { | ||
const srcDirectory = join(__dirname, '../..'); | ||
|
||
return join(srcDirectory, 'blueprints/ember-addon'); | ||
} | ||
|
||
export const blueprintRoot = getBlueprintRoot(); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { globSync } from 'glob'; | ||
|
||
export function findFiles(pattern, { cwd, ignoreList = [] }) { | ||
if (!pattern) { | ||
throw new RangeError('ERROR: The glob pattern is unknown.\n'); | ||
} | ||
|
||
if (!cwd) { | ||
throw new RangeError('ERROR: The current working directory is unknown.\n'); | ||
} | ||
|
||
const filePaths = globSync(pattern, { | ||
cwd, | ||
dot: true, | ||
ignore: ignoreList, | ||
nodir: true, | ||
}); | ||
|
||
return filePaths; | ||
} | ||
|
||
export function unionize(files) { | ||
if (files.length <= 1) { | ||
return files.join(','); | ||
} | ||
|
||
return `{${files.join(',')}}`; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { blueprintRoot } from '../../../src/utils/blueprints.js'; | ||
import { assert, test } from '../../helpers/testing.js'; | ||
|
||
test('utils | blueprints | blueprint-root', function () { | ||
assert.strictEqual( | ||
blueprintRoot.endsWith('src/blueprints/ember-addon'), | ||
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,57 @@ | ||
import { findFiles } from '../../../src/utils/files.js'; | ||
import { codemodOptions } from '../../helpers/shared-test-setups/typescript.js'; | ||
import { assert, loadFixture, test } from '../../helpers/testing.js'; | ||
|
||
test('utils | files | find-files', function () { | ||
const inputProject = { | ||
tests: { | ||
dummy: { | ||
app: { | ||
'.eslintrc.js': '', | ||
'app.ts': '', | ||
'index.html': '', | ||
'router.ts': '', | ||
}, | ||
config: { | ||
'environment.js': '', | ||
'optional-features.json': '', | ||
'targets.js': '', | ||
}, | ||
}, | ||
integration: { | ||
components: { | ||
'container-query-test.ts': '', | ||
}, | ||
}, | ||
'index.html': '', | ||
'test-helper.ts': '', | ||
}, | ||
'ember-cli-build.js': '', | ||
'index.js': '', | ||
'package.json': '', | ||
}; | ||
|
||
loadFixture(inputProject, codemodOptions); | ||
|
||
let filePaths = findFiles('tests/dummy/**/*.{js,ts}', { | ||
cwd: codemodOptions.projectRoot, | ||
}); | ||
|
||
assert.deepStrictEqual(filePaths.sort(), [ | ||
'tests/dummy/app/.eslintrc.js', | ||
'tests/dummy/app/app.ts', | ||
'tests/dummy/app/router.ts', | ||
'tests/dummy/config/environment.js', | ||
'tests/dummy/config/targets.js', | ||
]); | ||
|
||
filePaths = findFiles('tests/**/*.{js,ts}', { | ||
cwd: codemodOptions.projectRoot, | ||
ignoreList: ['tests/dummy/**/*'], | ||
}); | ||
|
||
assert.deepStrictEqual(filePaths.sort(), [ | ||
'tests/integration/components/container-query-test.ts', | ||
'tests/test-helper.ts', | ||
]); | ||
}); |