Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from BohemianCoding/f/update-build-process
Browse files Browse the repository at this point in the history
update build process
  • Loading branch information
mathieudutour authored Jul 10, 2019
2 parents 2ec056c + d2f3d89 commit 4393938
Show file tree
Hide file tree
Showing 7 changed files with 747 additions and 1,031 deletions.
1,628 changes: 712 additions & 916 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "print-export",
"version": "1.0.2",
"version": "1.0.3",
"description": "Export artboards or pages to a PDF for printing",
"engines": {
"sketch": ">=3.0"
Expand All @@ -17,11 +17,10 @@
"build": "skpm-build",
"watch": "skpm-build --watch",
"start": "skpm-build --watch --run",
"prepublish": "npm run build && xcodebuild build -workspace ./src/framework/print-export.xcworkspace -scheme 'print-export' -configuration release -quiet COMMAND_LINE_BUILD=1",
"postinstall": "npm run build && xcodebuild build -workspace ./src/framework/print-export.xcworkspace -scheme 'print-export' -configuration release -quiet COMMAND_LINE_BUILD=1 && skpm-link"
"postinstall": "npm run build && skpm-link"
},
"devDependencies": {
"@skpm/builder": "^0.5.11"
"@skpm/builder": "^0.7.1"
},
"author": "Sketch",
"license": "MIT",
Expand Down
44 changes: 20 additions & 24 deletions src/command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Orientation, Unit } = require('./enums')
const { loadFramework, getFilename, valueWithPropertyPath } = require('./utils')
const { getFilename, valueWithPropertyPath } = require('./utils')
const Settings = require('sketch/settings')
const { ExportType, Scope } = require('./enums')
const { paperSizeStandards } = require('./constants')
Expand Down Expand Up @@ -38,27 +38,25 @@ const defaultValues = {
}

