-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BPK-2653] Investigate shipping CSS (#1607)
* [BPK-2653] Investigate shipping CSS * [BPK-2653] Add CSS files * [BPK-2653] Support loading CSS in storybook
- Loading branch information
George Gillams
committed
Oct 19, 2019
1 parent
7c2f51a
commit baaf025
Showing
4 changed files
with
153 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Backpack - Skyscanner's Design System | ||
* | ||
* Copyright 2016-2019 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* How this works | ||
* | ||
* First of all, this scans all our packages and gets the current versions. | ||
* | ||
* Each package is then updated to have `-css.0` appended to the version, | ||
* and then `npm publish` is used to publish each package with the `css` tag for easy installation, | ||
*/ | ||
|
||
/* @flow */ | ||
|
||
const { | ||
getCurrentPackageMeta, | ||
appendToPackageVersions, | ||
publishPackagesToNPM, | ||
verbose, | ||
logVerbose, | ||
} = require('./util'); | ||
|
||
const cli = async () => { | ||
const currentPackageMeta = getCurrentPackageMeta(); | ||
if (verbose) { | ||
logVerbose(`currentPackageMeta`); | ||
logVerbose(currentPackageMeta); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('Updating package versions...'); | ||
await appendToPackageVersions(currentPackageMeta, 'css.0'); | ||
// eslint-disable-next-line no-console | ||
console.log('All good. 👍'); | ||
|
||
await publishPackagesToNPM(currentPackageMeta, 'css'); | ||
}; | ||
|
||
cli().then(null); |
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,64 @@ | ||
/* | ||
* Backpack - Skyscanner's Design System | ||
* | ||
* Copyright 2016-2019 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* @flow strict */ | ||
|
||
const fs = require('fs'); | ||
const { execSync } = require('child_process'); | ||
|
||
const updateImports = (file, findReplaces) => | ||
new Promise((resolve, reject) => { | ||
fs.readFile(file, 'utf8', (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
let result = data; | ||
findReplaces.forEach(fr => { | ||
const splitFile = result.split(fr.find); | ||
if (splitFile.length === 1) { | ||
return; | ||
} | ||
result = splitFile.join(fr.replace); | ||
}); | ||
|
||
fs.writeFile(file, result, 'utf8', err2 => { | ||
if (err2) return reject(err2); | ||
return resolve(); | ||
}); | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('Crunching import paths...'); | ||
|
||
const findReplaces = [{ find: '.scss', replace: '.css' }]; | ||
|
||
const jsFiles = execSync( | ||
'find packages -name "*.js" -o -name "*.jsx" | grep -v node_modules', | ||
) | ||
.toString() | ||
.split('\n') | ||
.filter(s => s !== ''); | ||
|
||
const updatePromises = jsFiles.map(jF => updateImports(jF, findReplaces)); | ||
|
||
Promise.all(updatePromises).then(() => { | ||
// eslint-disable-next-line no-console | ||
console.log('All good. 👍'); | ||
process.exit(0); | ||
}); |
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