Fix: Remove .gitignore from package build (#787)

* gitignore is removed from package build

* node script for moving generated files

* changed file name

* dropped console log
This commit is contained in:
Adrian
2023-01-10 16:48:32 -05:00
committed by GitHub
parent df568f467b
commit 9ca1addbbc
5 changed files with 29 additions and 13 deletions

3
.gitignore vendored
View File

@@ -9,4 +9,5 @@ package
coverage coverage
pnpm-lock.yaml pnpm-lock.yaml
.vscode .vscode
.temp .temp
src/lib/tailwind/generated

View File

@@ -17,7 +17,7 @@
"coverage": "vitest run --coverage", "coverage": "vitest run --coverage",
"prebuild:jss": "postcss src/lib/styles/all.css --dir .temp --base src/lib/styles", "prebuild:jss": "postcss src/lib/styles/all.css --dir .temp --base src/lib/styles",
"build:jss": "prejss-cli .temp/all.css --format commonjs", "build:jss": "prejss-cli .temp/all.css --format commonjs",
"postbuild:jss": "mkdir -p src/lib/tailwind/generated && mv -f .temp/all.js src/lib/tailwind/generated/allComponents.cjs" "postbuild:jss": "node ./scripts/mv-generated-files.js"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^1.0.0", "@sveltejs/adapter-auto": "^1.0.0",
@@ -63,4 +63,4 @@
"./styles/*": "./src/lib/styles/*", "./styles/*": "./src/lib/styles/*",
"./tailwind/*": "./src/lib/tailwind/*" "./tailwind/*": "./src/lib/tailwind/*"
} }
} }

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env node
import { renameSync, mkdirSync } from 'fs';
try {
// makes the directory if it doesn't exist
mkdirSync('src/lib/tailwind/generated');
} catch (e) {
// throws if the directory already exists
}
try {
// moves generated file to appropriate location
renameSync('.temp/all.js', 'src/lib/tailwind/generated/allComponents.cjs');
} catch (e) {
console.error(`Failed to move file: ${e}`);
}

View File

@@ -1,18 +1,17 @@
#!/usr/bin/env node #!/usr/bin/env node
import { readFileSync, writeFileSync } from 'fs' import { readFileSync, unlinkSync, writeFileSync } from 'fs';
//Put the exports field back into package.json so that monorepos can work again //Put the exports field back into package.json so that monorepos can work again
let packageJson = readFileSync('package.json').toString() let packageJson = readFileSync('package.json').toString();
packageJson = packageJson.slice(0, packageJson.lastIndexOf('}')-1) //strip closing } packageJson = packageJson.slice(0, packageJson.lastIndexOf('}') - 1); //strip closing }
packageJson += packageJson += `,
`,
"exports": { "exports": {
".": "./src/lib/index.ts", ".": "./src/lib/index.ts",
"./themes/*": "./src/lib/themes/*", "./themes/*": "./src/lib/themes/*",
"./styles/*": "./src/lib/styles/*", "./styles/*": "./src/lib/styles/*",
"./tailwind/*": "./src/lib/tailwind/*" "./tailwind/*": "./src/lib/tailwind/*"
} }
}` }`;
writeFileSync('package.json', packageJson); writeFileSync('package.json', packageJson);
unlinkSync('./package/.gitignore'); // delete .gitignore file from built package

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
import { del } from "edit-package-json"; import { del } from 'edit-package-json';
import { readFileSync, writeFileSync } from 'fs' import { readFileSync, writeFileSync } from 'fs';
//We chop out the exports field of ../package.json rather than manipulate the one in ../package/package.json in case there //We chop out the exports field of ../package.json rather than manipulate the one in ../package/package.json in case there
//are changes to the behaviour of 'vite build'. post-build.js will patch it back in so that monorepos work again. //are changes to the behaviour of 'vite build'. post-build.js will patch it back in so that monorepos work again.
writeFileSync('package.json', del(readFileSync('package.json').toString(), 'exports')) writeFileSync('package.json', del(readFileSync('package.json').toString(), 'exports'));