export default function(context) {
if (loadFramework('print_export', mainClassName, context)) {
const document = getSelectedDocument()
const optionsDialog = new OptionsDialog(pluginName, getSettings(document), context)
if (optionsDialog.dialog.runModal() === NSAlertFirstButtonReturn) {
setSettings(optionsDialog, document)
const filePath = getFilePath(optionsDialog.scope, document)
if (filePath != null) {
const options = {
exportType: optionsDialog.exportType,
scope: optionsDialog.scope,
showArtboardShadow: optionsDialog.showArtboardShadow,
showArtboardName: optionsDialog.showArtboardName,
showPrototypingLinks: optionsDialog.showPrototypingLinks,
pageWidth: normalizeDimension(optionsDialog.pageWidth, optionsDialog.paperSizeStandard),
pageHeight: normalizeDimension(optionsDialog.pageHeight, optionsDialog.paperSizeStandard),
includeCropMarks: optionsDialog.includeCropMarks,
bleed: normalizeDimension(optionsDialog.bleed, optionsDialog.paperSizeStandard),
slug: normalizeDimension(optionsDialog.slug, optionsDialog.paperSizeStandard)
}
frameworkClass().generatePDFWithDocument_filePath_options_context(document.sketchObject, filePath, options, context)
const document = getSelectedDocument()
const optionsDialog = new OptionsDialog(pluginName, getSettings(document), context)
if (optionsDialog.dialog.runModal() === NSAlertFirstButtonReturn) {
setSettings(optionsDialog, document)
const filePath = getFilePath(optionsDialog.scope, document)
if (filePath != null) {
const options = {
exportType: optionsDialog.exportType,
scope: optionsDialog.scope,
showArtboardShadow: optionsDialog.showArtboardShadow,
showArtboardName: optionsDialog.showArtboardName,
showPrototypingLinks: optionsDialog.showPrototypingLinks,
pageWidth: normalizeDimension(optionsDialog.pageWidth, optionsDialog.paperSizeStandard),
pageHeight: normalizeDimension(optionsDialog.pageHeight, optionsDialog.paperSizeStandard),
includeCropMarks: optionsDialog.includeCropMarks,
bleed: normalizeDimension(optionsDialog.bleed, optionsDialog.paperSizeStandard),
slug: normalizeDimension(optionsDialog.slug, optionsDialog.paperSizeStandard)
}
frameworkClass().generatePDFWithDocument_filePath_options_context(document.sketchObject, filePath, options, context)
}
}
}
Expand All @@ -68,7 +66,7 @@ export const onShutdown = function(context) {
}

const frameworkClass = function() {
return NSClassFromString(mainClassName)
return require('./framework/print-export.xcworkspace/contents.xcworkspacedata').getClass(mainClassName)
}

const getSettings = function(document) {
Expand Down Expand Up @@ -167,5 +165,3 @@ const getDefaultPageSize = function(paperSizeStandard) {
return paperSizeStandard.sizes[0]
}
}


30 changes: 8 additions & 22 deletions src/framework/print-export.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
4DA8CB322241369D00FC9D2D /* Sources */,
4DA8CB332241369D00FC9D2D /* Frameworks */,
4DA8CB342241369D00FC9D2D /* Resources */,
4DA8CB41224137F300FC9D2D /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -280,23 +279,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
4DA8CB41224137F300FC9D2D /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "FRAMEWORK=\"print_export.framework\"\nPLUGIN_FILENAME=\"print-export.sketchplugin\"\n\ncp -R $BUILT_PRODUCTS_DIR/$FRAMEWORK $SRCROOT/../../$PLUGIN_FILENAME/Contents/Resources/\n\nif [ $COMMAND_LINE_BUILD -eq 0 ]; then\n osascript -e 'quit app \"Sketch\"'\n sleep 4\n open -a \"/Applications/Sketch.app\"\nfi\n\n";
};
8700C1F07C1BA4654B4A6F0A /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -461,11 +443,12 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 934C9379DCA27F4889B1A21D /* Pods-print-export.debug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COMMAND_LINE_BUILD = 0;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = WUGMZZ5K46;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -479,6 +462,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.sketch.print-export";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
};
name = Debug;
Expand All @@ -487,11 +471,12 @@
isa = XCBuildConfiguration;
baseConfigurationReference = F87F0855D9C588A6689F6891 /* Pods-print-export.release.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COMMAND_LINE_BUILD = 0;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = WUGMZZ5K46;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -505,6 +490,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.sketch.print-export";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:print-export.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
8 changes: 4 additions & 4 deletions src/options-dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { loadNib, buildDialog } = require('./utils')
const { buildDialog } = require('./utils')
const { ExportType, Scope, Orientation, Unit } = require('./enums')
const { paperSizeStandards } = require('./constants')

Expand All @@ -7,7 +7,7 @@ const UNIT_TEXTFIELD_INDENTIFIERS = ['pageWidthUnits', 'pageHeightUnits', 'bleed
module.exports = class OptionsDialog {

constructor(pluginName, model, context) {
this.nib = loadNib('PEOptionsAccessoryView')
this.nib = require('./framework/print-export.xcworkspace/contents.xcworkspacedata').getNib('PEOptionsAccessoryView')

this.exportTypeChanged = this.exportTypeChanged.bind(this)
this.nib.artboardPerPage.setCOSJSTargetFunction(this.exportTypeChanged)
Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = class OptionsDialog {
this.nib.slug.doubleValue = model.slug
this.nib.slug.toolTip = 'The area beyond the bleed that contains the crop marks'

this.dialog = buildDialog(pluginName, 'Export', this.nib.rootView, context)
this.dialog = buildDialog(pluginName, 'Export', this.nib.getRoot(), context)
}

exportTypeChanged() {
Expand Down Expand Up @@ -216,4 +216,4 @@ module.exports = class OptionsDialog {
return this.nib.slug.doubleValue()
}

}
}
57 changes: 0 additions & 57 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@ const ObjClass = require('cocoascript-class').default;
const manifest = require('./manifest.json')
const path = require('path')

export function loadNib(nibName, delegate = undefined) {
const bundle = NSBundle.bundleWithIdentifier(manifest.identifier)
const nibOwner = (new ObjClass(delegate || {})).new()
const topLevelObjectsPointer = MOPointer.alloc().initWithValue(null)
const loadedNib = bundle.loadNibNamed_owner_topLevelObjects(nibName, nibOwner, topLevelObjectsPointer)
if (!loadedNib) {
throw new Error(`Error loading nib file ${nibName}.nib`)
}

let rootView
var topLevelObjects = topLevelObjectsPointer.value();
for (let i = 0; i < topLevelObjects.count(); i++) {
let obj = topLevelObjects.objectAtIndex(i)
if (/View$/.test(String(obj.className()))) {
rootView = obj
break
}
}

const result = {nibOwner, rootView}

walkViewTree(rootView, function(view) {
const id = String(view.identifier())
if (id && !id.startsWith('_')) {
result[id] = view
}
})

return result
}

export function buildDialog(dialogTitle, buttonTitle, accessoryView, context) {
const dialog = NSAlert.new()
dialog.messageText = dialogTitle
Expand All @@ -43,15 +12,6 @@ export function buildDialog(dialogTitle, buttonTitle, accessoryView, context) {
return dialog
}

export function loadFramework(framework, frameworkClassName, context) {
const frameworkPath = context.scriptPath.stringByDeletingLastPathComponent().stringByDeletingLastPathComponent().stringByAppendingPathComponent("Resources")
if (!frameworkLoaded(frameworkClassName) && !Mocha.sharedRuntime().loadFrameworkWithName_inDirectory(framework, frameworkPath)) {
console.error(`Couldn't load framework ${framework}`)
return false
}
return true
}

export function getFilename(filePath, extension) {
return `${path.basename(filePath, path.extname(filePath))}${extension}`
}
Expand All @@ -64,20 +24,3 @@ export function valueWithPropertyPath(object, keyPath) {
})
return currentObject
}

const frameworkLoaded = function(frameworkClassName) {
return NSClassFromString(frameworkClassName) != null
}

const walkViewTree = function(rootView, fn) {
function _visit(view) {
fn(view)

const subviews = view.subviews();
for (let i = 0; i < subviews.count(); i++) {
_visit(subviews.objectAtIndex(i))
}
}

_visit(rootView);
}

0 comments on commit 4393938

Please sign in to comment.