Skip to content

Commit

Permalink
fix(configuration): minor license improvements
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Jul 21, 2024
1 parent 77f3bca commit 0b0f78e
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const metro = object | 'react-native' | File (JavaScript only)
export const reactNative = object | File
export const drizzle = 'basic' | object | File
export const vercel = 'spa' | 'SPA' | 'single-page-application' | 'spa-routes' | 'github-silent' | { extends: 'spa', routes: { ... }}
export const license = 'MIT' | 'mit' | 'public' | 'cc0' | 'commercial' | 'ccby4' | { extends: 'MIT', authors: [{ name: 'Anyone' }, { name: 'Someone', year: 2022 }]}
export const license = 'recommended' | 'MIT' | 'mit' | 'public' | 'cc0' | 'commercial' | 'ccbync4' | { extends: 'MIT', authors: [{ name: 'Anyone' }, { name: 'Someone', year: 2022 }]}
export const ignore = true | 'recommended' | 'bundle' | 'numic' | string[] | ['extends:bundle', ...]
export const gitignore = // Alias for ignore
```
Expand Down
28 changes: 16 additions & 12 deletions configuration/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getNameFromPackageJson = () => {
return state.packageJson.name
}

function listAuthors(authors?: { year?: string; name?: string }[]) {
function listAuthors(authors?: ({ year?: string; name?: string } | string)[]) {
if (!authors) {
return `${new Date().getFullYear()} ${getNameFromPackageJson()}`
}
Expand All @@ -24,7 +24,8 @@ function listAuthors(authors?: { year?: string; name?: string }[]) {
}

return authors.reduce((acc, author, index) => {
const authorString = `${author.year || new Date().getFullYear()} ${author.name || getNameFromPackageJson()}`
const authorString =
typeof author === 'string' ? author : `${author.year || new Date().getFullYear()} ${author.name || getNameFromPackageJson()}`
return acc + (index > 0 ? ', ' : '') + authorString
}, '')
}
Expand Down Expand Up @@ -68,39 +69,42 @@ When using or citing the work, you should not imply [endorsement](https://creati
[See the legal code](https://creativecommons.org/publicdomain/zero/1.0/legalcode.en)`

// Creative Commons CC0 1.0 UNIVERSAL license, does not waive rights given under the publishing jurisdiction of the author.
const commercialLicense = () => `# ATTRIBUTION 4.0 INTERNATIONAL
// Creative Commons CC BY-NC 4.0 license, contents can be shared with attribution but not used for commercial purposes.
const commercialLicense = () => `# ATTRIBUTION-NONCOMMERCIAL 4.0 INTERNATIONAL
## You are free to:
**Share** — copy and redistribute the material in any medium or format for any purpose, even commercially.
**Share** — copy and redistribute the material in any medium or format
**Adapt** — remix, transform, and build upon the material for any purpose, even commercially.
**Adapt** — remix, transform, and build upon the material
The licensor cannot revoke these freedoms as long as you follow the license terms.
## Under the following terms:
**Attribution** — You must give [appropriate credit](https://creativecommons.org/licenses/by/4.0/deed.en#ref-appropriate-credit) , provide a link to the license, and [indicate if changes were made](https://creativecommons.org/licenses/by/4.0/deed.en#ref-indicate-changes). You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
**Attribution** — You must give [appropriate credit](https://creativecommons.org/licenses/by-nc/4.0/deed.en#ref-appropriate-credit), provide a link to the license, and [indicate if changes were made](https://creativecommons.org/licenses/by-nc/4.0/deed.en#ref-indicate-changes). You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
**NonCommercial** — You may not use the material for [commercial purposes](https://creativecommons.org/licenses/by-nc/4.0/deed.en#ref-commercial-purposes).
**No additional restrictions** — You may not apply legal terms or [technological measures](https://creativecommons.org/licenses/by/4.0/deed.en#ref-technological-measures) that legally restrict others from doing anything the license permits.
**No additional restrictions** — You may not apply legal terms or [technological measures](https://creativecommons.org/licenses/by-nc/4.0/deed.en#ref-technological-measures) that legally restrict others from doing anything the license permits.
## Notices:
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable [exception or limitation](https://creativecommons.org/licenses/by/4.0/deed.en#ref-exception-or-limitation).
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable [exception or limitation](https://creativecommons.org/licenses/by-nc/4.0/deed.en#ref-exception-or-limitation).
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as [publicity, privacy, or moral rights](https://creativecommons.org/licenses/by/4.0/deed.en#ref-publicity-privacy-or-moral-rights) may limit how you use the material.
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as [publicity, privacy, or moral rights](https://creativecommons.org/licenses/by-nc/4.0/deed.en#ref-publicity-privacy-or-moral-rights) may limit how you use the material.
[See the legal code](https://creativecommons.org/licenses/by/4.0/legalcode.en)`
[See the legal code](https://creativecommons.org/licenses/by-nc/4.0/legalcode.en)`

export const templates: Template<string> = {
recommended: mitLicense,
mit: mitLicense,
// biome-ignore lint/style/useNamingConvention: Alias for upper case typed license.
MIT: mitLicense,
public: publicDomainLicense,
cc0: publicDomainLicense,
commercial: commercialLicense,
ccby4: commercialLicense,
ccbync4: commercialLicense,
}

export function createFile(content: string | object) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"author": "Matthias Giger",
"scripts": {
"check": "biome check --write .",
"clean": "git clean -fdx test/fixture",
"postinstall": "bun index.ts",
"types": "tsc",
"template": "folders 'template/*' 'update --no-install' --output",
"test": "bun test ./test/*.test.ts",
"clean": "git clean -fdx test/fixture"
"types": "tsc"
},
"dependencies": {
"avait": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion template/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.3",
"zero-configuration": "^0.16.3"
"zero-configuration": "^0.17.0"
},
"trustedDependencies": [
"zero-configuration"
Expand Down
2 changes: 1 addition & 1 deletion template/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.3",
"zero-configuration": "^0.16.3"
"zero-configuration": "^0.17.0"
},
"trustedDependencies": [
"zero-configuration",
Expand Down
2 changes: 1 addition & 1 deletion template/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"numic": "^2.2.0",
"react-test-renderer": "^18.3.1",
"typescript": "^5.5.3",
"zero-configuration": "^0.16.3"
"zero-configuration": "^0.17.0"
},
"trustedDependencies": [
"zero-configuration",
Expand Down
2 changes: 1 addition & 1 deletion template/plugin-bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"typescript": "^5.5.3",
"zero-configuration": "^0.16.3"
"zero-configuration": "^0.17.0"
},
"peerDependencies": {
"typescript": ">= 5"
Expand Down
2 changes: 1 addition & 1 deletion template/plugin-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@biomejs/biome": "^1.8.3",
"@types/react": "^18.3.3",
"typescript": "^5.5.3",
"zero-configuration": "^0.16.3"
"zero-configuration": "^0.17.0"
},
"peerDependencies": {
"react": ">= 18",
Expand Down
2 changes: 1 addition & 1 deletion template/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.3",
"zero-configuration": "^0.16.3"
"zero-configuration": "^0.17.0"
},
"trustedDependencies": [
"zero-configuration"
Expand Down
7 changes: 6 additions & 1 deletion test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ test('Empty project will exit and not add default gitignore.', () => {
expect(existsSync(join(fixturePath, '.gitignore'))).toBe(false)
})

test('Creates configuration files for various build-tool configurations.', () => {
test('Creates configuration files for various build-tool configurations.', async () => {
const fixturePath = './test/fixture/build'

execSync('bun ./../../../index.ts', {
Expand All @@ -135,11 +135,16 @@ test('Creates configuration files for various build-tool configurations.', () =>
expect(existsSync(join(fixturePath, 'farm.config.ts'))).toBe(true)
expect(existsSync(join(fixturePath, 'vite.config.ts'))).toBe(true)
expect(existsSync(join(fixturePath, 'tailwind.config.ts'))).toBe(true)
expect(existsSync(join(fixturePath, 'LICENSE.md'))).toBe(true)
// Only work with JavaScript configuration or serializable configuration.
// Not serializable in this case.
expect(existsSync(join(fixturePath, 'next.config.js'))).toBe(false)
// JavaScript only, but defined in package.json.
expect(existsSync(join(fixturePath, 'postcss.config.ts'))).toBe(true)

const license = await Bun.file(join(fixturePath, 'LICENSE.md')).text()

expect(license).toContain('Copyright (c) Supports String, 2099 Even multiple strings!')
})

test('Creates configuration files in all workspaces including the root.', async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/fixture/build/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ export const tailwind = {
},
plugins: [],
}

export const license = { extends: 'recommended', authors: ["Supports String", "2099 Even multiple strings!"] }

0 comments on commit 0b0f78e

Please sign in to comment.